I have the following bits of code in my script:
//in global header
struct TeamStats {
...
String Name;
...
};
//top of global script
TeamStats Team[Max_Num_Teams];
//game_start script
Team[Team_A - 1].Name.Format("USA Army");
Team[Team_B - 1].Name.Format("Red Army");
Team[Team_C - 1].Name.Format("British Army");
Team[Team_D - 1].Name.Format("Nazi Army");
//within a function
if (regular_damage != 0) {
if (Unit[unit_ID].Defense >= regular_damage) {
if (Unit[unit_ID].Team != Neutral) Display("%s of The %s has recieved 1 damage to its armor.", Unit[unit_ID].Name, Team[Unit[unit_ID].Team - 1].Name);
Unit[unit_ID].Armor --;
}
...
Notice the Display command in the last code. I have similar display commands all throughout my functions. That is, display commands that should display the String Name of the team of the variable unit_ID. However, whenever any of these commands are called, where the team name should be, '(null)' is displayed. However, I defined them in the game_start. What am I doing wrong that the game thinks that they are (null) still?
Worked for me (not tested to work also with Strings in structs yet though).
Was the function in a room script or the global script? If that's in a room script, make sure you export/import the variables properly, and they're not variables of the same names local to the room.
Everything is called globaly. Do you need to export array definitions? It's strange really, the other variables assigned in the Team struct are called without problem, it's just the String var that they have a problem with. It's really quite irritating...
Ah, I know your problem now.
You used String.Format() to set the names which is a static function.
In other words, calling something like Blah.Format("haha!");
would not change the content of Blah but instead return the String "haha!".
The correct format is:
Team[Team_A - 1].Name = String.Format("USA Army");
HOWEVER, as you don't really need any formating there, you could directly assign the Strings instead, which is much more readible and understandable:
Team[Team_A - 1].Name = "USA Army";
Format() is only required for cases like:
Message = String.Format("%s has %d hotdogs.", YourName, quantity);