export problem (possibly)

Started by HandsFree, Sun 14/02/2021 11:30:04

Previous topic - Next topic

HandsFree

Hope I can make this clear.
We have a generic way of showing player deaths.

Code: ags

in global script:
function ShowDeathGui(CauseOfDeath cod) { //makes death gui appear
 //stuff
  DisplayAtY(280, death_message[cod]);

}

function game_start(){
  death_message[eDeathTree] = "test";

}

GlobalScript.ash
enum CauseOfDeath {
  eDeathZombie, 
  eDeathTree, 
};
String death_message[80];
export death_message; //added this but it didn't help

In room scripts:
ShowDeathGui(eDeathTree);


So when the player dies you see the text "test".
This works.

But for the tree I want to have several random messages, so in de room script I added:
Code: ags

void RandomTreeMessage(){
  int r = Random(4);
  r = 0; //testing
  if (r==0) death_message[eDeathTree] = "This is the first random text";
}

And then
RandomTreeMessage()
ShowDeathGui(eDeathTree);

The result is that the text "test" is still shown, instead of "This is the first random text"
I assume this is some kind of import/export thing?
Or should this be a function with parameters?

How do I do this?
Thanks

Crimson Wizard

You are placing variable declaration and "export" in the header, while you should normally place them inside script body, and place "import" in the header instead.

Here's explaination on how to export/import variables and functions:
https://adventuregamestudio.github.io/ags-manual/ImportingFunctionsAndVariables.html
Also for more information on why you should not place regular variable declarations in the header:
https://adventuregamestudio.github.io/ags-manual/TheScriptHeader.html

HandsFree

I now have in global script:
String death_message[80]; //this is line 57

in ash:
import String death_message[];

When compiling I get error:
Attributes of identifier do not match prototype (on line 57)

If I change the import statement to import String death_message[80]; I get another error (unresolved import)

Laura Hunt

This looks weird to me:

Code: ags
function ShowDeathGui(CauseOfDeath cod)


Shouldn't that be simply function ShowDeathGui(int cod)?

HandsFree

The cause of death is an enum, so I believe that part of the script is correct. At least it has always worked until I tried to set the message from a room script.

Crimson Wizard

#5
Quote from: HandsFree on Sun 14/02/2021 12:08:21
If I change the import statement to import String death_message[80]; I get another error (unresolved import)

This means the variable was not exported.

You need an export statement for each variable you export from script. For example:
Code: ags

String death_message[80];
export death_message;



"Import" declares that such variable exist somewhere else. "Export" actually links particular variable to its "import" declaration.

HandsFree

I added the export, but I still get 'Attributes of identifier do not match prototype'.

Crimson Wizard

#7
Quote from: HandsFree on Sun 14/02/2021 13:55:09
I added the export, but I still get 'Attributes of identifier do not match prototype'.

What line of script does this error point to? Is the import declaration match the variable declaration?

HandsFree

In GlobalScript.asc
String death_message[80];// line 57
export death_message;

in GlobalScript.ash
import String death_message[];

The error points at line 57.

When I removed the [] in the import statement, the error is 'death_message is not an array'.

Crimson Wizard

Well import has to be declared exactly as the variable. I thought you already fixed this error before.

HandsFree

OK, ik works with import String death_message[80];
I didn't expect I had to write that 80 there in the import statement.

thanks

SMF spam blocked by CleanTalk