How, I have this function that basically removes a certain item from a list.
function LoseQuest(String text){
int p;
while (p < quests.ItemCount){ //Change ListBox1 with the name of your listbox
if (quests.Items[p].CompareTo(text, false) == 0){ //Change ListBox1 with the name of your listbox
quests.RemoveItem(p); //Change ListBox1 with the name of your listbox
PlaySound (10);
return;
}
p ++;
}
}
I also have an int called "experience". Now what I wish to do is add the possibility not only write what quest (item) will the player lose but also how much experience will he get for it. Any idea how? Thanks.
Just add the xp the player gains as parameter to the function:
function LoseQuest(String text, int xp_gained) { // ADDED int PARAMETER
int p;
while (p < quests.ItemCount) { //Change ListBox1 with the name of your listbox
if (quests.Items[p].CompareTo(text, false) == 0) { //Change ListBox1 with the name of your listbox
quests.RemoveItem(p); //Change ListBox1 with the name of your listbox
PlaySound (10);
experience += xp_gained; // <------------ ADDED THIS LINE
return;
}
p ++;
}
}
Now call the function like this:
LoseQuest("Tutorial", 20);
Hi. Thanks for the cod. Im having a problem with it as it wont compile:
First when I add exgain to integers:
---------------------------
Compile Error
---------------------------
'exgain' is a global var; cannot use as name for local.
Than without it:
---------------------------
Compile Error
---------------------------
Function declaration has wrong number of arguments to prototype.
So I do not know how to do it, although I know Im doing some silly mistake.
If exgain is a global variable then just name it differently ;)
Of course when you call the function you can put whatever variable you like as the parameter (like 'exgain').
EDIT: Now I see! I forgot to change the header of that function to match. Sorry guys.