Having problems with the if player.activeinventory.... ..

Started by PrimitiveUser, Sat 29/11/2008 17:06:08

Previous topic - Next topic

PrimitiveUser

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?

Khris

Mind the placement of the brackets:

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

Gilbert

Should be more 'else' added, otherwise the 'no axe' message will be displayed in the first two cases.
Code: ags

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.");
}

PrimitiveUser

thanks u 2 guys but um lol u acidently forgot to put capitals in the 13th script...
but hey it works now!!

Trent R

As did you.... but at least the problems solved.

~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

SMF spam blocked by CleanTalk