Inventory dialog response
#2

You should think about using an enum or defines for dialog IDs. It's gonna be a pain at some point to juggle with plain numbers. Also searching for a number will bring up duplicates at some point which won't happen with dialog names like "DIALOG_INVENTORY". But that just as a side note.

To detect the item the player clicked there are a few ways to do this.

You could include the Item Slot in the dialog text in the first position, which would then be assigned to "inputtext" from OnDialogResponse when the player selects an item.

So if you click a dialog row called "45\tBread\n", inputtext will contain "45" (it won't contain tabs or text after tabs). Convert this to a decimal using sscanf or strval and you have the slot ID the player clicked.

Alternatively you execute the same loop you used to generate the list, only this time you count down listitem instead of assembling the text. Once listitem is 0, the loop counter (i) will be at the slot the player clicked (this basically counts the number of valid items until the selection was found).

Your loop is close to it, but you need to add the check you did during show dialog (if the slot contains an item), and instead of comparing listitem to i, you subtract one and compare it with 0.
Reply


Messages In This Thread
Inventory dialog response - by SaiyanZ - 28.03.2019, 12:42
Re: Inventory dialog response - by NaS - 28.03.2019, 13:16
Re: Inventory dialog response - by SaiyanZ - 28.03.2019, 14:22
Re: Inventory dialog response - by NaS - 28.03.2019, 14:56
Re: Inventory dialog response - by SaiyanZ - 28.03.2019, 16:33

Forum Jump:


Users browsing this thread: 1 Guest(s)