error in misc file

JBR
Member
 
Posts: 76
Joined: Sun May 26, 2013 22:04

error in misc file

by JBR » Sat Jun 15, 2013 23:38

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.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
    minetest.after(4,game)

function game:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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

by PilzAdam » Sat Jun 15, 2013 23:46

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

by JBR » Sat Jun 15, 2013 23:50

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

by PilzAdam » Sat Jun 15, 2013 23:54

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

by JBR » Sun Jun 16, 2013 00:03

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:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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

by PilzAdam » Sun Jun 16, 2013 00:10

The problem is
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.after(1,count(3))

Change it to
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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

by JBR » Sun Jun 16, 2013 00:14

PilzAdam wrote:The problem is
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.after(1,count(3))

Change it to
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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! :)
 


Return to Minetest Problems

Who is online

Users browsing this forum: No registered users and 4 guests

cron