Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help,
read this .
ChicoGameDev
Citizen
Posts: 70 Joined: Thu Feb 14, 2019 6:02 pm
Location: Switzerland
Contact:
Post
by ChicoGameDev » Tue Sep 01, 2020 3:41 pm
Hi everybody,
Am I missing something or love.math.random cannot be accessed from a new thread created using love.thread.newThread?
I get this error :
attempt to index field 'math' (a nil value)
on this line :
siberian
Prole
Posts: 21 Joined: Sat Apr 06, 2019 1:42 pm
Post
by siberian » Tue Sep 01, 2020 4:00 pm
You can use math.random()
Code: Select all
local threadCode = [[
local count = ...
count = count or 1
math.randomseed(os.time())
for i = 1, count do
print(math.random(10))
end
]]
local th
function love.load()
th = love.thread.newThread( threadCode )
th:start(10)
end
or add
into thread code.
"When a Thread is started, it only loads love.data, love.filesystem, and love.thread module. Every other module has to be loaded with require."
Last edited by
siberian on Tue Sep 01, 2020 4:06 pm, edited 1 time in total.
ChicoGameDev
Citizen
Posts: 70 Joined: Thu Feb 14, 2019 6:02 pm
Location: Switzerland
Contact:
Post
by ChicoGameDev » Tue Sep 01, 2020 4:04 pm
Hi,
That's should be precised in the wiki x)
Thanks for your answer, indeed in the love table there is only love.thread, love.filesystem (wonderful!) and love.data.
I'll go with math.random then.
[Edit]
I did not see the full answer ! Waouw that's really wonderful ! Thanks I was missing something indeed !
Awesome! Thanks!
Regards,
Last edited by
ChicoGameDev on Tue Sep 01, 2020 4:09 pm, edited 1 time in total.
siberian
Prole
Posts: 21 Joined: Sat Apr 06, 2019 1:42 pm
Post
by siberian » Tue Sep 01, 2020 4:08 pm
I added a second option into my answer, it's simpler.
zorg
Party member
Posts: 3444 Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:
Post
by zorg » Tue Sep 01, 2020 5:07 pm
ChicoGameDev wrote: ↑ Tue Sep 01, 2020 4:04 pm
That's should be precised in the wiki x)
It is mentioned (verbatim) on the page for threads:
https://love2d.org/wiki/love.thread
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
ChicoGameDev
Citizen
Posts: 70 Joined: Thu Feb 14, 2019 6:02 pm
Location: Switzerland
Contact:
Post
by ChicoGameDev » Tue Sep 01, 2020 5:15 pm
Yes I'm so sorry my eyes have just jumped this information :'(
Thanks for answering.
Regards,
Users browsing this forum: No registered users and 79 guests