First of all, should "thread:start()" be included in "love.update" function to work?
Second, i'm trying to boot thread on main file load, send variable to him; in the thread itself this variable increases, sends back to the main file and displays on 300,300 point... And its simply not working. Can you guys explain me where am i did mistake?
The main file:
Code: Select all
local e = 0 -- time limitation variable
function love.load()
vr = 5 -- variable that sends in the thread
thread1 = love.thread.newThread("menu.lua") -- creating thread
channel = love.thread.newChannel("channel") -- creating channel (?)
thread1:start() -- starting thread
channel:push(vr) -- sending variable to the thread (?????)
vr = channel:pop() -- receive increased variable from the thread (????)
end
function love.update(dt)
end
function love.draw(dt)
love.graphics.print(tostring(vr), 300,300) -- draw increased variable on 300.300
end
function love.threaderror(t, e) -- error-capturing function i've found on the internet
return error(e)
end
Code: Select all
require("love") -- including all modules from love (????)
local channel = love.thread.getChannel("channel") -- receive channel from main file
local d = 0 -- variable that will hold sended number
d = channel:pop() -- getting variable from channel (????) after "channel:push(vr)" in the main file (????)
if d == nil then -- d got nothing so without this block love'll give me an error
d = 393
end
local e = 15 + tonumber(d) -- variable that sends back to the main file
channel:push(e)