Jump to content

Home

(More) Scripting Help


Robespierre

Recommended Posts

Yes, its me again. After a rather short hiatus from modding I'm trying to tie up the proverbial loose ends and get some mods released.

 

Alright, so my little scripting problems. I was working on getting some local variables working, and Stoffe explained to me this method of setting the boolean:

 

void main() {
   if (!GetLocalBoolean(GetModule(), 30) && (GetEnteringObject() == GetFirstPC())) {
       SetLocalBoolean(GetModule(), 30, TRUE);
   }
}

 

Now this, as I understand it, sets the local boolean 30 to TRUE for the module that I'm in currently.

 

And now this code:

 

int StartingConditional() {
   return GetLocalBoolean(GetModule(), 30);
}

 

This checks to see whether the local boolean 30 is true or false.

 

Now this does essentially exactly what I want it to do, however the very nature of my mod means that I have to check variables in different modules from the one I'm currently in. So I need to set the variable on, say, tar_m02ac, and then check that variable when I'm standing in tar_m02ab.

 

Any ideas?

Link to comment
Share on other sites

Now this does essentially exactly what I want it to do, however the very nature of my mod means that I have to check variables in different modules from the one I'm currently in. So I need to set the variable on, say, tar_m02ac, and then check that variable when I'm standing in tar_m02ab.

 

You can't. The game only has one module loaded at a time; the one the player currently is in. This is the only module that scripts can do anything with. Objects in all other modules are unavailable until the player goes there.

 

However, if you want a variable that can be checked from anywhere in the game, this is what global variables are for. They can be set and checked from any module, and will keep their value throughout the game.

 

To use a global variable you must first add it to the globalcat.2da file for the game to recognize it. Then you can use the SetGlobaBoolean(), GetGlobalBoolean(), SetGlobalNumber() and GetGlobalNumber() etc functions to read and write to them.

 

Unlike local variables which use a fixed number of variable slots that are accessed by an index value (30 in your script above, for example), global variables use a tag name to refer to them (which is set in globalcat.2da). So for example, your scripts using global variables instead would look like:

 

void main() {
   if (!GetGlobalBoolean("[color=Yellow]MyPlayerCheck[/color]") && (GetEnteringObject() == GetFirstPC())) {
       SetGlobalBoolean("[color=Yellow]MyPlayerCheck[/color]", TRUE);
   }
}

 

int StartingConditional() {
   return GetGlobalBoolean("[color=Yellow]MyPlayerCheck[/color]");
}

 

Where MyPlayerCheck is the tag of the variable you have set in the globalcat.2da file.

Link to comment
Share on other sites

Thanks for that.

 

Are there any limit to the amount of global variables set in game?

 

EDIT: Just a quick note, for anyone thats interested, here's the code I used in the end:

 

void main() {
   if (!GetGlobalBoolean("MyPlayerCheck") && (GetEnteringObject() == GetFirstPC())) {
       SetGlobalBoolean("MyPlayerCheck", 1);
   }
}

 

So its 1 rather than TRUE.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...