Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: JadeWizard on Wed 01/05/2019 13:31:19

Title: Function does not stop after warning dialog.
Post by: JadeWizard on Wed 01/05/2019 13:31:19
So if you touch this cactus it sends you to the game over screen. I wanted it to warn you the first time you click on it then if you clicked it again it kills you. Problem is after clicking it for the first time it plays all the dialog and sends you to the game over screen anyway.

Feels like I'm missing something but I don't know what it is. Oof!  :confused:

Code (ags) Select


function cactus_Interact()
{
cNinja.Walk(1594, 536, eBlock, eWalkableAreas) ;
if ( WarningCounter <= 0 )
cNinja.StopMoving() ;
cDrunk.Say("I wouldn't do that if I were you.") ;
WarningCounter++ ;
cNinja.FaceCharacter(cDrunk) ;
Wait(150) ;

if ( WarningCounter <= 1 )
cDrunk.Say("Alright but don't say I didin't warn you.") ;
cNinja.FaceLocation(1990, 450) ;
Display("You reach out and touch the cactus") ;
player.Say("Ouch!") ;
Display("Well that cactus did strange things to your body. It was wonderful while it lasted. All those bright colors and wacky things you saw. But...") ;
Display("Then you died.") ;
player.ChangeRoom(300) ;

Title: Re: Function does not stop after warning dialog.
Post by: Cassiebsg on Wed 01/05/2019 13:55:33
You are missing the { } brakets to hold your code in a block and the last if needs to either be a else or else if.

Essentially what you currently have have is if ( WarningCounter <= 0 ) cNinja.StopMoving() ; Which of course runs cause your warning counter is at zero at the moment. then you run all the next code where you add +1 to the counter. Then you execute if ( WarningCounter <= 1 ) cDrunk.Say("Alright but don't say I didin't warn you.") ; Which of course runs, since you previously told it to add 1 to the counter, and after that you run all the code after that.

What you want to do is:

Code (ags) Select

function cactus_Interact()
{
  cNinja.Walk(1594, 536, eBlock, eWalkableAreas) ;
  if ( WarningCounter <= 0 )
  {
    cNinja.StopMoving() ;
    cDrunk.Say("I wouldn't do that if I were you.") ;
    WarningCounter++ ;
    cNinja.FaceCharacter(cDrunk) ;
    Wait(150) ;
  }
  else
  {
    cDrunk.Say("Alright but don't say I didin't warn you.") ;
    cNinja.FaceLocation(1990, 450) ;
    Display("You reach out and touch the cactus") ;
    player.Say("Ouch!") ;
    Display("Well that cactus did strange things to your body. It was wonderful while it lasted. All those bright colors and wacky things you saw. But...") ;
    Display("Then you died.") ;
    player.ChangeRoom(300) ;
  }
}
[/ags]
Title: Re: Function does not stop after warning dialog.
Post by: JadeWizard on Wed 01/05/2019 17:53:18
Ack I knew it was something simple, can't believe I forgot the brackets. After looking over the manual again I also found out why my counter wasn't working, I had to put WarningCounter += 1; at the end of the argument not in the middle.

Thanks man.  :grin: