Persistant variables...will this work?

Post » Mon Jun 18, 2012 7:53 pm

Spent about an hour trying to figure out how to make variables persistant...but have to go to work now and haven't had time to test it...would this work to make variable values stick around, and implement a "There can be only one" type function?

Spoiler
Scriptname TeleportNodeListener extends ObjectReference  {Thread that runs on the teleport node to kill old nodes and pass reference to self}import gameimport utilitybool KillMyself = falsebool Property KillOrderSent = false auto ;Cicero asks: Can all running TeleportNodeListeners see this? I hope so!PlayerTeleportScript property WhoIsIt = None autoObjectReference Function Get()	return (self as objectreference)endfunctionFunction Listen() ; Cicero is listening!	while !KillMyself		if KillOrderSent			KillMyself = true ; Cicero says poor Cicero must die!		endif		if WhoIsIt ; Someone asks where Cicero is?			WhoIsIt.GetTeleportNode(self as ObjectReference) ; Tell them once			WhoIsIt = None		endif		Wait(2.0) ; Cicero says, Let's not use up ALL the processor cycles just keeping our variables alive!	endwhile	self.delete() ; Urk! (Thud!)endfunctionFunction SendKillOrder() ; Cicero says, everybody die...except me!	KillOrderSent = true	Wait(4.0) ; Wait til the others get the message.	KillOrderSent = falseendfunctionEvent OnLoad()	SendKillOrder() ; Cicero says to kill any other Listeners out there!	Listen() ; Cicero says to listen!EndEvent

(Yes, this problem is driving me to channel poor poor Cicero!)
User avatar
Ben sutton
 
Posts: 3427
Joined: Sun Jun 10, 2007 4:01 am

Post » Mon Jun 18, 2012 1:11 pm

What's wrong with a global? Those are persistent and unique.
User avatar
Joey Bel
 
Posts: 3487
Joined: Sun Jan 07, 2007 9:44 am

Post » Tue Jun 19, 2012 12:27 am

What's wrong with a global? Those are persistent and unique.

Tell me how to make a global ObjectReference and I will kiss you!

(PlayerTeleportScript Extends ObjectReference - and there is apparently no way to make it global without using a quest script, and it ain't a quest!.)
User avatar
dell
 
Posts: 3452
Joined: Sat Mar 24, 2007 2:58 am

Post » Mon Jun 18, 2012 7:58 pm

If you want to store any references in "global like" variables (actors, objects, etc.) you may want to create a quest with start game enabled that never ends.
And you need to create a script and attach it to that quest where you only declare properties that should store things you want to use by your other scripts or fragments.
User avatar
matt
 
Posts: 3267
Joined: Wed May 30, 2007 10:17 am

Post » Mon Jun 18, 2012 11:21 am

If you want to store any references in "global like" variables (actors, objects, etc.) you may want to create a quest with start game enabled that never ends.
And you need to create a script and attach it to that quest where you only declare properties that should store things you want to use by your other scripts or fragments.

1: I can't create quest aliases, as the window is too large and the "OK" button is off the bottom of the screen at all times.

2: I shouldn't have to create a quest just to have variables be persistent...they're supposed to be persistent to begin with...storing values is what they're for. What is the point of having Set and Get functions on properties for example, if the value you send with the Set function isn't stored, and the value you get from the Get function is initialised when you send the command because the script isn't running in an eternal "keep my variables alive" loop at that particular moment?

And I booted up the CK at work...and this doesn't even work! the other instances of the script can't see the KillOrderSent property variable when it's set to true (I can tell because they don't disappear within 2 seconds)
User avatar
Elle H
 
Posts: 3407
Joined: Sun Aug 06, 2006 3:15 am

Post » Mon Jun 18, 2012 6:02 pm

On the wiki reference page abou quest Reference Alias it gives a workaround for the off the screen OK button
User avatar
yermom
 
Posts: 3323
Joined: Mon Oct 15, 2007 12:56 pm

Post » Mon Jun 18, 2012 3:13 pm

1: I can't create quest aliases, as the window is too large and the "OK" button is off the bottom of the screen at all times.
You do not need any aliases for this. Setting up a quest, its script and declaring global property that will store "things" is like 30 seconds of work.


