Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Atelier on Wed 27/05/2009 16:37:02

Title: Listbox.ItemCount
Post by: Atelier on Wed 27/05/2009 16:37:02
Hullo. Sorry for posting twice in the same day.
I've sorted out a list box GUI at the bottom of the screen that displays everything the player's done, such as looking at something or "You picked up X item." and such.

Anyway, I don't want it to display everything since they began playing, so I'm trying to find a way to delete the items at the top of the list box (the ones less recent) if the number of things registered reaches 25, for example. Here's the code I've come up with:

if (ListBox.ItemCount <25) {
   ListBox.RemoveItem(0);
}

I've bunged this under game_start like I do with most things. When I run the game, the yellow box thing comes up and points at the second line - which I've highlighted in blue - and says 'ListBoxRemove: invalid listindex specified.' I have a feeling I have to create a global variable, but what's wrong?

Thanks in advance.
Title: Re: Listbox.ItemCount
Post by: monkey0506 on Wed 27/05/2009 17:22:50
Well you are checking if the number of items in the list is less than 25. Now that looks like pseudo code anyway, but are you sure you're using the > (greater than) symbol in your actual code? ;)

Oh, by the way this code would be better suited to repeatedly_execute anyway. game_start is called once when the game is very first loaded. repeatedly_execute is called once every game loop throughout the duration of the game.
Title: Re: Listbox.ItemCount
Post by: Atelier on Wed 27/05/2009 17:30:26
 :) No wonder it didn't work! :) (Pseudo code?)
I'd better edit my original post so nobody else sees my embarrassing mathematical blunder.

Thanks!
Title: Re: Listbox.ItemCount
Post by: monkey0506 on Wed 27/05/2009 18:59:18
I said it's pseudo-code because your listbox isn't really named ListBox. That wouldn't work. So it's fake code because it won't compile.

As far as the operator, it's a simple mistake but definitely one that could cause a lot of problems. ;)