Parse error in Global Script

Started by Zephyr, Sat 28/12/2019 11:40:40

Previous topic - Next topic

Zephyr

Hi again everyone!

So I've reached a point in my game where my main character shoots and kills another character (simply called cVictim), but I want the main character to interact differently with cVictim, depending upon whether she's alive or dead.  So I put in GlobalScript.ash:

Code: ags
bool IsVictimDead = false;


and in GlobalScript.asc:

Code: agsfunction cVictim_Look()
{
      if (IsVictimDead == false)
(     
         cChristian.FaceDirection (eDirectionUp))
         cChristian.LockViewFrame (CHRISTIAN_NORMAL, 3, 1, eStopMoving);
         cChristian.SayAt (15, 191, 300, "It appears to be a female but it's making a horrible sound...");
         Wait (5);
         cChristian.SayAt (15, 191, 300, "There's something very wrong here!");
         Wait (5);
         cChristian.UnlockView (eKeepMoving);
         cChristian.LockView (1);
}
    else
(
         cChristian.Walk (150, 68, eBlock, eWalkableAreas);
         cChristian.FaceDirection (eDirectionUp);
         Wait (5);
         cChristian.ChangeRoom (64);
}
}


But when I try to run the game, I'm getting a parse error at the line " if (IsVictimDead == false)".
I just can't seem to work out where I'm going wrong.  Can anyone help, please?  Remember - simplified instructions only please!  :cheesy:

- Zephyr
<3 Zephyr <3

eri0o

I don't think you can define a variable in the header like you did. You can though go into the Global Variables panel and create one there.

I think you mistyped when writing the code inside the global script in your post (it's empty).

Crimson Wizard

#2
Quote from: eri0o on Sat 28/12/2019 11:58:40
I don't think you can define a variable in the header like you did. You can though go into the Global Variables panel and create one there.

You can declare a variable's import in the header, with the "import" keyword.

in GlobalScript.ash:
Code: ags

import bool IsVictimDead;

^ this will tell every other script that such variable exists (somewhere), so they can use it.

in GlobalScript.asc:
Code: ags

bool IsVictimDead = false;
export IsVictimDead;

^ this will actually create such variable, and also export it for use in other modules.

Global Variables panel simplifies this process, but in the end it automatically generates same code.

Khris

#3
You're getting a parse error because you're opening your if blocks with ( instead of {. The syntax is

Code: ags
  if (condition) // parens for condition
  { // curly brace to open block of statements
    ...
  } // curly brace to close block


You also have a missing semi-colon near the start.

Unrelated but not less important: if you declare a variable in the header, you will create a separate one for each script, which is not what you want, usually.

Final note: given that the variable is a bool, you can do this:
Code: ags
  if (IsVictimDead) {
    ...
  }
  else {
    ...
  }

Zephyr

Hi everyone,

Thanks again so much for your help. Sorry about the missing script - I must have mistyped as you said! 

@Crimson Wizard - Your suggestion about "import bool" is working perfectly, so many thanks for that.  I still get SO confused about what goes where and about the correct syntax!

@Khris - Yep! You got me there! It turns out that I'd mistakenly used ( instead of { in a couple of places.  Can't believe I made such a silly mistake (it just goes to show that scripting is NOT a good idea when you're tired!).

- Zephyr  :-[ :-*
x
<3 Zephyr <3

Khris

Btw, the code is in your post (that's how I knew what the parse error was) but you accidentally deleted the ] from the opening code tag.

SMF spam blocked by CleanTalk