Listbox.ItemCount

Started by Atelier, Wed 27/05/2009 16:37:02

Previous topic - Next topic

Atelier

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.

monkey0506

#1
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.

Atelier

 :) No wonder it didn't work! :) (Pseudo code?)
I'd better edit my original post so nobody else sees my embarrassing mathematical blunder.

Thanks!

monkey0506

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. ;)

SMF spam blocked by CleanTalk