The Elder Scrolls Forums

TES Construction Set and Plugins >> General TES Construction Set

Pages: 1
maxpublic
Curate

Reged: 09/29/02
Posts: 858
passing variables from one script to another?
      #2036760 - 12/08/03 07:49 PM

Just wondering if it's possible to pass values for variables from a chained subscript back up to the master script that called it. Scripting for Dummies implies that it isn't unless you use the 'Set MyObject.variable' command, and that local variables are specific to scripts, not processes.

Max

--------------------

The really successful criminals never break laws. They make them.

Post Extras: Print Post   Remind Me!   Notify Moderator   Email Post
jaxalot
Adept

Reged: 09/02/03
Posts: 314
Re: passing variables from one script to another? [Re: maxpublic]
      #2036809 - 12/08/03 08:57 PM

Just use a global variable.

--------------------
Jaxalot reserves the right to speak in the third person.

McAsmod Member
Werewolves Forums

Post Extras: Print Post   Remind Me!   Notify Moderator   Email Post
maxpublic
Curate

Reged: 09/29/02
Posts: 858
Re: passing variables from one script to another? [Re: jaxalot]
      #2037251 - 12/09/03 02:27 AM

Quote:

Just use a global variable.




I don't want an alternative, but an answer to the original question.

Max

--------------------

The really successful criminals never break laws. They make them.

Post Extras: Print Post   Remind Me!   Notify Moderator   Email Post
ThreadWhisperer
Curate

Reged: 10/05/03
Posts: 584
Re: passing variables from one script to another? [Re: maxpublic]
      #2037262 - 12/09/03 02:35 AM

I have never found a way to pass variables at all without using a global as the variable. So from what I understand there is no way to do what you ask without creating a global. I would love to be wrong about it though!! if anyone does know a way I hope they share it sometime

It seems that the script enviornments run as stand alone programs in a way, and therefore they do not "share" amongst themselves but rather depend on the primary program that controls them for sharing information, so for them to share a variable it has to be set in the controling program or "attached" to something in it, ie a global variable or a set value to an object...Thats my understanding of it anyway...



--------------------
"Within the mind of a stranger are the stories of a lifetime."

Post Extras: Print Post   Remind Me!   Notify Moderator   Email Post
paschors
Curate

Reged: 09/05/03
Posts: 639
Loc: Oregon, USA
Re: passing variables from one script to another? [Re: ThreadWhisperer]
      #2037354 - 12/09/03 03:26 AM

I pass variables back and forth all the time.

The trick is, when you reference the variable you must reference the ITEM ID it is attached to, not the script name. So in the example below, I am changing a variable in the scripts attached to 3 different torch lights. All torches have the same script attached to them. I am setting the doOnce in all those scripts so that it will kick off their doOnce loop again.

The variables in those scripts get changed when the device that holds the script below gets activated.

Code:

Begin Turn_On_Lights

Short doOnce

If ( OnActivate == 1 )
If ( doOnce == 0 )
Set Wa_Torch_Light_01.doOnce to 0
Set WA_Torch_Light_02.doOnce to 0
Set WA_Torch_Light_03.doOnce to 0
Set doOnce to 1
EndIf
EndIf

End Turn_On_Lights



This is just a small piece of large bit of code

--------------------
Paschors/aka Kiriel/ aka Patty
Home Page - Kiriel's Morrowind Creations


Post Extras: Print Post   Remind Me!   Notify Moderator   Email Post
Dave Humphrey
Curate

Reged: 06/19/00
Posts: 605
Loc: Toronto, Canada
Re: passing variables from one script to another? [Re: paschors]
      #2037456 - 12/09/03 04:14 AM

Paschors is correct in that you can set local variables of another object in a script. Just to note that you cannot get/check the same variable, i.e:

set SomeValue to object01.LocalVar
if ( object01.LocalVar > 0 )

both won't work (you'll get 0's for each).

