function game()
players = minetest.get_connected_players()
if #players < 2 then
reset()
return
end
for i = 1, #catchers do
local num = math.random(1, #catcherspawns[lvlnum])
catchers[i]:setpos(catcherspawns[lvlnum])
end
for i = 1, #runners do
local num = math.random(1, #runnerspawns[lvlnum])
runners[i]:setpos(runnerpawns[lvlnum])
end
GameOn = true
loading = false
end
Please help.
Also it didn't wait before it called the function.
edit: I'm using minetest version 4.7
Last edited by JBR on Sat Jun 15, 2013 23:40, edited 1 time in total.
PilzAdam wrote:Try making the game function local, to be sure that other mods dont screw it up.
wait your saying that if your don't make functions/variables are not local they can be accessed by other mods? Whats the point of using dofile then?
My though is that maybe because on 4.7 they have changed minetest.env to just minetest maybe they forgot to change one of the functions to minetest. Do you think I should try using minetest.env instead?
edit: I just tried making the game function local and it didn't work, still got the same error.
Last edited by JBR on Sat Jun 15, 2013 23:53, edited 1 time in total.
PilzAdam wrote:All mods run in the same namespace. This is extremly useful for mods like mesecons (other mods can add mesecon functionality and so on).
Can you please paste your whole code? I guess game is just not defined when running minetest.after.
function count(num)
minetest.chat_send_all(num)
end
function game()
players = minetest.get_connected_players()
if #players < 2 then
reset()
return
end
for i = 1, #catchers do
local num = math.random(1, #catcherspawns[lvlnum])
catchers[i]:setpos(catcherspawns[lvlnum])
end
for i = 1, #runners do
local num = math.random(1, #runnerspawns[lvlnum])
runners[i]:setpos(runnerpawns[lvlnum])
end
GameOn = true
loading = false
end
function chooseplayers()
players = minetest.get_connected_players()
if #players < 2 then
reset()
return
end
numcatchers = #players/2
numcatchers = math.floor(numcatchers)
chosen = {}
peepstochoose = players
for i = 1, numcatchers do
local num = math.random(1,#peepstochoose)
table.insert(chosen, peepstochoose[num])
table.remove(peepstochoose, num)
end
cmsg = ""
for i = 1, #chosen do
cmsg = cmsg..chosen[i]:get_player_name()
if i ~= #chosen then
cmsg = cmsg..", "
end
end
minetest.chat_send_all("Catchers chosen! They are: "..cmsg)
for i = 1, #chosen do
table.insert(catchers,chosen[i])
end
for i = 1, #peepstochoose do
table.insert(runners,peepstochoose[i])
end
minetest.chat_send_all("Game starting in..")
minetest.after(1,count(3))
minetest.after(2,count(2))
minetest.after(3,count(1))
minetest.after(4,game)
end
function main(dtime)
timer = timer+dtime
players = minetest.get_connected_players()
if #players > 1 then
if not GameOn then
if not loading then
loading = true
local num = math.random(1,#levels)
lvlname = levels[num]
lvlnum = num
minetest.chat_send_all("Level chosen:"..lvlname)
minetest.chat_send_all("Selecteting catchers..")
minetest.after(2.0, chooseplayers)
end
end
end
end