Scripting issue, GlobalScript.ash(7): Error (line 7): PE03: Parse error at '1'

Started by KANDYMAN-IAC, Thu 18/08/2016 08:34:52

Previous topic - Next topic

KANDYMAN-IAC

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
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
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.
"Don't lose the bluecups they may be our only hope....!!1!!!1"

"I'm jealous of all of you guys, which means. I love your work, I just hate you as a person.... wait thats not right."

Crimson Wizard

When you declare (import) a function, you do not mention actual parameter values there, you mention parameter types and their names:

Code: ags

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".

KANDYMAN-IAC

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
"Don't lose the bluecups they may be our only hope....!!1!!!1"

"I'm jealous of all of you guys, which means. I love your work, I just hate you as a person.... wait thats not right."

Crimson Wizard

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.

KANDYMAN-IAC

"Don't lose the bluecups they may be our only hope....!!1!!!1"

"I'm jealous of all of you guys, which means. I love your work, I just hate you as a person.... wait thats not right."

KANDYMAN-IAC

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...
"Don't lose the bluecups they may be our only hope....!!1!!!1"

"I'm jealous of all of you guys, which means. I love your work, I just hate you as a person.... wait thats not right."

Crimson Wizard

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.

Khris

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).

Code: ags
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:
Code: ags
import function unhandled_event(int what, int type);


Here's your room code with proper indentation:
Code: ags
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:
Code: ags
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.)

KANDYMAN-IAC

Thanks Khris, that appears to have fixed it... I'm retesting it now to be certain.

You're a god send...
"Don't lose the bluecups they may be our only hope....!!1!!!1"

"I'm jealous of all of you guys, which means. I love your work, I just hate you as a person.... wait thats not right."

SMF spam blocked by CleanTalk