need help on mod update : lua exception

User avatar
redcrab
Member
 
Posts: 831
Joined: Tue Dec 13, 2011 13:45

need help on mod update : lua exception

by redcrab » Wed Jan 25, 2012 16:14

I'm a dumb lua script writter. and I try to update mods to make 20120122 compatible
Sure that any modder can answer my noob issue

I try to fix die_hard mod but still has a nil exception

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
ERROR[ServerThread]: ERROR: An unhandled exception occurred: LuaError: error: .../Minetest-staging/bin/../data/moddie_hard/init.lua:13: attempt to call method 'is_empty'
(a nil value)


on inventory ref "inventorylist[ i] :is_empty()"

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 Die Hard Mod
-- Players lose most of their items.

math.randomseed(os.time())

-- You need to roll ONE out of ITEM_LOSE_DICE
local ITEM_LOSE_DICE = 4

minetest.register_on_dieplayer(function(player)
    local inventorylist=player:get_inventory():get_list("main")
    local i=1
    while inventorylist[i]~=nil do
        if math.random(1, ITEM_LOSE_DICE) ~= 1 and (not (inventorylist[ i ]:is_empty())) then
            print(inventorylist[i]:get_name())
            -- local bnumbeg, bnumend=string.find(inventorylist[ i ], '" ')
            -- local oldvalue=tonumber(string.sub(inventorylist[ i ], bnumend))
            local lostquantum=inventorylist[ i ]:get_count()
            lostquantum=math.random(0,(oldvalue*2/3))
            -- local newstring=string.sub(inventorylist[ i ], 1, bnumend)
            -- newstring=(newstring..tostring(oldvalue))
            -- if oldvalue == 0 then
            -- inventorylist[ i ]=""
            -- else
            -- inventorylist[ i ]=newstring
            -- end
            inventorylist[ i ]:take_item(lostquantum)
        end
        i=i+1
    end
    player:get_inventory():set_list("main", inventorylist)
    return
end)

print("[die_hard] Loaded!")


Thanks
0.4 for serious builder click here
Dedicated Minetest redcrab server forum at http://minetestbb.suret.net

It's nice to be important but it is more important to be nice.
 

cornernote
Member
 
Posts: 844
Joined: Wed Jul 11, 2012 15:02

by cornernote » Sun Sep 30, 2012 07:26

something like this:

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 Die Hard Mod
-- Players lose most of their items.

math.randomseed(os.time())

-- You need to roll ONE out of ITEM_LOSE_DICE
local ITEM_LOSE_DICE = 4

minetest.register_on_dieplayer(function(player)
    local inv=player:get_inventory()
    if not inv:is_empty("main") then
        for i=1,inv:get_size("main") do
            if math.random(1, ITEM_LOSE_DICE) ~= 1 and not inv:get_stack("main", i):is_empty() then
                local stack = inv:get_stack("main", i)
                inv:remove_item("main", stack)
            end
        end
    end
    return
end)

print("[die_hard] Loaded!")
Last edited by cornernote on Sun Sep 30, 2012 07:27, edited 1 time in total.
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 12 guests

cron