Global Variables?

Post » Tue Jun 19, 2012 5:34 am

Hi.

1. How can I make global variables?
When I add a property and hover my mouse pointer over it, it says: "Status: Property edited locally."


2. Bonus question: How do I make a variable "read only" (constant)?
I read on the wiki something about replacing "Auto" with "AutoReadOnly", but that gives me a compile error.
EDIT: Maybe "AutoReadOnly" only works for certain types of variables? I'm trying to make a WEAPON-type constant.


3. Super-bonus question: What is "akKiller"? The name suggest that it returns the killer of the actor that dies. I am guessing that "akTarget" means the victim?
What does "ak" stand for?
User avatar
Alexx Peace
 
Posts: 3432
Joined: Thu Jul 20, 2006 5:55 pm

Post » Tue Jun 19, 2012 1:28 am

Hi buddy, I have had the same global variable issue, here is how I fixed it (answering number 1 only):
1 in the object window, go to miscealanous/global, and create the global variable you want to use, WhateverName (LMB, "new")
2 in your script, create the Global variable property (globalvariable Property WhaterverName auto) I suggest strongly to name both variables the same, as it will be helpfull for autofilling :-)
3 you can use the Globalvariable functions through importing "globalVariable"
4 important, and main issue as far as I am concerned, don't forget to assign the global to the property in the script owner.

Hope it helps.
User avatar
-__^
 
Posts: 3420
Joined: Mon Nov 20, 2006 4:48 pm

Post » Tue Jun 19, 2012 12:04 am

Variables can't be read only. Use a property. You can use the "hidden" flag to prevent it from showing up in the Creation Kit, if you want.

Both "akKiller" and "akTarget" are names used for parameters in their documentation on the wiki. If you use another name for the same parameter when overriding an event or other function, then you can use your name within the function body as well. The documentation of the function in question should describe what the parameters represent. I'm not sure what "ak" represents.

Cipscis
User avatar
DarkGypsy
 
Posts: 3309
Joined: Tue Jan 23, 2007 11:32 am

Post » Tue Jun 19, 2012 5:45 am

Hi buddy, I have had the same global variable issue, here is how I fixed it (answering number 1 only):
1 in the object window, go to miscealanous/global, and create the global variable you want to use, WhateverName (LMB, "new")
2 in your script, create the Global variable property (globalvariable Property WhaterverName auto) I suggest strongly to name both variables the same, as it will be helpfull for autofilling :-)
3 you can use the Globalvariable functions through importing "globalVariable"
4 important, and main issue as far as I am concerned, don't forget to assign the global to the property in the script owner.

Hope it helps.

Hi.
Thanks for the detailed help. =)
I don't understand what you mean in step 3: "you can use the Globalvariable functions through importing "globalVariable"", so I tried ignoring that step and of course I got compilation error.
Here's what I did:
1. Went to Misceallanous -> Global.
2. Created a new variable, short-type, named BM_Counter
3. Went to my script -> Properties.
4. Created a new property, global variable-type, named BM_Counter (GlobalVariable Property BM_Counter Auto)
5. Edited my script, adding this line:

BM_Counter = BM_Counter + 1

When I added that line the script failed to compile. -It's as if the script thinks BM_Counter isn't an integer-variable-type. -Did I fail to define my variable as an integer?


Variables can't be read only. Use a property. You can use the "hidden" flag to prevent it from showing up in the Creation Kit, if you want.

When creating a new global variable there's a box that can be checked, that says "Constant". -I would be very surprised if variables can't be read-only.
User avatar
Christie Mitchell
 
Posts: 3389
Joined: Mon Nov 27, 2006 10:44 pm

Post » Tue Jun 19, 2012 5:30 am

The Constant check box makes the variable not save with save game data, as it is expected not to change. If it's unchecked, then the value is expected to change and will be saved. What is the error that you get when you try to compile? And post the whole script, it'll be easier for people here to help you that way. :smile:
User avatar
Frank Firefly
 
