Empty Slot Problem in Custom Inventory GUI? [SOLVED]

Started by Play_Pretend, Thu 26/06/2008 01:10:49

Previous topic - Next topic

Play_Pretend

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!

Ishmael

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)
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Play_Pretend

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.

TwinMoon

#3
(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.

Play_Pretend

Thanks for the suggestion, but I'm afraid neither way worked.  It still just left the empty slot there regardless.  Any other thoughts?

TwinMoon

#5
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).

Play_Pretend

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:




Khris

How about:
Code: ags
function on_event (EventType event, int data) {
  if (event == eEventLoseInventory && InvWindow.ItemAtIndex[2] == null) ScrollUp();
}

Play_Pretend

#8
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:

Code: ags

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.

Play_Pretend

#9
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?

Khris

Did you import the function?

Code: ags
// header
import function Lose_Inventory(InventoryItem *item);

Play_Pretend

#11
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! :)

TwinMoon

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.

Play_Pretend

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!

SMF spam blocked by CleanTalk