View Full Version : Global Variables


Pyro
Wed, 29th Jan '03, 6:19pm
I dont understand how to make, set and check "if" with global variables, I know how to do with locals, can anyone explain this to me?

Errol
Wed, 29th Jan '03, 11:52pm
Okay, make a conversation like this:

[OWNER] - Hello, I've spoken to you once.

Select it, goto Actions Taken tab, and press the Wizards hat. Now choose Set Local Variables, and name your Variable. Give it the number 1.
Make another line of Conversation above.

[OWNER] - Hello again!
[OWNER] - Hello, I've spoken to you once.

And for the top line, click the Text Appears When tab. Wizards Hat. And now choose Local Variable. Give the name of your saved variable(int) and say its gotta be equal to 1, which you set it to earlier.

Save that.

Now that when you speak to the person, he will say the "Hello, I've spoken to you once." line. And set a Variable to 1. He will not say the "Hello again!" line, because there is no variable set at 1 which it needs.

Next time however, you will have already set the variable to one, so he will speak the top line.

Understand?

Thorin
Thu, 30th Jan '03, 1:47am
Gopher that is one type of local variable. Once you become proficient in making scripts you can create and store your own variables. This is a basic version of one. They are mainly used for major plot parts.

//To Store An Int on a Player
//Created by Thorin
object oPlayer = GetFirstPC();
//declares the object oPlayer to be the first Pc
string sKey = "key";
//sets the string sKey to the value of key
int iKeyValue = 1;
//iKeyValue value is 1
SetLocalInt(oPlayer,sKey,iKeyValue);
//stores the value of ikeyValue on the first pc, with the access word of key

//To Return a Stored Int Value
//Created by Thorin
object oPlayer = GetFirstPC();
//declare agian the target of where you stored the variable
int iValue;
//an Integer to contian the value you want
iValue = GetLocalInt(oPlayer,"key");
//sets iValue to the value that was stored with the string key

Errol
Thu, 30th Jan '03, 1:52am
:rolleyes:
There's always one trying to be better than the rest. :p

Pyro
Thu, 30th Jan '03, 8:10am
Yeah, I know of all that already, thats local variables. Isnt there any global variables like I though? Can all variables stored on the PC be read from all objects? Im doing a conversation and the script on the last NPC line has this script:

SetLocalInt(GetPCSpeaker(), "Daerenustalk1check", 2);

In another area I have a one-way area transistion which has been used when you get there the first time, so there is only a way to the area and not from, and this script should get around that:

object oJumpTarget = GetObjectByTag("WP_Backfirstarea");
if(!(GetLocalInt(GetPCSpeaker(), "Daerenustalk1check") == 2))
ActionSpeakString("You are not supposed to go there, maybe some other time");
if((GetLocalInt(GetPCSpeaker(), "Daerenustalk1check") == 2))
ActionJumpToObject(oJumpTarget);

BUT, this does not work, any idea as to why?

Thorin
Thu, 30th Jan '03, 8:23am
True nwn global varaibles should really not be used for going between areas. Gobal variables where ment for major events. The commands anyhow are GetGlobal, Global, SetGlobal.

LocalVaraibles on the PC, are pratically what you need as they are really gobal varaibles, they stay when saving, and dying.

try extracting the varaible from the pc before checking it. Second if I remember you cant jump to an object if it is in a different area. You will have to a getobjectlocation, and jump the pc to the objects location.

(it's late and I am tired so exuse the spelling)

[ January 30, 2003, 08:23: Message edited by: Thorin ]

Pyro
Thu, 30th Jan '03, 8:42am
You are wrong actually, Ive tried to do a jumpto script from a dialogue displaying first an effect and then doing a jumpto a waypoint in another area and it worked.