2: I shouldn't have to create a quest just to have variables be persistent...they're supposed to be persistent to begin with...storing values is what they're for.
If you want to have variable (property actually) which you can access globally and store things other than numbers there through the whole game, then quest scripts are the easiest option to begin with.
User avatar
Rachie Stout
 
Posts: 3480
Joined: Sun Jun 25, 2006 2:19 pm

Post » Mon Jun 18, 2012 10:50 pm

You do not need any aliases for this. Setting up a quest, its script and declaring global property that will store "things" is like 30 seconds of work.

If you want to have variable (property actually) which you can access globally and store things other than numbers there through the whole game, then quest scripts are the easiest option to begin with.

So instead of trying to actually use the functionality that's supposed to be built in, I should ignore the existance of variables and properties, because they don't function like variables and properties do in every other programming language I've ever used, and just put everything in one huge quest, and put a permanent quest in the players' Journal called "NotAQuest, Just a place to store stuff"

I read the documentation...the player has to HAVE the quest for the values to be initialized...or at least that's what it looks like.
User avatar
Anna Watts
 
Posts: 3476
Joined: Sat Jun 17, 2006 8:31 pm

Post » Mon Jun 18, 2012 6:05 pm

I read the documentation...the player has to HAVE the quest for the values to be initialized...or at least that's what it looks like.
The player "has" all quests. A quest doesn't necessarily mean a journal entry.

Quest scripts run even if the player has no knowledge of them. You can use an OnInit block, this always runs.
User avatar
Elle H
 
Posts: 3407
Joined: Sun Aug 06, 2006 3:15 am

Post » Mon Jun 18, 2012 10:55 pm

The player "has" all quests. A quest doesn't necessarily mean a journal entry.

Quest scripts run even if the player has no knowledge of them. You can use an OnInit block, this always runs.

OK...if this is so easy, let's create an example we can put on the Wiki on how to do it.

Creating a quest called "GlobalVariableStorageQuest01"

What should the script to store global references look like, and how do we call them from the other function (the equivalent of the line

MyVariableName = (WhateverCodegetsTheRefereceFromTheQuest)
User avatar
Umpyre Records
 
Posts: 3436
Joined: Tue Nov 13, 2007 4:19 pm

Post » Tue Jun 19, 2012 12:24 am

So instead of trying to actually use the functionality that's supposed to be built in, I should ignore the existance of variables and properties, because they don't function like variables and properties do in every other programming language I've ever used, and just put everything in one huge quest, and put a permanent quest in the players' Journal called "NotAQuest, Just a place to store stuff"

That last fragment may indicate that you may want to review your perception of "Quests" in Bethesda games ;]
Quests can have dialogue or not. Can have scripts or not. Can have journal entries or not. Can have everything or nothing. One of the ways to describe them is they are more like "containers" that store stuff and organize things.
So creating a "quest" that runs in the background with the script attached which organizes and maintains various things constantly during the whole game, and in the same time is not visible to the player at all, is quite a common practice here :)
User avatar
Marina Leigh
 
Posts: 3339
Joined: Wed Jun 21, 2006 7:59 pm

Post » Mon Jun 18, 2012 2:57 pm

Actually, reviewing what I was trying to do above, for all I know, the "Listener" idea works...apparently, the object the script was attached to (A light being carried by a spell projectile) isn't descended from ObjectReference, and thus has no Onload...Like you said, OnInit would have to be used...the problem now is...if a light isn't an object, and neither is a projectile (which is strange...I'm pretty sure if you can pick it up, it has to have a location and other object data)...how do you reference it's location? You can't turn it into an object reference...

Aggggg..My brain hurts! http://www.youtube.com/watch?v=IIlKiRPSNGA
User avatar
rebecca moody
 
Posts: 3430
Joined: Mon Mar 05, 2007 3:01 pm

Post » Tue Jun 19, 2012 12:11 am

OK...if this is so easy, let's create an example we can put on the Wiki on how to do it. Creating a quest called "GlobalVariableStorageQuest01" What should the script to store global references look like, and how do we call them from the other function (the equivalent of the line MyVariableName = (WhateverCodegetsTheRefereceFromTheQuest)


Here's a recipie how I do this (names and IDs are just examples):

1. create quest myVarsQuest (start game enabled, do not bother with other settings at all)

2. in quest window -> go to tab "Scripts" -> press Add button -> chose [New Script] option -> type name as myVarsQuestScript -> OK

3. r-click on already created script -> from menu "Edit Source" -> add declaration of property:
Actor Property myActor auto ; for Actors
ObjectReference Property myObject auto ; for Objects

4. if I have another script (IE attached to some spell) and want to pass variable from it and store it in that global quest property then I add to this script such line:
myVarsQuestScript Property myVarsQuest Auto

and then in this local script I can address global and "persistent" quest properties like this:
myVarsQuest.myActor = [reference of actor which local script aquired]
myVarsQuest.myObject = [reference of object which local script aquired]
or
if myVarsQuest.myActor == game.getPlayer()
; something
endif

etc.



Aggggg..My brain hurts! http://www.youtube.com/watch?v=IIlKiRPSNGA
Do not worry, that was me three days after release of CK. Seems like quite a normal behavior for those introduced to Papyrus ;]
User avatar
Jamie Lee
 
Posts: 3415
Joined: Sun Jun 17, 2007 9:15 am

Post » Mon Jun 18, 2012 6:30 pm


Do not worry, that was me three days after release of CK. Seems like quite a normal behavior for those introduced to Papyrus ;]

And even after all this, my spell seems doomed to fail, since I still can't figure out how to locate a moving light or projectile object...or a stationary one for that matter...or get the finding functions to actually work.
User avatar
Timara White
 
Posts: 3464
Joined: Mon Aug 27, 2007 7:39 am

Post » Mon Jun 18, 2012 9:20 pm

Creation Kit has crashed twice trying to create the quest...haven't had any crashes in 4 days and NOW it starts crashing...maybe the universe doesn't want these spells finished?
User avatar
Gavin boyce
 
Posts: 3436
Joined: Sat Jul 28, 2007 11:19 pm

Post » Mon Jun 18, 2012 7:15 pm

Creation Kit has crashed twice trying to create the quest...haven't had any crashes in 4 days and NOW it starts crashing...maybe the universe doesn't want these spells finished?
I was trying to do what Artisanix was suggesting and it kept crashing. Doing first step, pressing ok to save the quest and then reopening and adding the script worked though
User avatar
Angus Poole
 
Posts: 3594
Joined: Fri Aug 03, 2007 9:04 pm

Post » Mon Jun 18, 2012 8:30 pm

I was trying to do what Artisanix was suggesting and it kept crashing. Doing first step, pressing ok to save the quest and then reopening and adding the script worked though
Ah, yes. That's maybe something worth of notice. As I always do not trust CK much, and it's already one of my habits to create something and save it first, then reopen and edit.
Alas such behavior is recommended with other dealings inside of CK as well - like papyrus fragments in dialogues for instance. When I need to add some code in fragment I usually fill the form with empty space, then close the topic window with OK button what creates the script, and only then reopen the window and edit the code.
Well, those traps of instabilities and too complex dealings with papyrus as far as simple things go, aren't the best deals CK has to offer for us :/
User avatar
Laura Wilson
 
Posts: 3445
Joined: Thu Oct 05, 2006 3:57 pm

Post » Mon Jun 18, 2012 8:57 pm

Ah, yes. That's maybe something worth of notice. As I always do not trust CK much, and it's already one of my habits to create something and save it first, then reopen and edit.
Alas such behavior is recommended with other dealings inside of CK as well - like papyrus fragments in dialogues for instance. When I need to add some code in fragment I usually fill the form with empty space, then close the topic window with OK button what creates the script, and only then reopen the window and edit the code.
Well, those traps of instabilities and too complex dealings with papyrus as far as simple things go, aren't the best deals CK has to offer for us :/
Ahhh but that's the price we pay for being the first ones using the CK. I bet in a couple of months wiki will have all the little issues listed if not fixed :)

As a side note, I also realized that in your fourth step the property in the local script wasn't being autofilled so I had to do it manually ( just saying in case someone else reads this)

Thanks for your help, I kinda managed to do what I wanted to hehe :D
User avatar
Natasha Callaghan
 
