Can't figure out how to change a variable in a room.

Started by cliffwhite, Sun 17/05/2020 03:24:31

Previous topic - Next topic

cliffwhite

Once again, I'm having problems with scripting. In my GlobalScript, I have the code...

int game_var;
export game_var;

In my Global Script Header, I have the following code...

import int game_var;

In my Room2 RoomScript, I typed in the following code....

int game_var = 7;

and I get the following error message.....

Failed to save room room2.crm; details below
room2.asc(1): Error (line 1): Variable 'game_var' is already imported

If I remove "int" from the last entry and just type in....

game_var = 7;

then I get the following error message.....

Failed to save room room2.crm; details below
room2.asc(1): Error (line 1): Parse error: unexpected 'game_var'

I haven't been able to find any help in the docs, online or in the FAQ's. Can anyone tell me how to change a variable in room? Does this have to be in a function? And if so, does all coding have to occur in a function?  Thanks!

Crimson Wizard

#1
This is exactly same problem as the previous case: changing variable value is a command, and you can only do commands inside a function. Determine at which event do you want this happen and make corresponding function for that event. Inside the function you can then write "game_var = 7;"

Snarky

Quote from: cliffwhite on Sun 17/05/2020 03:24:31And if so, does all coding have to occur in a function?  Thanks!

Like CW says, all commands have to be inside functions. Declarations don't need to be. (These are the things like creating a variable and giving it a starting value, describing new data types like structs and enums, and all the import/export lines.) Nor do macros, which are lines that start with #.


SMF spam blocked by CleanTalk