Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Rd27 on Fri 13/08/2004 22:43:59

Title: Problem with my_counter;
Post by: Rd27 on Fri 13/08/2004 22:43:59
I have little problem with this my_counter.

I have placed top of my room script int my_counter; and I have placed this to one of the hotspots:

if (my_counter == 0) {
  DisplaySpeech(EGO,"xxxxxxxxxxxxxx");
  }
if (my_counter == 1) {
  DisplaySpeech(EGO,"xxxxxxxxxxxxxx");
  }
if (my_counter == 2) {
  DisplaySpeech(EGO,"xxxxxxxxxxxxxx"
  }
if (my_counter <2) {
  my_counter ++;
  }

It works fine, but I want to make more of these in same room. How can I do that? I tried to look at he manual, but didn't find.

Thanks
Title: Re: Problem with my_counter;
Post by: Alynn on Sat 14/08/2004 04:23:37
since you want them global to the room you can just make more variables to use... if you want to just have one variable, you can make it an array

int my_counter[x]; //Where x is the number of vars you need

Then access them by

if (my_counter[0]<1)

EDIT stupid Yabb code didn't like me using braces :(
Title: Re: Problem with my_counter;
Post by: Goot on Sat 14/08/2004 07:05:53
I'm not exactly sure what you mean by 'I don't want to make more of these in the same room.' Do you want to use that script for multiple hotspots. If so you can make it a function. Put in the room script, after defining variables:

function x(){
if (my_counter == 0) {
  DisplaySpeech(EGO,"xxxxxxxxxxxxxx");
  }
else if (my_counter == 1) {
  DisplaySpeech(EGO,"xxxxxxxxxxxxxx");
  }
else if (my_counter == 2) {
  DisplaySpeech(EGO,"xxxxxxxxxxxxxx");
  }
if (my_counter <2) {
  my_counter ++;
  }
}

whenever you want to use it in a script, put x(); or whatever you made the function name. I also added else if's in there to make it neater. It doesn't make much difference but it's more efficient if the computer doesn't have to check each statement everytime...whatever, it doesn't really matter.

Hopefully this will help.
Title: Re: Problem with my_counter;
Post by: Ashen on Sat 14/08/2004 12:43:40
Or, just make more variables:

int my_counter;
int my_counter2;
int my_counter3;
... and so on, as many as you need. Or give them names that reflect the hotspot they're related to.


Edit: This may be exactly what Alynn said. Sorry.
Title: Re: Problem with my_counter;
Post by: Rd27 on Sat 14/08/2004 15:27:34
It is working now like I wanted it to work :)

Thanks for help!!! ;D