Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey! I got a question. I make a program to a game i play and i need some help. I have a listbox where i add items i get from a boss, i can then see how many of one item i've got and how big chance of recieving the item are. the list can look like this:

1. Magic seed
2. Magic logs
3. Green dragonhide
4. Torva platebody
5. Green dragonhide
6. Saradomin brews
7. Pure essence

what i want to do is to see how many "kills" ago i added the Torva platebody. And as you can see it's 3 kills ago. I just don't know how i should write the code to make the program count it. I want it to be there next time i open the program. I read a text file into the listbox where all that item is and then i can see how many of one item i've got in a label etc.. But how can i do to see how many kills ago i added the item "Torva platebody"?
Posted
Comments
Richard C Bishop 17-Apr-13 14:30pm    
Just use an incrementer and add one to it everytime you kill. Keep track of that number after the "Torva platebody" has been added.
Gramas19 17-Apr-13 14:51pm    
I tried that but i didn't really get it, could you please write a code to show me how you mean?
Richard C Bishop 17-Apr-13 14:54pm    
Without having any idea what language you are using I will give you an example in C# in a solution below.

1 solution

This is only an example of how to increment and not to be taken as a solution to the thread. Code is more readable here.
public static void Kill()
{
    int killIncrementer = 0;
    killIncrementer++;
}


That just increments an int eachtime a kill happens. You will want to store that number or set it to a label whenever you want.
 
Share this answer
 
Comments
Gramas19 17-Apr-13 15:00pm    
Thanks, yes i am using C# :) and i guess that will work but how can i then make it remember it next time i start the program, cause when i restart it, it will say 0 but i want it to say 3 or whatever it is.
Richard C Bishop 17-Apr-13 15:01pm    
I would store it in a database. That is your best bet I would say. So each time the game shuts off, just send that value to a table and then query it when the game starts back up to populate the label again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900