Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Melee Island Resident on Thu 09/06/2011 12:09:44

Title: expected '(' problem FIXED
Post by: Melee Island Resident on Thu 09/06/2011 12:09:44
function region1_WalksOnto()
{
if player.ActiveInventory(iMedallion);
player.ChangeRoom(11);{
}
else player.Say("I feel drawn to something in this room")
player.Say("I really want to find out what it is");

I have this code and I keep getting this error message:

room9.asc(87): Error (line 87): expected '('

I've tried for the past few hours to fix this, but I can't, could someone please explain to me why I'm an idiot?
Title: Re: expected '(' problem
Post by: ZapZap on Thu 09/06/2011 12:24:24
 you should put
function region1_WalksOnto()
{
if (player.ActiveInventory==iMedallion){
player.ChangeRoom(11);
}
else {player.Say("I feel drawn to something in this room");
player.Say("I really want to find out what it is");
}
}
Title: Re: expected '(' problem
Post by: Khris on Thu 09/06/2011 12:43:24
After an "if (condition)" you don't put a semicolon but either a single command or several encased in { and }.
The condition must be encased in ( and ) (the reason for the error you got), and player.ActiveInventory isn't a function but a pointer pointing to an inventory item.

None of you use indentation so here's how it is supposed to look:

function region1_WalksOnto()
{
 if (player.ActiveInventory == iMedallion)
 {
   player.ChangeRoom(11);
 }
 else
 {
   player.Say("I feel drawn to something in this room");
   player.Say("I really want to find out what it is");
 }
}


Now you can immediately see what the function body is and what's going to happen depending on the if condition.
I'd suggest to start using indentation now, your original code looked like you were merely guessing at where to put which bracket, so seeing the underlying structure should definitely help.
AGS will also do all the indenting automatically if you hit enter after { or }.

Like I said, the brackets around "player.ChangeRoom(11);" are optional since they contain only one command.

The most important thing though is to get the syntax straight.
Title: Re: expected '(' problem
Post by: NickyNyce on Thu 09/06/2011 12:44:44
check out Densming's video's on youtube, they are very helpful for beginners.
just type in...How to use ags part 1, there are forty something videos, they are light years old but still do the trick.

seems like you are confusing Addinventory with Activeinventory

check out video...how to use ags part 27, that will show you the problem you are having
Title: Re: expected '(' problem
Post by: abstauber on Thu 09/06/2011 12:44:58

function region1_WalksOnto()
{
  if (player.ActiveInventory == iMedallion)  {
    player.ChangeRoom(11);
  }
  else {
    player.Say("I feel drawn to something in this room");
    player.Say("I really want to find out what it is");
  }
}


If you indent you code, you don't run into bracket problems that fast.

Argh, Khris... you're too fast for me!
Title: Re: expected '(' problem
Post by: Matti on Thu 09/06/2011 12:50:40
Abstauber, you still got the ActiveInventory part wrong ;)
Title: Re: expected '(' problem
Post by: abstauber on Thu 09/06/2011 12:51:57
Haha, damn  ;D

me fixes.
Title: Re: expected '(' problem
Post by: Melee Island Resident on Thu 09/06/2011 13:08:40
okay what i'm trying to do is if the player has iMedallion in their inventory, then region1 takes them to room 8, but this just runs the same dialog every time i go on it and doesn't take me to room 8, and when the dialog runs background 0 and 1 keep alternating.

I can probably fix the background problem my self but could anyone help me with inventory thing? I blame myself for not explaining to you guys what I was hoping to do.
Title: Re: expected '(' problem
Post by: abstauber on Thu 09/06/2011 13:24:31
Switching

if (player.ActiveInventory == iMedallion)  {

to

if (player.HasInventory(iMedallion) )  {


should do the trick.
Title: Re: expected '(' problem FIXED
Post by: Melee Island Resident on Sat 11/06/2011 19:26:27
function Button5_OnClick(GUIControl *control, MouseButton button)
{
gSaveGame.Visible = true;

{
  if gSaveGame.Visible = true  {
    gIconbar.Visible = false;
  }

}

GlobalScript.asc(600): Error (line 600): expected '('

help please you guys
Title: Re: expected '(' problem
Post by: Matti on Sat 11/06/2011 20:26:25
A condition must be enclosed by (and). Also, in a condition you need to change = to ==.

if (gSaveGame.Visible == true)

Also, you can shorten the whole thing to this:

if (gSaveGame.Visible) gIconbar.Visible = false;

EDIT: You don't even need the condition because the GUI is visible in any case:


function Button5_OnClick(GUIControl *control, MouseButton button)
{
  gSaveGame.Visible = true;
  gIconbar.Visible = false;
}
Title: Re: expected '(' problem
Post by: Khris on Sat 11/06/2011 20:28:25
function Button5_OnClick(GUIControl *control, MouseButton button)
{
  gSaveGame.Visible = true;

  if (gSaveGame.Visible)
  {
    gIconbar.Visible = false;
  }
}


Not sure what you're doing there; this code will give the same result:
function Button5_OnClick(GUIControl *control, MouseButton button)
{
  gSaveGame.Visible = true;
  gIconbar.Visible = false;
}


You're turning gSaveGame visible so of course it's going to be visible one line down in the code.
I suspect what you're trying to do is to turn off gIconbar whenever gSaveGame is visible, right?
You do things like that in repeatedly_execute.

Also please read what we wrote earlier:
QuoteThe condition must be encased in ( and ) (the reason for the error you got)