Jump to content

[Script] Externally changing local variables?


Recommended Posts

From what I tried to figure it, it seems to modifying local variables of other scripts is not possible. (?)

I'd appreciate it, if somene could confirm this for me.

 

I also wonder about the reasons for this. Is TES scripting engine this dreadful?

Externally modifying variables of other objects' scripts would be a powerful tool.

Is that not something that OBSE could overcome?

 

 

I have a second question I want to ask.

In my mod I am using persistent activators to hold variables and do some logic on them.

(In a sense, I'm trying to use them like simple objects of object-oriented programming.)

 

I know that I can modify local variables of a persistent activator by calling it's editor ID, like:

set SomePersistentID.localVar to 0

But it surprises me that I can't do the same thing by calling that same persistent object from a reference:

ref someRef
...

set someRef to SomePersistentID
...
set someRef.localVar to 0

(Being able to use references like this would allow me a more elegant handling of persistent activators that I'm using.)

 

Is that really the case? Am I missing something here?

Link to comment
Share on other sites

If memory serves, it is possible to change variables in quests.

 

I used arrays to hold data for objects of object-oriented-like programming.

 

Arrays are nice for this as you can pass them around from function to function.

If memory serves (again), I even passed refs to functions as array entries, so each 'object' could call different functions for the same action,

Link to comment
Share on other sites

If memory serves, it is possible to change variables in quests.

 

I used arrays to hold data for objects of object-oriented-like programming.

 

Arrays are nice for this as you can pass them around from function to function.

If memory serves (again), I even passed refs to functions as array entries, so each 'object' could call different functions for the same action,

I know you can directly access variables of quest and persistent object scripts

but only if you specify their exact name (editor ID).

 

You can't seem to be able to do that if you're calling from a reference though.

Or do you mean to say that it's actually possible?

 

 

Arrays could do as a workaround I guess... It's an interesting approach.

The "OOP object" would only need to hold it's own index. Then you could access it's "data" from global arrays.

I will keep it in mind, in case I can't figure it out the way I want.

Thanks!

 

 

Actually, I noticed a strange behavior in TES4CS Extended script editor.

This just adds up to my confusion...

(Check attached image.)

 

 

Edited by Eillis
Link to comment
Share on other sites

This is the same problem as the other. If the object (and its script data) are in the same cell as the player or are still in memory, you can set variables and activate them.

 

I fixed two vanilla issues related to this issue. One is in the Hall of Epochs, when you have to go into an adjacent room and push a button that is supposed to lower the walls around the Undead and the gates where you gotta shoot the arrow of extrication. That would not work for me most of the time. So, I changed the switch to set a quest variable when pushed, and added a new TriggerZone to the main room that detects when you return to that room and you've activated that switch, and it activates the first thing in the daisy-chain (the same activator that was activated by the switch). This works 100% of the time.

 

I did something similar with two oblivion realms where you activate a gate switch in a tower, and it's supposed to open a gate or extend a bridge in the exterior space. In that case, the switch script sets a variable within itself (instead of a quest variable) and the trigger-zone in the world space checks the variable in the other script. So, you can at least read a value from another object script.

Edited by GamerRick
Link to comment
Share on other sites

Changing Questscripts from other scripts works perfect and functions, but the other way around seems not to work properly.

The whole purpose of my response is to help demystify it and show that if you play by the undocumented rules and limitations of this game's scripting language, you can get almost anything to work properly.

 

Another technique is to create a new armor item that is set to unplayable. You can add this item to the player, and it's object script will run the same as it does for objects that are in the same cell as the player. You can add the item to the player with the AddItemNS command and they will never know. Because it's set to unplayable, the player will never see the item in their inventory. It's up to you then to decide what blocktypes to use. You can create a OnAdd block to fire when it's added, and/or create a GameMode block to do things. Just keep in mid that an object script with a GameMode block will run every frame. There is no such thing as a fQuestDelay variable to control how often it runs.

 

The rules for object scripts are actually very simple, as I have already explained.

 

Just in case you don't already know this, when calling another object script, you call it from the object's RefID (just like to access a quest script you use the QuestID). For example, to access the object script of an NPC you use the RefID of the NPC to access their script. Obviously the NPC has to be set to persistent to do this.

Edited by GamerRick
Link to comment
Share on other sites

I keep getting more confused and disappointed with the scripting language.

 

It appears that you simply cannot access a local variable from a reference.

 

 

 

(I tried moving those activators to player with MoveTo. That didn't help either.)

 

 

EDIT:

GetVariable and GetRefVariable seem to allow me to retrieve data from a reference.

This code works perfectly:

set refVariable to temp.GetRefVariable "horseController"

Now I am still missing an ability to set local variables through references.

Edited by Eillis
Link to comment
Share on other sites

I eventually figured out how to work with scripting.

 

I wanted to use Activators as "objects" to contain some data and perform operations on it.

To be exact, I wanted my Activators to control assigned NPCs in accordance with how they are configured.

 

As I mentioned, from references we can only read local variables but cannot modify them.

This prevented me from parametrizing my Activators in other scripts.

 

I solved this by moving Activators' "parameters" or, so to say "public variables" into quest script arrays.

Each Activator has it's own index, which is used to read "public data" assigned to it.

Since that data is inside a single quest script (a static singleton), I can read and modify it from anywhere, without needing to access it from a reference.

 

So this is probably the same thing that QQuix did.

 

Just wanted to share my final solution in case someone else has these problems.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...