Error on item:setColor()
1 1

2 posts in this topic

Recommended Posts

-- wash the clothing!
function WashMyClothing_OnCreate(items, result, player, selectedItem)
    for i=0,items:size() - 1 do
        local item = items:get(i);
        if instanceof (item, "Clothing") then
            local name = item:getType();
            if DIRTY_TO_NORMAL[name] then
                print("New item:",DIRTY_TO_NORMAL[name]);
                local new_item = player:getInventory():AddItems(DIRTY_TO_NORMAL[name], 1);
                if new_item then
                    print("new_item",tostring(new_item));
                    local color = item:getColor()
                    print("color",tostring(color));
                    new_item:setColor(color); -----> ERROR HERE?!
                end
                return;
            end
        end
    end
end

Crash log:

Spoiler

1544309613060 New item:	Base.PaddedTrousers
1544309613060 new_item	[zombie.inventory.types.Clothing@7357a011]
1544309613060 color	Color (0.3137255,0.35686275,0.6509804,1.0)
1544309613060 
1544309613060 -----------------------------------------
1544309613060 STACK TRACE
1544309613060 -----------------------------------------
1544309613060 function: WashMyClothing_OnCreate -- file: serverCode.lua line # 22
1544309613060 Callframe at: PerformMakeItem
1544309613061 function: perform -- file: ISCraftAction.lua line # 44
java.lang.RuntimeException: Object tried to call nil in WashMyClothing_OnCreate
	at se.krka.kahlua.vm.KahluaUtil.fail(KahluaUtil.java:83)
	at se.krka.kahlua.vm.KahluaThread.luaMainloop(KahluaThread.java:973)
	at se.krka.kahlua.vm.KahluaThread.call(KahluaThread.java:167)
	at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1922)
	at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1747)
	at se.krka.kahlua.integration.LuaCaller.pcall(LuaCaller.java:77)
	at se.krka.kahlua.integration.LuaCaller.protectedCall(LuaCaller.java:113)
	at zombie.inventory.RecipeManager.PerformMakeItem(RecipeManager.java:1099)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at se.krka.kahlua.integration.expose.caller.MethodCaller.call(MethodCaller.java:61)
	at se.krka.kahlua.integration.expose.LuaJavaInvoker.call(LuaJavaInvoker.java:199)
	at se.krka.kahlua.integration.expose.LuaJavaInvoker.call(LuaJavaInvoker.java:189)
	at se.krka.kahlua.vm.KahluaThread.callJava(KahluaThread.java:186)
	at se.krka.kahlua.vm.KahluaThread.luaMainloop(KahluaThread.java:1009)
	at se.krka.kahlua.vm.KahluaThread.call(KahluaThread.java:167)
	at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1922)
	at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1747)
	at se.krka.kahlua.integration.LuaCaller.pcall(LuaCaller.java:86)
	at zombie.characters.CharacterTimedActions.LuaTimedActionNew.perform(LuaTimedActionNew.java:80)
	at zombie.characters.IsoGameCharacter.update(IsoGameCharacter.java:10149)
	at zombie.characters.IsoPlayer.update(IsoPlayer.java:3109)
	at zombie.iso.IsoCell.ProcessObjects(IsoCell.java:2342)
	at zombie.iso.IsoCell.update(IsoCell.java:6201)
	at zombie.iso.IsoWorld.update(IsoWorld.java:3165)
	at zombie.gameStates.IngameState.update(IngameState.java:1365)
	at zombie.gameStates.GameStateMachine.update(GameStateMachine.java:101)
	at zombie.GameWindow.logic(GameWindow.java:688)
	at zombie.GameWindow.run(GameWindow.java:1314)
	at zombie.GameWindow.maina(GameWindow.java:1090)
	at zombie.gameStates.MainScreenState.main(MainScreenState.java:184)

 

 

I can't understand what's wrong. "new_item" is valid and "color" is valid too. So why item:setColor(color) causes an error?

Edited by Maris

Share this post


Link to post
Share on other sites

Okay, I avoid crash by using

local new_item = InventoryItemFactory.CreateItem(name);

insted of 

local new_item = player:getInventory():AddItems(name)

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
1 1