Hope I can make this clear.
We have a generic way of showing player deaths.
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:
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
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
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)
This looks weird to me:
function ShowDeathGui(CauseOfDeath cod)
Shouldn't that be simply function ShowDeathGui(int cod)?
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.
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:
String death_message[80];
export death_message;
"Import" declares that such variable exist
somewhere else. "Export" actually links particular variable to its "import" declaration.
I added the export, but I still get 'Attributes of identifier do not match prototype'.
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?
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'.
Well import has to be declared exactly as the variable. I thought you already fixed this error before.
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