Help with cEgo.ActiveInventory

Started by Facu87, Thu 31/01/2008 21:56:43

Previous topic - Next topic

Facu87

Hi Forumers!
(First, Im from Argentina, sorry for my "English" xD)

Im having trouble with my AGS project, especially with that function (c.Ego.ActiveInventory). Here is the principal code:

Code: ags
function Pato_UseInv()
{
if (cEgo.ActiveInventory == iPlata) 
Display("Mmg.. si tenias unos pesos mas hablabamos. PERO NO");

else if (cEgo.ActiveInventory == iEntrada) 
Display("Pasa pibe ya empieza");
cEgo.ChangeRoom(6, 112, 240);
}


Principally I have a problem, when I use "iPlata" on this Character, it says that ("Mmg.. bla bla"), but it also Changes the room!
I cant explain me very good, the function of any object is always the same!
I dont know what's happening, and I will be pleased if anyone could help me..

(Sorry for my English again xD)

Khris

#1
That's funny because that exact problem was addressed incidentally in the other thread :)

If you want to execute more than one command only after a condition is met, you have to group the commands together using a {} block:

Code: ags
function Pato_UseInv()
{
  if (cEgo.ActiveInventory == iPlata) 
    Display("Mmg.. si tenias unos pesos mas hablabamos. PERO NO");

  else if (cEgo.ActiveInventory == iEntrada) {    // open the block
    Display("Pasa pibe ya empieza");
    cEgo.ChangeRoom(6, 112, 240);
  }                                              // close the block
}


I'd suggest to get used to indenting your code like I did from the start, saves loads of debugging time :)

Of course there doesn't have to be more than one command inside the block. Putting the curly brackets around a single command:
Code: ags
  if (cEgo.ActiveInventory == iPlata) {
    Display("Mmg.. si tenias unos pesos mas hablabamos. PERO NO");
  }

will work fine.

Facu87

It Works!

Thanks Man, I've thought that was something related to brackets xD..

Thanks very much Again, you're very kind!

Khris

You're welcome, and btw, your english is very good, better than some natives' ;)

SMF spam blocked by CleanTalk