expected '(' problem FIXED

Started by Melee Island Resident, Thu 09/06/2011 12:09:44

Previous topic - Next topic

Melee Island Resident

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?

ZapZap

#1
 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");
}
}
"Loose ends have a way of strangling you"

Khris

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:

Code: ags
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.

NickyNyce

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

abstauber

#4
Code: ags

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!

Matti

Abstauber, you still got the ActiveInventory part wrong ;)

abstauber


Melee Island Resident

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.

abstauber

Switching
Code: ags

 if (player.ActiveInventory == iMedallion)  {

to
Code: ags

 if (player.HasInventory(iMedallion) )  {


should do the trick.

Melee Island Resident

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

Matti

#10
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:

Code: ags

function Button5_OnClick(GUIControl *control, MouseButton button)
{
  gSaveGame.Visible = true;
  gIconbar.Visible = false;
}

Khris

Code: ags
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:
Code: ags
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)

SMF spam blocked by CleanTalk