Jump to content
tommysticks

[SOLVED] Transferring items

Recommended Posts

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 by tommysticks
Solved

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 by tommysticks

Share this post


Link to post
Share on other sites

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.

 

 

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...