error in misc file

Post Reply
JBR
Member
Posts: 76
Joined: Sun May 26, 2013 22:04
Location: United Kingdom, Wales

error in misc file

by JBR » Post

Ok i was testing my mod and I got this error minetest-0.4.7\bin\..\builtin/misc.lua:17: attempt to call field 'func' (a nil value)

The error came up when this was called or when the function game was called.

Code: Select all

    minetest.after(4,game)
function game:

Code: Select all

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.

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

Try making the game function local, to be sure that other mods dont screw it up.

JBR
Member
Posts: 76
Joined: Sun May 26, 2013 22:04
Location: United Kingdom, Wales

by JBR » Post

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.

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

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.

JBR
Member
Posts: 76
Joined: Sun May 26, 2013 22:04
Location: United Kingdom, Wales

by JBR » Post

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.
Here's the relevant part of the code:

Code: Select all

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

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

The problem is

Code: Select all

minetest.after(1,count(3))
Change it to

Code: Select all

minetest.after(1, count, 3)
You need to pass a function to minetest.after(), parameters for this function can be added as additional parameters to minetest.after().

JBR
Member
Posts: 76
Joined: Sun May 26, 2013 22:04
Location: United Kingdom, Wales

by JBR » Post

PilzAdam wrote:The problem is

Code: Select all

minetest.after(1,count(3))
Change it to

Code: Select all

minetest.after(1, count, 3)
You need to pass a function to minetest.after(), parameters for this function can be added as additional parameters to minetest.after().
That worked thanks! :)

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests