PDA

View Full Version : How to define permanent global variables without being in a control?!



Visvalor
December 6th, 2009, 20:21
Ok let's say I want to define EVERY variable with scripts like

if ClassColor.getValue() == "Red" then
ClassHpVar = 9;
elseif ClassColor.getValue() == "Green" then
ClassHpVar = 6;
elseif ClassColor.getValue() == "Blue" then
ClassHpVar = 3;
else
ClassHpVar = 0;

That at the top of charsheet main and just have them as variables waiting to be called on in different numbercontrols throughout the sheet (Which will update and whatnot)

The only way it recognizes variables is by tossing them into scripts inside of controls. Do I need to write a lua file or something to get it to declare all the variables so that it's good to go before the charsheet is even open? I tried just sticking them inside of <script></script> at the top of the charsheet like you would do in a php file and it just didn't work :P

Ideas?

/edit

Also if I have to toss them into a control, that's fine but I need it to be invislbe and uneditable >_< and hold a lot of variables.

Visvalor
December 6th, 2009, 20:28
Nevermind apparently I can just put a script in a control and define it, then not anchor it and it is invisible >_>

Is there a less ghetto way :P?

Foen
December 6th, 2009, 21:34
Global variables can be declared in scripts, which are typically created in base.xml.

Say you have a script file called scripts/globalvars.lua and want to declare some global variables. All you do is include a line in base.xml: you need to remember that it is the script name in this statement ('MyGlobals') and not the file name ('globalvars') that is used to access the new variable. The included line would be something like:


<script name="MyGlobals" file="scripts/globalvars.lua" />

Any top-level variables in scripts/globalvars.lua will now be visible as named 'properties' of MyGlobals. If globalvars.lua has a declaration:


FirstVar = "first";

Then you can access this as either MyGlobals.FirstVar or MyGlobals["FirstVar"] so the following are equally valid:


racevar = MyGlobals.FirstVar;
~~~
racevar = MyGlobals["FirstVar"];
~~~
key = "FirstVar";
racevar = MyGlobals[key];

Hope that helps

Stuart

Visvalor
December 6th, 2009, 21:57
And could I declare if elseif variables in that script? Or are all of those static?

Such as;

if ClassColor.getValue() == "Red" then
ClassHpVar = 9;
elseif ClassColor.getValue() == "Green" then
ClassHpVar = 6;
elseif ClassColor.getValue() == "Blue" then
ClassHpVar = 3;
else
ClassHpVar = 0;

Visvalor
December 6th, 2009, 23:07
Alright got a global variable script written up but I need it do be able to perform elseif and else's being pulled from the racial selection drop-down menu.

function onInit()
RaceVar = window.class.getDatabaseNode();
RaceVar.onUpdate = update;
update();
end


I have that inside the global variable table to get the class description but something tells me that it isn't going to be able to look into everyones character sheets.... and update accordingly :P

How do I get it so that it'll look for the race, else or elseif the proper bonus to assign to that races strength variable and then return it to the client?