Page 1 of 1
Question about Threads
Posted: Tue Sep 01, 2020 3:41 pm
by ChicoGameDev
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 :
Re: Question about Threads
Posted: Tue Sep 01, 2020 4:00 pm
by siberian
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."
[SOLVED] Re: Question about Threads
Posted: Tue Sep 01, 2020 4:04 pm
by ChicoGameDev
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,
Re: Question about Threads
Posted: Tue Sep 01, 2020 4:08 pm
by siberian
I added a second option into my answer, it's simpler.
Re: [SOLVED] Re: Question about Threads
Posted: Tue Sep 01, 2020 5:07 pm
by zorg
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
Re: Question about Threads
Posted: Tue Sep 01, 2020 5:15 pm
by ChicoGameDev
Yes I'm so sorry my eyes have just jumped this information :'(
Thanks for answering.
Regards,