Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Play_Pretend on Thu 26/06/2008 01:10:49

Title: Empty Slot Problem in Custom Inventory GUI? [SOLVED]
Post by: Play_Pretend on Thu 26/06/2008 01:10:49
Hey y'all...I'm working on a custom Iconbar/Inventory popdown GUI, where the inventory is displayed as part of the iconbar menu.  It shows three items at a time, scrollable up and down to see more.  The problem is:

- When an item in the very bottom slot disappears from a LoseInventory command, it leaves an empty slot in its place when you come back to the inventory. 
- If you click upwards, the empty slot disappears and the inventory goes back to normal. 
- It happens again the next time you LoseInventory on the bottom slot. 
- This doesn't happen with any other slots.  Any idea what's going on and how to fix it?

If it helps at all, here's a previous thread where I asked for help with coding the GUI in the first place: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=34559.msg451738#msg451738

Thanks!
Title: Re: Empty Slot Problem in Custom Inventory GUI?
Post by: Ishmael on Thu 26/06/2008 01:25:09
The only way I can think of for fixing it is to check if the last item was removed, and if so, automatically scroll the inventory one up. I think LoseInventory can be trapped with OnEvent (or whatever it's called nowdays if it's been renamed)
Title: Re: Empty Slot Problem in Custom Inventory GUI?
Post by: Play_Pretend on Thu 26/06/2008 01:37:57
I tried adding these lines in to the global script for when my GUI pops down:

if (invCustomInv.ItemAtIndex[-1] == null) {
        invCustomInv.ScrollUp();
        }

I thought it worked at first, but it's wrong somehow...it scrolls up one item every time you open the GUI, instead of just when the last slot's empty.
Title: Re: Empty Slot Problem in Custom Inventory GUI?
Post by: TwinMoon on Thu 26/06/2008 02:12:54
(Intersting idea for a GUI btw.)

I can suggest a workaround: Use a custom function for loseinventory.

function Lose_Inventory(InventoryItem *item) {
  player.LoseInventory(item);
  invCustomInv.ScrollDown();
}

Every time the player loses an inventory item, call this function instead.


EDIT: It's completely untested, I think ScrollDown works since it goes to the last row. (which is one row higher, so ironically ScrollDown scrolls up here.)
If this doesn't work use ScrollUp.
Title: Re: Empty Slot Problem in Custom Inventory GUI?
Post by: Play_Pretend on Thu 26/06/2008 02:29:07
Thanks for the suggestion, but I'm afraid neither way worked.  It still just left the empty slot there regardless.  Any other thoughts?
Title: Re: Empty Slot Problem in Custom Inventory GUI?
Post by: TwinMoon on Thu 26/06/2008 02:36:03
I somehow got the idea you're showing three inventory items vertically, but if I read closely you didn't say that anywhere.
If you're showing 3 items next to each other, my solution wouldn't work.

However, I have another idea:

function Lose_Inventory(InventoryItem *item) {
  player.LoseInventory(item);
  UpdateInventory();
}

UpdateInventory rearranges the inventory, so that might do the trick.


EDIT: Um... if this works it's more efficient to drop the whole function and do UpdateInventory() before you show the GUI. (Sorry, got distracted).
Title: Re: Empty Slot Problem in Custom Inventory GUI?
Post by: Play_Pretend on Thu 26/06/2008 03:17:25
Huh!  UpdateInventory(); all by itself, just before the GUI visible command, did the trick, but in an unexpected way (at least, surprising to me :) ).  In the puzzle, you give one item, and receive another.  Before, it was adding the new item to the bottom of the inventory list.  Now it adds the new item into the slots in the order it appears in the AGS engine's inventory item menu.  Is that what UpdateInventory does, puts everything in that order?

(Ah, okay, I just read the manual entry about it, and yes, that's what it does.  :P )

It certainly solves the problem, but do you think that's going to annoy the players? :)  The items are shown vertically, I hate to spoil the surprise but here's the unfinished GUI, so you can see for yourself:

(http://www.2dadventure.com/ags/Hilt-GUI-withRings1.PNG)

Title: Re: Empty Slot Problem in Custom Inventory GUI?
Post by: Khris on Thu 26/06/2008 09:25:21
How about:
function on_event (EventType event, int data) {
  if (event == eEventLoseInventory && InvWindow.ItemAtIndex[2] == null) ScrollUp();
}
Title: Re: Empty Slot Problem in Custom Inventory GUI?
Post by: Play_Pretend on Thu 26/06/2008 11:41:07
I copied that into my global script, undid my previous changes, and tried it, and got:

Error (line 61): must have an instance of the struct to access a non-static member

Was I supposed to change something in it?

EDIT: I changed it to:


function on_event (EventType event, int data) {
  if (event == eEventLoseInventory && invCustomInv.ItemAtIndex[2] == null) invCustomInv.ScrollUp();
}


and also tried -1 instead of 2.  The error went away, but it still doesn't work.
Title: Re: Empty Slot Problem in Custom Inventory GUI?
Post by: Play_Pretend on Thu 26/06/2008 12:16:35
Aggggh!  I'm a retard.  :o  Twinmoon's solution worked with Scrollup, I just forgot to use Lose_Inventory instead of the normal cEgo.LoseInventory command.  :-[

EDIT:  Whoops, wait...it doesn't work from inside Hotspot interactions?  Can I not call functions from inside other functions?
Title: Re: Empty Slot Problem in Custom Inventory GUI?
Post by: Khris on Thu 26/06/2008 12:40:13
Did you import the function?

// header
import function Lose_Inventory(InventoryItem *item);
Title: Re: Empty Slot Problem in Custom Inventory GUI?
Post by: Play_Pretend on Thu 26/06/2008 12:46:16
Heh...I was just figuring that out right before you replied. :)  Sorry, I've never scripted functions before.  Do I need to import it at the top of each room's script?

EDIT:  Never mind, I toyed a bit and figured out that I only needed it in what few rooms had interactions that would end up in a LoseInventory moment.  Yay, consider this really solved now! :)
Title: Re: Empty Slot Problem in Custom Inventory GUI? [SOLVED]
Post by: TwinMoon on Thu 26/06/2008 16:40:22
Glad that it worked! Those picky parsers, always requiring every _ and ;  ;)
Ah, it's for Quest to End all Quests? That's very high on my my can't-wait-for-it list.

Anyway, if you want to import functions into every script, use the global header. It's in the "scripts" pane > GlobalScript.ash.
Title: Re: Empty Slot Problem in Custom Inventory GUI? [SOLVED]
Post by: Play_Pretend on Thu 26/06/2008 19:28:55
Twinmoon:  Yep, any time I ever come on here puzzled by unusual scripting problems it's for Q2EAQ. :)  Thanks again for your help...heh, I went ahead and already copied/pasted the import line to the top of each room's script before I got your message about the GlobalScript.ash.  Ah, well.  It works, anyways.  Thanks!