Posts: 3429
Joined: Sun Aug 19, 2007 9:34 am

Post » Tue Jun 19, 2012 2:23 pm

The Constant check box makes the variable not save with save game data

Does that mean the variable can still be changed?

The error I get is the same as every other time, basically saying: "There is an error, save failed". -There is never any information about the error. Not even which line is the cause of the error. I am using the very-weak, built-in script editor, by the way.

Scriptname BM_GuardReplaceWeaponScript extends Actor{A simple script that will replace the Alik'r Scimitar with a normal Scimitar when a Black Market Guard dies. To prevent the player from getting one of these powerful swords.}WEAPON Property BM_GuardWeapon AutoWEAPON Property BM_GuardNewWeapon AutoGlobalVariable Property BM_Counter  AutoEvent OnDeath(Actor akTarget)RemoveItem(BM_GuardWeapon, 1, true)AddItem(BM_GuardNewWeapon, 1, true)BM_Counter += 1Debug.Notification(BM_Counter)endEvent

The script itself isn't really important. I am just trying to learn how to use global variables.

Earlier I tried using a local integer variable in this script; as expected: the script always returned "1".
User avatar
Phillip Brunyee
 
Posts: 3510
Joined: Tue Jul 31, 2007 7:43 pm

Post » Tue Jun 19, 2012 1:15 am

What i mean in step 3 is this:
http://www.creationkit.com/GlobalVariable_Script

You have to (well, can...), at the beginning of your script, import globalvariable, so that you will be able to use the fucntions associated to this script (getvalue(), setvalue(), and so on...)

or in you case, the problem is that you can't add an integer to a global variable.

try this:
int whatever = globalvariable.BM_counter.getValueInt () ; get the value of the global variable, as an integerwhatever +=1  ; increment this integer by oneglobalvariable.BM_counter.setValueInt (whatever) ;set the global variable to the new incremented integer.
it should work.

OR if you imported global variable at the beginning of your script (step 3 i was mentionning), just write:
int whatever = BM_counter.getValueInt ()whateve r+=1BM_counter.setValueInt (whatever)

Hope it helps
User avatar
Jon O
 
Posts: 3270
Joined: Wed Nov 28, 2007 9:48 pm

Post » Tue Jun 19, 2012 8:44 am

Thanks a lot. I finally got it to work. =)
Variables are a real hassle in CK.

Here's my trigger, if anyone's intersted:


ScriptName BM_GuardReplaceWeaponScript extends ActorWEAPON Property BM_GuardWeapon AutoWEAPON Property BM_GuardNewWeapon AutoGlobalVariable Property BM_Counter AutoEvent OnDeath(Actor akTarget)	RemoveItem(BM_GuardWeapon, 1, true)	AddItem(BM_GuardNewWeapon, 1, true)	BM_Counter.SetValueInt(BM_Counter.GetValueInt() + 1)	Debug.Notification(BM_Counter.GetValueInt())endEvent
User avatar
Mel E
 
Posts: 3354
Joined: Mon Apr 09, 2007 11:23 pm

Post » Tue Jun 19, 2012 4:05 am

Glad to hear this. Yes, variables reaally really do svck in CK.
User avatar
Tyler F
 
Posts: 3420
Joined: Mon Aug 27, 2007 8:07 pm

Post » Tue Jun 19, 2012 5:51 am

When creating a new global variable there's a box that can be checked, that says "Constant". -I would be very surprised if variables can't be read-only.
Which reminds me: Global variables aren't really variables - not like they were in previous games - they're a special type of object that can be used like a globally accessible variable (although still using the syntax for an object).

If I remember correctly, the "Constant" flag means that any changes made to the global variable will not be saved, so when the game is reloaded the variable's value will be restored from the master file, but I don't think it prevents the value from being set with a script. I've not used "Constant" global variables before, though, so this is based off what I can remember from others and I'm not that confident about it.

Cipscis
User avatar
Everardo Montano
 
Posts: 3373
Joined: Mon Dec 03, 2007 4:23 am


Return to V - Skyrim