SOLVED: add number to int in a function

Started by Gepard, Thu 03/03/2011 22:34:22

Previous topic - Next topic

Gepard

How, I have this function that basically removes a certain item from a list.

   
Code: ags
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.
Drink up me 'arties! Yo ho!

Khris

Just add the xp the player gains as parameter to the function:

Code: ags
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);

Gepard

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.
Drink up me 'arties! Yo ho!

Matti

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

Gepard

#4
EDIT: Now I see! I forgot to change the header of that function to match. Sorry guys.
Drink up me 'arties! Yo ho!

SMF spam blocked by CleanTalk