Author Topic: Sort of global variables  (Read 346 times)

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Sort of global variables
« on: April 30, 2012, 09:53:32 pm »


               Hi all, just wondering.. I have read there is no way to create global variables. If this is true, how would i (if even possible) create a set of variables that scripts run on/by any player can edit. Because, I am trying to create a world, where classes other than barbarian are unnavailable until a certain event, but the only way I can think to do this would be to have these events change a "Global" int variable, that is then checked when a new player enters the world, so for example a bard.
int iBard = FALSE;
Bard unlocking event happens, triggers the following:
iBard = TRUE; 
and whenever a character uses the portal to enter the world, if they have bard as a class, it will do:
if(iBard == TRUE)
{
    //Teleport to world
}
else
{
    BootPC(oPC);
}

So how would I go about setting this up?
               
               

               
            

Legacy_Leurnid

  • Sr. Member
  • ****
  • Posts: 473
  • Karma: +0/-0
Sort of global variables
« Reply #1 on: April 30, 2012, 09:58:52 pm »


               you could store the vars on the module
               
               

               


                     Modifié par Leurnid, 30 avril 2012 - 09:00 .
                     
                  


            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Sort of global variables
« Reply #2 on: April 30, 2012, 10:08:25 pm »


               Yes but my question is how?
               
               

               
            

Legacy_Leurnid

  • Sr. Member
  • ****
  • Posts: 473
  • Karma: +0/-0
Sort of global variables
« Reply #3 on: April 30, 2012, 10:26:36 pm »


               Edit > Module Properties > Advanced Tab> bottom item on the list is 'variables', click the button with the ellipsis on it and away you go.

You could set the variables via script on an appropriate event too, and you can always modify them via script later.


*And this is precisely why I was saying that it would be nice of the tutorials told you how to set vars either manually, or via scripting*
               
               

               


                     Modifié par Leurnid, 30 avril 2012 - 09:29 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Sort of global variables
« Reply #4 on: April 30, 2012, 11:01:54 pm »


               NWN has a thing called a Local Variable.  Now Given they gave it a bad name, When most people think of a local variable they think about variabls that are placed on the stack.   Not the case here, Local Variables are in fact the closest thing you are going to get to global variables.   I almost with they would have called them ObjectVariables instead.  For that is what they are they are variables that are local to an Object,  Not local to a script or function that the name would imply.   

So setting a Local Variable on the module will give you a Var that will last as long as the module does.   You can concider that global.   

As far as how to set/get them in scripting. 





Get/SetLocalFloat
Get the value of a decimal number stored on an object.

Get/SetLocalInt
Get the value of a whole number stored on an object.

Get/SetLocalLocation
Get the data describing a location stored on an object.

Get/SetLocalObject
Get the data describing an object stored on an object.

Get/SetLocalString
               
               

               


                     Modifié par Lightfoot8, 30 avril 2012 - 10:03 .
                     
                  


            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Sort of global variables
« Reply #5 on: May 05, 2012, 11:30:05 am »


               Ahah, I knew about local variables.. but.. are you saying you can give the module itself local variables, which basically act as a global variable would?
               
               

               
            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
Sort of global variables
« Reply #6 on: May 05, 2012, 12:27:44 pm »


               exactly so.

'<img'>