Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: PrimitiveUser on Sat 29/11/2008 17:06:08

Title: Having problems with the if player.activeinventory.... ..
Post by: PrimitiveUser on Sat 29/11/2008 17:06:08
Please help me.

Heres what i wanted there are 3 different kinds of axes to cut a tree.
1 axe is iron when i use the item on the tree it gives me 1 wood log.
when i use another axe a granite axe on the tree,  it gives 2 wood logs.
when i use a starfite axe on the tree it gives 3 logs.

heres the code that i use and it deoesnt work (dont make fun of me its stupid):


function hHotspot1_UseInv()
{
   if (player.ActiveInventory == iaxeiron) {
   player.AddInventory(ilog);
   Display("You have collected a log.");
     if (player.ActiveInventory == iaxegranite)
  player.AddInventory(ilog);
  player.AddInventory(ilog);
  Display("You have collected logs.");
     if (player.ActiveInventory == iaxestar)
  player.AddInventory(ilog);
  player.AddInventory(ilog);
  player.addinventory(ilog);
  Display("You have collected logs.");
}
else Display("You need an axe to cut this tree.");
}

insted of doing that when i use the iron axe it gives me 2 logs!!!! i wanted 1!
when i use granite and stafite it gives the you need an axe to cut this tree display thingy
can u give the code?
Title: Re: Having problems with the if player.activeinventory.... ..
Post by: Khris on Sat 29/11/2008 17:16:16
Mind the placement of the brackets:

function hHotspot1_UseInv() {
   if (player.ActiveInventory == iaxeiron) {
     player.AddInventory(ilog);
     Display("You have collected a log.");
  } // was missing
  if (player.ActiveInventory == iaxegranite) { // was missing
    player.AddInventory(ilog);
    player.AddInventory(ilog);
    Display("You have collected logs.");
  } // was missing
  if (player.ActiveInventory == iaxestar) { // was missing
    player.AddInventory(ilog);
    player.AddInventory(ilog);
    player.addinventory(ilog);
    Display("You have collected logs.");
  }
  else Display("You need an axe to cut this tree.");
}
Title: Re: Having problems with the if player.activeinventory.... ..
Post by: Gilbert on Sat 29/11/2008 17:18:58
Should be more 'else' added, otherwise the 'no axe' message will be displayed in the first two cases.

function hHotspot1_UseInv()
{
   if (player.ActiveInventory == iaxeiron) {
     player.AddInventory(ilog);
     Display("You have collected a log.");
  } else if (player.ActiveInventory == iaxegranite) {
    player.AddInventory(ilog);
    player.AddInventory(ilog);
    Display("You have collected logs.");
  } else if (player.ActiveInventory == iaxestar) {
      player.AddInventory(ilog);
     player.AddInventory(ilog);
     player.addinventory(ilog);
     Display("You have collected logs.");
 } else Display("You need an axe to cut this tree.");
}
Title: Re: Having problems with the if player.activeinventory.... ..
Post by: PrimitiveUser on Sat 29/11/2008 21:24:13
thanks u 2 guys but um lol u acidently forgot to put capitals in the 13th script...
but hey it works now!!
Title: Re: Having problems with the if player.activeinventory.... ..
Post by: Trent R on Sat 29/11/2008 21:37:13
As did you.... but at least the problems solved.

~Trent