Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: KANDYMAN-IAC on Thu 18/08/2016 08:34:52

Title: Scripting issue, GlobalScript.ash(7): Error (line 7): PE03: Parse error at '1'
Post by: KANDYMAN-IAC on Thu 18/08/2016 08:34:52
Hello World,

It's been 13 years since my first game, and 6 years since I was last here. I logged in to review my original game and update it for the new millenium... and possibly ios...

Well in upgrading it from 2.71 to ANY version of 3 I have hit a few snags.

I am getting a single coding error.
room3.asc(301): Error (line 301): Undefined token 'unhandled_event'

the unhandled event on line 301 is unhandled_event(1, 3)... which is used elsewhere with no issues.

Code (ags) Select
function hHotspot3_UseInv()
{
if (player.ActiveInventory == inventory[18]) {
hotspot3_a();
}
else {
unhandled_event(1, 3);
}
}


SO I did some research and added to the global header...
Code (ags) Select
import function unhandled_event(1, 3);

BUT this just yields this error...
GlobalScript.ash(7): Error (line 7): PE03: Parse error at '1'


It's been years... I got nothing.
Title: Re: Scripting issue, GlobalScript.ash(7): Error (line 7): PE03: Parse error at '1'
Post by: Crimson Wizard on Thu 18/08/2016 12:42:34
When you declare (import) a function, you do not mention actual parameter values there, you mention parameter types and their names:

Code (ags) Select

import function unhandled_event(int a, int b);


Of course you should later put something comprehensible instead of "a" and "b" which let you know what these parameters mean. If it is default unhandled_event known in AGS, then it should be "int what, int type".
Title: Re: Scripting issue, GlobalScript.ash(7): Error (line 7): PE03: Parse error at '1'
Post by: KANDYMAN-IAC on Thu 18/08/2016 14:38:41
THANK YOU...

I just used (int, int) then (int a, int b)...

Now I have this error on RUN.

Script link failed: Runtime error: unresolved import unhandled_event
Title: Re: Scripting issue, GlobalScript.ash(7): Error (line 7): PE03: Parse error at '1'
Post by: Crimson Wizard on Thu 18/08/2016 14:45:02
Quote from: KANDYMAN-IAC on Thu 18/08/2016 14:38:41
Script link failed: Runtime error: unresolved import unhandled_event
Where is your unhandled_event located in script? If you declared it in GlobalScript.ash, you need to have function itself in the GlobalScript.asc.
Title: Re: Scripting issue, GlobalScript.ash(7): Error (line 7): PE03: Parse error at '1'
Post by: KANDYMAN-IAC on Thu 18/08/2016 15:05:29
The function is in the room script...
Title: Re: Scripting issue, GlobalScript.ash(7): Error (line 7): PE03: Parse error at '1'
Post by: KANDYMAN-IAC on Thu 18/08/2016 15:06:54
Its meant to be use item on hotspot. There us an identical piece of code above it for different item and hot spot combo... no errors :(

again i'm coming back to this after 13 years...
Title: Re: Scripting issue, GlobalScript.ash(7): Error (line 7): PE03: Parse error at '1'
Post by: Crimson Wizard on Thu 18/08/2016 15:34:04
If some function is only in the room script, then you cannot declare it imported in the global header.

Remove the declaration in global header, and move "unhandled_event" function to the top of the room script to make it visible to every other function in same script.
Title: Re: Scripting issue, GlobalScript.ash(7): Error (line 7): PE03: Parse error at '1'
Post by: Khris on Thu 18/08/2016 17:29:27
Open GlobalScript.asc and look for the unhandled_event function.
If it's not already there, create it by adding it anywhere inside the script but preferably above your character / inventory handlers (those get added to the bottom of GlobalScript.asc as you add them to the game).

function unhandled_event(int what, int type) {
  // hotspot / object
  if (what == 1 || what == 2) {
    // look
    if (type == 1) Display("You see nothing special.");
    // interact, use inv
    else if (type == 2 || type == 3) Display("That doesn't work.");
    else if (type == 4) Display("It can't talk.");
    else Display("unhandled event on hotspot / object);
  }
  else Display("unhandled event on character / inv / nothing");
}


Now open Globalscript.ash (the header) and add this line:
import function unhandled_event(int what, int type);

Here's your room code with proper indentation:
Code (ags) Select
function hHotspot3_UseInv()
{
  if (player.ActiveInventory == inventory[18]) {
    hotspot3_a();
  }
  else {
    unhandled_event(1, 3);
  }
}


(Note that if you use this built-in method, you have to state the two parameters in every single handler function. A better way is to do this:
void Unhandled() {
  int lt = GetLocationType(mouse.x, mouse.y);
  InventoryItem *ii = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  if (lt == eLocationHotspot || lt == eLocationObject) {
    if (mouse.Mode == eModeLookat) Display("You see nothing special.");
    ...
  }
  ...
}

function unhandled_event(int w, int t) { Unhandled(); }

This way AGS will call your custom function for all unhandled actions, and you can simply call "Unhandled()" (after importing it) because the function will determine "what" and "type" automatically.)
Title: Re: Scripting issue, GlobalScript.ash(7): Error (line 7): PE03: Parse error at '1'
Post by: KANDYMAN-IAC on Sat 20/08/2016 12:36:10
Thanks Khris, that appears to have fixed it... I'm retesting it now to be certain.

You're a god send...