Skip to main content
gamedev.net
🔒 Locked

ListBox

Started by Daboy Dec 21, 2001 at 4:47 PM 5 replies 1.3k views
Original Post
Daboy
Daboy
Hey, Im making a Tcp/Ip type RPG game. A text like game. Well anyway in a ListBox i have all the weapons and how many times you can use them. for Example LongSword 2. How can i change the items in the listbox therefore decreasing the number of the weapon used? and when reaching 0 makes it unavailable?? Thx
Jordan Weberwww.pheonixsoftware.com
Arctic Weasel
Arctic Weasel
Hello, I am Arctic Weasel and this is my first posting
here...

If you want to decrement a quantity of one of your weapons,
start at the end of your string and work backward until
you encounter a space:

str,numstr:string;

str:=ListBox1.Items[index];

for i:=Length(string) downto 1 do begin
if (string=' ') then
break;
numstr:=string[i]+numstr;
end;

Now you have a string with just the number in it, and
you can convert it, decrement it, and replace the
string in the stringlist.

Do you always want the complete list of weapons in this
ListBox? If not, what you should do is start at the end,
something like:

for i:=ListBox1.Items.Count-1 downto 0 do
if ListBox1[i] needs deleting then
ListBox1.Items[i].Delete;

By starting at the end, you won't have to
constantly evaluate where the end of your
listbox is.


Edited by - Arctic Weasel on December 22, 2001 3:25:41 PM
Fitzbean
Fitzbean
Better yet have an Quantiy box next to the list down, which holds the # of times for the weapon that is currently selected in the list.
Fitz
Daboy
Daboy
How would i go about that??
Jordan Weberwww.pheonixsoftware.com
Fitzbean
Fitzbean
simply set up a weapons object:

TWeapon = record
name : String;
usesremaining : Integer;
end;

TWeapons = record
Weapon : Array [1..xx] of TWeapon;
end;

Then load the names into the listbox and call the usesremaining as needed.
Fitz
MButchers
MButchers
Hi there,

when you add the item to the list box store the
index it was added in

  

Item.ListIndex := ListBox.Items.Add(Item.Name) + '' '' + IntToStr(Item.ChargesLeft);



Then when you change the value of the charges

  

ListBox.Items.Strings[Item.ListIndex] := Item.Name + '' '' + IntToStr(Item.ChargesLeft);



If you make the Item a class then you could make "charges left" a property
and encapsulate all the code in the actual item class, so when you change
charges it automatically updates the listbox.

Hope it helps ( and makes sence )

Mark
Daboy
Daboy
Yeah, that makes more sense thanks ill have to try that.
Jordan Weberwww.pheonixsoftware.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.