Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: barefoot on Fri 12/02/2010 19:31:26

Title: ActiveInventory with Distance function problem
Post by: barefoot on Fri 12/02/2010 19:31:26
Hi

I am having trouble inplementing the below code. Its the ActiveInventory that Is giving me problems as any inv can be used. The else statement works as does the distance settings.
When a player comes to close to the main character the main character can knock them out with a knuckleduster (iduster), would also like to have the choice with baseball bat (ibat)...

Can anyone shed some light?

cheers
barefoot



function cHank_UseInv()
{
if (player.ActiveInventory == iduster)

{
}
 
  if ((cHank.x - cEgo.x <=90 && cHank.x >= cEgo.x) || (cEgo.x - cHank.x < 90 && cEgo.x > cHank.x))

{
cHank.Say("Ouch!");

{
  cEgo.Say("sorry mate");
  Display("He falls down and you drag him off and hide him in the bushes");
    Display("You search him and find a knife");
    player.AddInventory(iknife);

  SetTimer(1,0);
  cHank.ChangeRoom(30);
 
}
 
}
else
 
  {
     Display("That's no good!!");
   
}

}






Title: Re: ActiveInventory with Distance function problem
Post by: monkey0506 on Fri 12/02/2010 19:43:44
The problem is that when the ActiveInventory is set to iduster you're not doing anything:

  if (player.ActiveInventory == iduster)

{
}


The next condition does not take the ActiveInventory into account at all and only compares the x co-ordinates of cEgo and cHank. The reason it's not working is because you're never using ActiveInventory to do anything. Ever. At all.

Try nesting the conditions properly:
function cHank_UseInv()
{
  if (player.ActiveInventory == iduster || player.ActiveInventory == ibat)
  {
    // removed closing brace
    if ((cHank.x - cEgo.x <=90 && cHank.x >= cEgo.x) || (cEgo.x - cHank.x < 90 && cEgo.x > cHank.x))
    {
      cHank.Say("Ouch!");
      // removed pointless and unneeded opening brace
      cEgo.Say("sorry mate");
      Display("He falls down and you drag him off and hide him in the bushes");
      Display("You search him and find a knife");
      player.AddInventory(iknife);
      SetTimer(1, 0);
      cHank.ChangeRoom(30);
    }
  }
  else
  {
    // ActiveInventory was NOT iduster or ibat
    Display("That's no good!!");
  }
}


The code is only going to do what you tell it to. It's not going to do your work for you. In short, bad logic is bad.
Title: Re: ActiveInventory with Distance function problem SOLVED
Post by: barefoot on Fri 12/02/2010 20:33:26
Many thanks Monkey

I definately need to keep my eye on my braces.. {}   ;)

Yes, need logic...

cheers

barefoot
Title: Re: ActiveInventory with Distance function problem
Post by: Ryan Timothy B on Fri 12/02/2010 22:30:16
You should also keep an eye on the brace finger, it seems trigger happy or perhaps just a nervous twitch. ;D
Title: SOLVED: ActiveInventory with Distance function problem
Post by: barefoot on Thu 18/02/2010 12:35:26
 ;) YEH