View Single Post
02-23-18, 03:36 AM   #1
Eommus
An Aku'mai Servant
Join Date: Apr 2017
Posts: 34
Adding a delay to the execution of a loop

Hi,

I use the following code to sell all items in a given bag, which is triggered when I click a Sell button for that bag.

Code:
function SellAllInBag(bag)
	for slot = 1, GetContainerNumSlots(bag) do
		UseContainerItem(bag, slot)
	end
end
The above loop tries to sell all the items in the bag at the same time, so it gets stuck and I have to click the Sell button 2-3 times to sell all items in a large bag.

What I am looking for is to add some sort of a delay (e.g. 0.1 seconds) to the loop, so that it will sell all items with one click without getting stuck.

Something like:

Code:
function SellAllInBag(bag)
	for slot = 1, GetContainerNumSlots(bag) do
		UseContainerItem(bag, slot)
		-- wait for 0.1 seconds, then continue with the loop
	end
end
Is that possible in LUA coding?

Thanks.
  Reply With Quote