Posts: 3523
Joined: Sat Dec 09, 2006 7:44 pm

Post » Mon Jun 18, 2012 11:47 pm

TX a lot for the tuto. Its amazing how this powerfull tool can be so stupid dealing with global variable, whereas in some languages, its as simple as adding a & in front of the variable name....
User avatar
Nikki Morse
 
Posts: 3494
Joined: Fri Aug 25, 2006 12:08 pm

Post » Mon Jun 18, 2012 10:15 pm

TX a lot for the tuto. Its amazing how this powerfull tool can be so stupid dealing with global variable, whereas in some languages, its as simple as adding a & in front of the variable name....

It's not just stupid with globals...it's also stupid with member variables...their values vanish at the drop of a hat.
User avatar
Dezzeh
 
Posts: 3414
Joined: Sat Jun 16, 2007 2:49 am

Post » Mon Jun 18, 2012 11:07 pm

Well it doesn't appear to be working...Does the name you used in step 1 for the quest and the name you used for the property in the script in step 4 have to be the same? I wouldn't think so, since you're declaring a local name, right?

In other words, instead of

MyVarsQuestScript Property MyVarsQuest Auto

couldn't you use

MyVarsQuestScript Property MVQ Auto

and refer to the variables as MVQ.MyObject and MVQ.MyActor?

That's the only difference I had in my implementation (wanted to use a shorter name in the scripts) and it's not storing the variables.

And yes, I verified that it's not saving values by simply sending notifications before and after "saving" them, and the come back as "none"
User avatar
Miss Hayley
 
Posts: 3414
Joined: Tue Jun 27, 2006 2:31 am

Post » Mon Jun 18, 2012 3:14 pm

In other words, instead of

MyVarsQuestScript Property MyVarsQuest Auto

couldn't you use

MyVarsQuestScript Property MVQ Auto

and refer to the variables as MVQ.MyObject and MVQ.MyActor?

Yes, you can do that as this variable is local. My reason was on the other hand to address the quest everywhere by the same name ;]

And it's also worth to mention that the case with quest scripts is that variables do not auto-link with values properly - just do what Shana posted above - press Properties button and set everything properly there. As this may be the cause your script doesn't work.
User avatar
Kelli Wolfe
 
Posts: 3440
Joined: Thu Aug 23, 2007 7:09 am

Post » Tue Jun 19, 2012 2:46 am

Yes, you can do that as this variable is local. My reason was on the other hand to address the quest everywhere by the same name ;] And it's also worth to mention that the case with quest scripts is that variables do not auto-link with values properly - just do what Shana posted above - press Properties button and set everything properly there. As this may be the cause your script doesn't work.

Well I can't test it til tomorrow...the Steam Cloud doesn't work for me for CreationKit, and my latest version is back at work...but I remember trying to manually set the property in my scripts and having nothing turn up in the pick list (though the variables came back as "undefined" when I misspelled them, so clearly it CAN find them) - and when I try to copy all the files associated with my mod onto a USB stick and copy them onto my home computer (Got all the Pex and ESP files) all the scripts go poof anyway, and I'm not about to spend 5 hours rewriting them tonight...

BTW...http://www.gunnerkrigg.com/archive_page.php?comicID=997
User avatar
Chloe :)
 
Posts: 3386
Joined: Tue Jun 13, 2006 10:00 am

Post » Tue Jun 19, 2012 2:38 am

OK, this is maddening...at home, i tested global variables and it worked...I could assign the script property to the Quest Script just fine.

But I get to work, open my mod (As I said, The cloud isn't working) and when I try to assign the script variable, all 3 of the option buttons are greyed out.

I don't know what that means...does it mean the script file that assigns the properties is broken somehow? Do I need to create a new script?

(Edit) OK, I don't know what was wrong, but creating a new script in the quest and copying the old one made it assignable. Something was busted with the old script, which was identical to the new script...

One last question...do I assign values to the properties in the quest script that's storing the variables, or just let the other scripts assign them from outside...at compile time, the only value possible would be "none" for references, since the items referred to don't exist yet...
User avatar
ImmaTakeYour
 
Posts: 3383
Joined: Mon Sep 03, 2007 12:45 pm


Return to V - Skyrim

cron