ActiveInventory with Distance function problem

Started by barefoot, Fri 12/02/2010 19:31:26

Previous topic - Next topic

barefoot

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


Code: ags

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

}






I May Not Be Perfect but I Have A Big Heart ..

monkey0506

The problem is that when the ActiveInventory is set to iduster you're not doing anything:

Code: ags
  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.

barefoot

Many thanks Monkey

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

Yes, need logic...

cheers

barefoot
I May Not Be Perfect but I Have A Big Heart ..

Ryan Timothy B

You should also keep an eye on the brace finger, it seems trigger happy or perhaps just a nervous twitch. ;D

barefoot

I May Not Be Perfect but I Have A Big Heart ..

SMF spam blocked by CleanTalk