tommysticks Posted September 14, 2016 Share Posted September 14, 2016 (edited) Anyone know of a way to transfer items from your inventory to a bag in your inventory instantly? I have this: if item:getType() ~= "KeyRing" and item:getType() ~= "IDCard" then ISTimedActionQueue.add(ISInventoryTransferAction:new(getPlayer(), item, item:getContainer(), idBag2, 0)); end But this isn't instant. I would like something that skips over it being a timed action. Edited October 18, 2016 by tommysticks Solved Link to comment Share on other sites More sharing options...
RoboMat Posted September 14, 2016 Share Posted September 14, 2016 You could probably just create a TimedAction with 0 execution time. On the other hand you can just write a function to directly transfer the items. Maybe this helps. tommysticks 1 Link to comment Share on other sites More sharing options...
tommysticks Posted September 14, 2016 Author Share Posted September 14, 2016 9 minutes ago, RoboMat said: You could probably just create a TimedAction with 0 execution time. That is my work around, didn't post the entire code, but even with 0 execution time it still has to iterate over each item for a split second, and on a stack of like 45, for example, it takes longer than an instant. I'll check out your link. Thanks. Link to comment Share on other sites More sharing options...
tommysticks Posted September 14, 2016 Author Share Posted September 14, 2016 (edited) else inventory:Remove(item); container:AddItem(item); end Ah! This looks like it'd work, but I was under the impression that with Remove() it destroys the item? Thanks man, you're a king. (Solved) Edited September 14, 2016 by tommysticks RoboMat 1 Link to comment Share on other sites More sharing options...
RoboMat Posted September 14, 2016 Share Posted September 14, 2016 It doesn't "destroy" the item. It just removes it from the inventory it is located in. Of course, if you don't have any reference to it (aka stored it in a variable in your code somewhere) it'll be lost. It's been quite some time since I worked with the inventory code so unfortunately, I can't give you more information than the code above. Link to comment Share on other sites More sharing options...
tommysticks Posted September 14, 2016 Author Share Posted September 14, 2016 1 minute ago, RoboMat said: ...(aka stored it in a variable in your code somewhere) it'll be lost. Ah... you are my Miyagi, just don't ask me to wax your car. Link to comment Share on other sites More sharing options...
RoboMat Posted September 14, 2016 Share Posted September 14, 2016 Too late tommy san. Wax on, wax off, wax on ... Link to comment Share on other sites More sharing options...
tommysticks Posted October 11, 2016 Author Share Posted October 11, 2016 Gah... so I'm getting an error with this: function UISibling.removeStuff() local player = getPlayer(); local pMod = player:getModData(); local pInv = player:getInventory(); local it = pInv:getItems(); local pID = pInv:FindAndReturn("IDCard"); for i = 0, it:size()-1 do local item = it:get(i); --STACK TRACE LINE #450 HERE pInv:Remove(item); end end The stacktrace is at : ----------------------------------------- STACK TRACE ----------------------------------------- Callframe at: get function: removeStuff -- file: sibling_func.lua line # 450 function: onMouseUp -- file: ISContextMenu.lua line # 98 java.lang.reflect.InvocationTargetException at sun.reflect.GeneratedMethodAccessor30.invoke(Unknown Source) 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:182) at se.krka.kahlua.vm.KahluaThread.luaMainloop(KahluaThread.java:983) at se.krka.kahlua.vm.KahluaThread.call(KahluaThread.java:163) at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1727) at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1642) at se.krka.kahlua.integration.LuaCaller.pcall(LuaCaller.java:63) at zombie.ui.UIElement.onMouseUp(UIElement.java:924) at zombie.ui.UIManager.update(UIManager.java:1085) at zombie.GameWindow.logic(GameWindow.java:583) at zombie.GameWindow.run(GameWindow.java:1233) at zombie.GameWindow.maina(GameWindow.java:1015) at zombie.gameStates.MainScreenState.main(MainScreenState.java:177) Caused by: java.lang.IndexOutOfBoundsException: Index: 12, Size: 6 at java.util.ArrayList.rangeCheck(ArrayList.java:604) at java.util.ArrayList.get(ArrayList.java:382) ... 18 more Link to comment Share on other sites More sharing options...
tommysticks Posted October 18, 2016 Author Share Posted October 18, 2016 My work around: for i = 0, (it:size()-1) do --stow primary inventory in table item = it:get(i); if item:getType() ~= "IDCard" and item:getType() ~= "KeyRing" then table.insert(iTable, item); print("Adding item ".. item:getType() .. " to iTable."); end end for i2, k2 in ipairs(iTable) do --removing items from inventory adding to IDCard print(k2:getType()..": removing from inventory to add to IDCard"); k2:setActualWeight(0); --sets weight to zero for transport in IDCard pInv:Remove(k2); pID:AddItem(k2); end The issue came when I was trying to iterate over an item that wasn't being removed. The solution was to iterate over every item and certain items add to a table. Then from that table remove/add items to the inventory. Thanks RoboMat! Link to comment Share on other sites More sharing options...
tommysticks Posted October 18, 2016 Author Share Posted October 18, 2016 (edited) Nothing to see here. Edited October 18, 2016 by tommysticks 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