you are right!
And all this time i used to think that order of functions dont matter! damn i am dumb.
Dead simple threads example
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Dead simple threads example
If you try to use something before you define it, it won't be defined at the time you use it.Rishavs wrote:Ok. so when i put the round function before the for loop in my thread file, it works.
But this is the first time i have seen anything like it. In my other scripts I can use function calls above the function definitions.
I think i am missing something very basic to lua.
That applies to your first snippet. Had you put it like this, it would have worked:
Code: Select all
function doit()
local smin = 1
local smax = 1000
channel = love.thread.getChannel("test")
for i = smin, smax, 1 do
print(i .. " > ALL WORK AND NO PLAY MAKES JACK A DULL BOY")
channel:push(round(i * 100 / smax))
end
end
function round(num, dp)
local mult = 10^(dp or 0)
return (math.floor(num * mult + 0.5)) / mult
end
doit()
Hope I've made sense.
Re: Dead simple threads example
Thanks pgimeno.
For some reasons i had forgotten forward declaration is a thing.
Now, for someone who might come in after me and read this thread;
what i wanted to do was to render something in the draw call without the logic bit making the window unresponsive.
threads is obviously one way of doing this.
Another is coroutines. I managed to make the same example work with coroutines.
I have updated the OP post with all the relevant code.
For some reasons i had forgotten forward declaration is a thing.

Now, for someone who might come in after me and read this thread;
what i wanted to do was to render something in the draw call without the logic bit making the window unresponsive.
threads is obviously one way of doing this.
Another is coroutines. I managed to make the same example work with coroutines.
I have updated the OP post with all the relevant code.
Who is online
Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Bing [Bot] and 6 guests