Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Facu87 on Thu 31/01/2008 21:56:43

Title: Help with cEgo.ActiveInventory
Post by: Facu87 on Thu 31/01/2008 21:56:43
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:

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)
Title: Re: Help with cEgo.ActiveInventory
Post by: Khris on Thu 31/01/2008 22:05:30
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:

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:
  if (cEgo.ActiveInventory == iPlata) {
    Display("Mmg.. si tenias unos pesos mas hablabamos. PERO NO");
  }

will work fine.
Title: Re: Help with cEgo.ActiveInventory
Post by: Facu87 on Thu 31/01/2008 22:26:03
It Works!

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

Thanks very much Again, you're very kind!
Title: Re: Help with cEgo.ActiveInventory
Post by: Khris on Thu 31/01/2008 22:41:25
You're welcome, and btw, your english is very good, better than some natives' ;)