--------------------
Dave Humphrey - Unofficial Elder Scrolls Pages, serving the ES community since 1995.
MWEdit - Alternate plugin editor
NIFTexture
Script Functions

Post Extras: Print Post   Remind Me!   Notify Moderator   Email Post
JOG
Adept

Reged: 09/15/02
Posts: 358
Re: passing variables from one script to another? [Re: Dave Humphrey]
      #2037485 - 12/09/03 04:32 AM

And remember that local variables might be reset when you change/uninstall any plugin. Global variables and Journal entries are always safe.

--------------------
Havish (Updated to v1.1!)

My Morrowind Corner

CON3-Homepage


Post Extras: Print Post   Remind Me!   Notify Moderator   Email Post
maxpublic
Curate

Reged: 09/29/02
Posts: 858
Re: passing variables from one script to another? [Re: JOG]
      #2037557 - 12/09/03 05:06 AM

Unfortunately I can't use the Set MyObject.variable command for what I'm thinking of doing, at least not in the context that I want to use it. In this particular case I want to toss the bartering system in the game and replace it with a scripted alternative for merchants. Because of the line limitation on scripts I need to reference other scripts during the process. Since the MyObject.variable command requires the specific object i.d., this would require separate scripts for every merchant NPC in the game. Putting 'inventory lists' in the shop isn't any more efficient for this very same reason (and it doesn't account for traveling merchants).

So it looks like global variables are the way to go for passing information, while local variables are needed to keep track of specific merchant inventory and pricing based on regional conditions. I was hoping for a non-global alternative just because keeping everything local is cleaner and self-contained.

Max

--------------------

The really successful criminals never break laws. They make them.

Post Extras: Print Post   Remind Me!   Notify Moderator   Email Post
paschors
Curate

Reged: 09/05/03
Posts: 639
Loc: Oregon, USA
Re: passing variables from one script to another? [Re: maxpublic]
      #2037613 - 12/09/03 05:43 AM

Another alternative could be journal entries. You can set journal entries if they exist or not. If they don't, then they set (as long as the journal id exists) anyway. They set, they just don't write anything to your journal.

You might do some experimenting to see if you can go up and down journal entry numbers. Like set it to 10, then set it to 5. And see how your GetJournal stuff comes out. If you set it to 10, then to 5 and ask if it is >5 will it return true? If not, you got yourself another place besides local and global.

I actually have some scripts doing that. Allowing you to take back the acceptance of a task then later say you will do it. I haven't completed testing those scripts though.


--------------------
Paschors/aka Kiriel/ aka Patty
Home Page - Kiriel's Morrowind Creations


Edited by paschors (12/09/03 05:53 AM)

Post Extras: Print Post   Remind Me!   Notify Moderator   Email Post
paschors
Curate

Reged: 09/05/03
Posts: 639
Loc: Oregon, USA
Re: passing variables from one script to another? [Re: Dave Humphrey]
      #2037723 - 12/09/03 06:24 AM

Quote:

Paschors is correct in that you can set local variables of another object in a script. Just to note that you cannot get/check the same variable, i.e:

set SomeValue to object01.LocalVar
if ( object01.LocalVar > 0 )

both won't work (you'll get 0's for each).




Haven't tried doing setting and checking in the same script. But, I don't want anyone to get the impression you can't check a value...you _can_ do this:

if ( object01.LocalVar > 0 )
or an example is:
If ( WA_Cavern_Light.SwitchState == 1 )

I think it is this that you cannot do this....set variable in this script to variable in other script. Don't know why. You can set the variable in the other script and check it.....
set SomeValue to object01.LocalVar

But, I wonder if you can do this? Like say this is in a third script.
Set WA_Lantern_01.doOnce to WA_Lantern_02.doOnce

--------------------
Paschors/aka Kiriel/ aka Patty
Home Page - Kiriel's Morrowind Creations


Post Extras: Print Post   Remind Me!   Notify Moderator   Email Post
Dave Humphrey
Curate

