tommysticks Posted June 6, 2015 Share Posted June 6, 2015 So, just tryin to get how this works. Here is my code:local function equippedTimes() local player = getPlayer(); local primary = player:getPrimaryHandItem(); local pModData = primary:getModData(); pModData.name = "Primary"; print(pModData.name);endEvents.OnEquipPrimary.Add(equippedTimes);Here is the stack trace I'm getting: -------------------------------------------------------------attempted index: getModData of non-table: null-----------------------------------------STACK TRACE-----------------------------------------function: equippedTimes -- file: named weapons.lua line # 26Callframe at: setPrimaryHandItemfunction: perform -- file: ISUnequipAction.lua line # 50java.lang.RuntimeException: attempted index: getModData of non-table: nullat se.krka.kahlua.vm.KahluaThread.tableget(KahluaThread.java:1544)at se.krka.kahlua.vm.KahluaThread.luaMainloop(KahluaThread.java:621)at se.krka.kahlua.vm.KahluaThread.call(KahluaThread.java:162)at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1722)at se.krka.kahlua.vm.KahluaThread.pcallvoid(KahluaThread.java:1667)at se.krka.kahlua.integration.LuaCaller.pcallvoid(LuaCaller.java:53)at se.krka.kahlua.integration.LuaCaller.protectedCallVoid(LuaCaller.java:81)at zombie.Lua.Event.trigger(Event.java:37)at zombie.Lua.LuaEventManager.triggerEvent(LuaEventManager.java:112)at zombie.characters.IsoGameCharacter.setPrimaryHandItem(IsoGameCharacter.java:1577)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:606)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:181)at se.krka.kahlua.vm.KahluaThread.luaMainloop(KahluaThread.java:981)at se.krka.kahlua.vm.KahluaThread.call(KahluaThread.java:162)at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1722)at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1637)at se.krka.kahlua.integration.LuaCaller.pcall(LuaCaller.java:72)at zombie.characters.CharacterTimedActions.LuaTimedActionNew.perform(LuaTimedActionNew.java:74)at zombie.characters.IsoGameCharacter.update(IsoGameCharacter.java:8640)at zombie.characters.IsoPlayer.update(IsoPlayer.java:2678)at zombie.iso.IsoCell.ProcessObjects(IsoCell.java:1337)at zombie.iso.IsoCell.update(IsoCell.java:5165)at zombie.iso.IsoWorld.update(IsoWorld.java:2323)at zombie.gameStates.IngameState.update(IngameState.java:1193)at zombie.gameStates.GameStateMachine.update(GameStateMachine.java:101)at zombie.GameWindow.logic(GameWindow.java:624)at zombie.GameWindow.run(GameWindow.java:1152)at zombie.GameWindow.maina(GameWindow.java:977)at zombie.gameStates.MainScreenState.main(MainScreenState.java:162)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:606)at com.exe4j.runtime.LauncherEngine.launch(Unknown Source)at com.exe4j.runtime.WinLauncher.main(Unknown Source)-----------------------------------------STACK TRACE-----------------------------------------function: equippedTimes -- file: named weapons.lua line # 26Callframe at: setPrimaryHandItemfunction: perform -- file: ISUnequipAction.lua line # 50Am I doing this completely wrong? Trying to set the mod data to primary whenever a weapon is equipped. Link to comment Share on other sites More sharing options...
EnigmaGrey Posted June 6, 2015 Share Posted June 6, 2015 See what kind of object primary is with print (primary). It doesn't appear to have the function getModData(), even though it should be an item. Some changes with exposed classes have been done for build 32. It's possible this one was mistakenly blocked. Link to comment Share on other sites More sharing options...
tommysticks Posted June 7, 2015 Author Share Posted June 7, 2015 See what kind of object primary is with print (primary). It doesn't appear to have the function getModData(), even though it should be an item. Some changes with exposed classes have been done for build 32. It's possible this one was mistakenly blocked.Primary prints some hex lookin number that I assume is the weapon identifier. It's different for each item and remains the same when an item is re-equipped. Link to comment Share on other sites More sharing options...
Brybry Posted June 7, 2015 Share Posted June 7, 2015 Pretty sure getPrimaryHandItem() is returning null (because not holding anything) and you're trying to call getModData() on a null object. Try local function equippedTimes() local player = getPlayer(); local primary = player:getPrimaryHandItem(); if primary ~= nil then local pModData = primary:getModData(); pModData.name = "Primary"; print(pModData.name); endend Link to comment Share on other sites More sharing options...
tommysticks Posted June 7, 2015 Author Share Posted June 7, 2015 Pretty sure getPrimaryHandItem() is returning null (because not holding anything) and you're trying to call getModData() on a null object. Try local function equippedTimes() local player = getPlayer(); local primary = player:getPrimaryHandItem(); if primary ~= nil then local pModData = primary:getModData(); pModData.name = "Primary"; print(pModData.name); endendWorked like a charm. Thanks. Link to comment Share on other sites More sharing options...
tommysticks Posted June 10, 2015 Author Share Posted June 10, 2015 Quick question... I believe I saw somewhere that ModData can't be an integer, is that correct? Link to comment Share on other sites More sharing options...
Brybry Posted June 10, 2015 Share Posted June 10, 2015 ModData is a lua table. It can't be an integer but you can store an integer in it. EnigmaGrey 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now