Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: snrub_guy on Sat 05/12/2009 15:33:40

Title: Problem with basic variables scripting
Post by: snrub_guy on Sat 05/12/2009 15:33:40
Hi there, sorry if this is a simple issue, but i'm going over the scripting tutorial, and I can't see why this script shouldn't work- I'm trying my first scripting using variables, and like in the tutorial I wanted the character to respond slightly differently the second time they interact with the object. The error that it tells me is that it is expecting a "{" at line 8 (function hMousehole_Interact()), but I did not think I needed one there. I tried just giving it a set of brakets, but then it tells me that it does not expect the next "if" to be there. The script is below. Any help would be appreciated. Thanks, M.
// room script file
int Mousecounter = 0;
function hMousehole_Look()
{
Display("It's where our house mouse, Bitey lives.");
}

function hMousehole_Interact()

if (Mousecounter == 0)
{
Display("Let's see if Bitey wants to join us for an adventure!");
Display("Ow! No. Bitey does not want to join us at this time.");
}
if (Mousecounter == 1)
{
  Display("I think I have put my hand in there enough for one day.");
}
if (Mousecounter < 1)
{
  Mousecounter += 1;
}
Title: Re: Problem with basic variables scripting
Post by: Ethan D on Sat 05/12/2009 15:59:23
Just add brackets at the beginning and end of the function hMousehole_Interact().  Like this

// room script file
int Mousecounter = 0;
function hMousehole_Look()
{
Display("It's where our house mouse, Bitey lives.");
}

function hMousehole_Interact()
{  
if (Mousecounter == 0)
{
Display("Let's see if Bitey wants to join us for an adventure!");
Display("Ow! No. Bitey does not want to join us at this time.");
}
if (Mousecounter == 1)
{
 Display("I think I have put my hand in there enough for one day.");
}
if (Mousecounter < 1)
{
 Mousecounter += 1;
}
}

Edit:  Also, for changing the variable you could just put Mousecounter = 1;  in this section like this

if (Mousecounter == 0)
{
Display("Let's see if Bitey wants to join us for an adventure!");
Display("Ow! No. Bitey does not want to join us at this time.");
Mousecounter = 1;
}

And this part is unnecesarry
if (Mousecounter < 1)
{
 Mousecounter += 1;
}


Title: Re: Problem with basic variables scripting
Post by: monkey0506 on Sat 05/12/2009 16:02:21
You're missing the opening and closing braces for your function:
function hMousehole_Interact()
{
if (Mousecounter == 0)
{
Display("Let's see if Bitey wants to join us for an adventure!");
Display("Ow! No. Bitey does not want to join us at this time.");
}
if (Mousecounter == 1)
{
 Display("I think I have put my hand in there enough for one day.");
}
if (Mousecounter < 1)
{
 Mousecounter += 1;
}
}
I'd highly recommend you use indentation to better visualize where these types of problems are coming from. Also you can use [code] and [/code] to encapsulate code like this:

function hMousehole_Interact()
{
 if (Mousecounter == 0)
 {
   Display("Let's see if Bitey wants to join us for an adventure!");
   Display("Ow! No. Bitey does not want to join us at this time.");
 }
 if (Mousecounter == 1)
 {
   Display("I think I have put my hand in there enough for one day.");
 }
 if (Mousecounter < 1)
 {
   Mousecounter += 1;
 }
}


;) Welcome to the forums (and AGS) as well.

Ethan beat me to the punch. Ah well.
Title: Re: Problem with basic variables scripting
Post by: snrub_guy on Sat 05/12/2009 16:10:40
Thanks very much! To both of you! A very speedy reply. Ciao for now, I'll no doubt find new things to ask shortly...
Title: Re: Problem with basic variables scripting
Post by: monkey0506 on Sat 05/12/2009 16:18:19
You're welcome. I also wanted to mention that for these one-off variables (where you want to do something once and then something different the rest of the game) you can use the Game.DoOnceOnly function such as:

function hMousehole_Interact()
{
  if (Game.DoOnceOnly("use mouse hole"))
  {
    Display("Let's see if Bitey wants to join us for an adventure!");
    Display("Ow! No. Bitey does not want to join us at this time.");
  }
  else
  {
    Display("I think I have put my hand in there enough for one day.");
  }
}