Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Surplusguy on Sun 30/06/2013 04:19:20

Title: Interact twice automatically
Post by: Surplusguy on Sun 30/06/2013 04:19:20
Alright, so I've put in an interact function for an object. Once the object is interacted with, a variable goes up by one. Interacting with it again is supposed to produce a different interaction because of the variable, but the problem is, when it's interacted with once, the second interaction plays automatically without the need for a second click.

How can I fix this?

Thanks in advance :)
Title: Re: Interact twice automatically
Post by: Ghost on Sun 30/06/2013 04:37:35
Looks like you have a broken conditional statement there, but it's hard to tell without seeing the code.

It SHOULD be something line this (in order to WORK)

Code (AGS) Select

function ObjectInteraction()
{
  if (timesInteracted == 0)
  {
    timesInteracted++;
    player.Say("This is the first time my grubby fingers are touching this!");
  }
  else
  {
    player.Say("Aha! Something has changed and it feels totally different now!");
  }
}


Apart from that, your actual mouse-click script could be broken- are you calling it from more than one script file maybe?

In any case; probably best to post the code  :)
Title: Re: Interact twice automatically
Post by: Khris on Sun 30/06/2013 11:02:40
If guess you have something like this:
Code (ags) Select
  if (counter == 0) {
    // blah, stuff
    counter++;
  }
  if (counter == 1) {
    // blah, other stuff
  }

Obviously, by the time the second if is reached, counter was already incremented. Like Ghost says, use an "else". Or swap the two blocks. Or add a "return;" to the end of the first.
Title: Re: Interact twice automatically
Post by: Surplusguy on Sun 30/06/2013 17:22:20
Thanks guys, I think that should work.

EDIT: Yep, just using an else worked. I was confused because I required the player to interact with it about 6 times, but it did work.

Cheers!
Title: Re: Interact twice automatically
Post by: Khris on Mon 01/07/2013 09:16:28
If those 6 times are reproducible, and not due to you clicking next to the object, there's still something wrong with your code.

As a general note: post. your. code.