Reged: 06/19/00
Posts: 605
Loc: Toronto, Canada
Re: passing variables from one script to another? [Re: paschors]
      #2037787 - 12/09/03 06:47 AM

Quote:

Haven't tried doing setting and checking in the same script. But, I don't want anyone to get the impression you can't check a value...you _can_ do this:

if ( object01.LocalVar > 0 )
or an example is:
If ( WA_Cavern_Light.SwitchState == 1 )




Are you sure about this? I know of people in the past trying to do this and it just doesn't work. It will compile fine but you just end up returning 0 instead of the actual local variable value. I know it was like this for the original game and Tribunal but haven't checked with Bloodmoon...they do tend to sneak subtle changes like this so I wouldn't be too surprised if it does work now.

--------------------
Dave Humphrey - Unofficial Elder Scrolls Pages, serving the ES community since 1995.
MWEdit - Alternate plugin editor
NIFTexture
Script Functions

Post Extras: Print Post   Remind Me!   Notify Moderator   Email Post
paschors
Curate

Reged: 09/05/03
Posts: 639
Loc: Oregon, USA
Re: passing variables from one script to another? [Re: Dave Humphrey]
      #2037859 - 12/09/03 07:12 AM

I am totally sure you can do the check. It is working just fine in my scripts. The thing that doesn't work is setting a variable in the current script to the value of the variable in another....

If you look at what it says in scripting for dummies, well, here is the exact quote from there. What works I put in yellow, what doesn't is what is in red. SFD is correct.


If a unique object has a local script running on it you can change variables from outside the script in the following way:

Set MyObject.variable to 100
or
Set MyObject.variable to local_variable

This method changes a local variable in the objectís script. The object must have a script on it for this to be valid. Note: The scripting system looks at the first object in the database, thus you should only reference objects that are unique (exist only once).

Note that the reverse does not work:

Set local_variable to MyObject.variable

Use a global variable to transfer information in this way, or set local_variable from the other script using the syntax above.

if ( anotherobject.x > 0 )

apparently works.



--------------------
Paschors/aka Kiriel/ aka Patty
Home Page - Kiriel's Morrowind Creations


Post Extras: Print Post   Remind Me!   Notify Moderator   Email Post
Cortex
Curate

Reged: 01/10/02
Posts: 697
Loc: London, England
Re: passing variables from one script to another? [Re: paschors]
      #2039721 - 12/09/03 11:23 PM

Quote:

if ( anotherobject.x > 0 )

apparently works





Are you sure. If it works its a major improvement. (runs away to check)

--------------------
Transform into a Bat, Mist or Wolf
Download Scripted spells 0.91 here:
http://www.euro-morrowind.com/index.php?section=plugin&code=05&id=2052
Download Vampire Embrace 1.35 from the same site. (Search author Cortex)

Post Extras: Print Post   Remind Me!   Notify Moderator   Email Post
CaveRat
Adept

Reged: 09/18/03
Posts: 227
Loc: Ehh...cave
Re: passing variables from one script to another? [Re: Cortex]
      #2039923 - 12/10/03 01:49 AM

Quote:

Quote:

if ( anotherobject.x > 0 )

apparently works





Are you sure. If it works its a major improvement. (runs away to check)




I am pretty sure.

--------------------
Squeak?!

Post Extras: Print Post   Remind Me!   Notify Moderator   Email Post
Pages: 1


Extra information
2 registered and 5 anonymous users are browsing this forum.

Moderator:  Freddo, Pete, klendathu, Lady Eternity, Locklear93, Hungry Donner, Archeopterix, slateman, tegger, Monica21 

Favorite Thread! (toggle)
Print Thread

Permissions
      You can start new topics
      You can reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Thread views: 103

Rate this thread
 
Jump to

The Elder Scrolls Homepage

*
UBB.threads™ 6.3

Click for Privacy Statement © 2003 Bethesda Softworks LLC, a ZeniMax Media company. All Rights Reserved.
PRIVACY POLICY | TERMS & CONDITIONS | LEGAL INFORMATION | CONTACT US