Help nonconsistant recurring error

User avatar
jojoa1997
Member
 
Posts: 2890
Joined: Thu Dec 13, 2012 05:11

Help nonconsistant recurring error

by jojoa1997 » Sun Mar 10, 2013 15:33

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 npc_spawner(pos, SPAWN_TYPE)
    local MAX_NPC = 15
    local count = table.getn(minetest.env:get_objects_inside_radius(pos, 50))
    if count == nil then
        count = 0
    end
   
    if count <= MAX_NPC then
        minetest.env:add_entity({x=pos.x+math.random(-1,1),y=pos.y+math.random(2,3),z=pos.z+math.random(-1,1)}, SPAWN_TYPE)
    end
end


Error
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
11:27:03: ERROR[main]: ========== ERROR FROM LUA ===========
11:27:03: ERROR[main]: ...minetest\bin\..\mods\mod_test\peaceful_npc/items.lua:4: attempt to index field 'env' (a nil value)
11:27:03: ERROR[main]: stack traceback:
11:27:03: ERROR[main]:     ...minetest\bin\..\mods\mod_test\peaceful_npc/items.lua:4: in function 'npc_spawner'
11:27:03: ERROR[main]:     ...minetest\bin\..\mods\mod_test\peaceful_npc/items.lua:53: in main chunk
11:27:03: ERROR[main]:     [C]: in function 'dofile'
11:27:03: ERROR[main]:     ...\minetest\bin\..\mods\mod_test\peaceful_npc\init.lua:6: in main chunk
11:27:03: ERROR[main]: =======END OF ERROR FROM LUA ========
Coding;
1X coding
3X debugging
12X tweaking to be just right
 

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

by PilzAdam » Sun Mar 10, 2013 16:00

If you call this function when the code is executed the first time (for registration of node, entities, etc.) minetest.env isnt defined. You can only call this callbacks (like nodedef.on_punch).
 

User avatar
jojoa1997
Member
 
Posts: 2890
Joined: Thu Dec 13, 2012 05:11

by jojoa1997 » Sun Mar 10, 2013 16:45

PilzAdam wrote:If you call this function when the code is executed the first time (for registration of node, entities, etc.) minetest.env isnt defined. You can only call this callbacks (like nodedef.on_punch).
fixed in irc. please close this
Coding;
1X coding
3X debugging
12X tweaking to be just right
 


Return to Minetest Problems

Who is online

Users browsing this forum: No registered users and 12 guests

cron