Jump to content

Persistence of Variables in Event Handlers


Recommended Posts

This sounds like it is really a question about "variable scope". Doesn't matter if you are talking about a "function" or an "event handler". But I think you are asking more about the nature of a "parameter".

 

Speaking very generally (as there are always exceptions), a variable passed as a "parameter" to another function is a "value" rather than the variable itself. So the receiving function (your event handler) gets the "value" of the passed parameter variable which it "initializes" to it's own internally declared "parameter variable". The original variable is unchanged and merely a vehicle to convey the value. (Which is not to say it can't get assigned the "returned value" of the event handler if set up that way.)

 

Think of variables like "taxis": they carry a passenger (value) around from one location to another, but are not the what the location cares about. Only their contents, which can be (and likely are) different each trip. But, each taxi is somewhat specialized and is expected to have a "passenger" of a particular nature (e.g. "lawyer" = "long integer", "singer" = "string", etc.).

 

-Dubious-

Link to comment
Share on other sites

Hmm. I'm of the impression that it depends on whether or not the variable is defined before or after the "Begin" block, but I can't find a reference off-hand so don't count on that without testing. If you want to ensure persistence confined to the Event Handler, I would suggest you look into "Auxiliary Variables".

 

But as for event handlers themselves, according to Docta Sax' tutorial:

 

Event handlers are UDFs that you register with NVSE to be called whenever [and before] their associated event happens. These handlers are then set for the rest of the game session; even if you load a different save, they are still valid until you actually restart the game.

 

 

-Dubious-

Link to comment
Share on other sites

Do you mean a variable as it relates to the "First" & "Second" of an eventhandler ?

So basically you capture a variable , then plug that variable into the eventhandler for 1 or 2 ?

Which honestly I didn't know that was possible if is the case.

 

Or is this a variable condition as a prefix trigger and/or suffix count of the trigger ? (something outside 1 & 2 )

 

As a mention to expand on what dubious said. Variable storage is possible without scripts or globals .

By using a container to put stuff in or take out. Then check it's item count , or even what is in them.

Something I learned from PixleHate a few years back ... thought it worth a mention as a means to keep a persistent variable where instances of scripts variables get reset from 1 to another instance of the same script.

Link to comment
Share on other sites

What's an example of a local variable ?

Any variable defined in a script at the time it runs. See the link on "variable scope" in my initial reply. See also "Global variables" in the GECKWiki.

 

Where it gets murky is "inheritance", because a "child" script called from another script will "inherit" variables of the parent script. This is not the same as a "global" variable which is available to any script regardless of whose child it is.

 

And question I am not clear on.

 

When an EventHandler fires ... it needs reset in order to trigger again ?

Per the ref GamerRick found: a UDF is a "one frame" script; and an EventHandler is just a particular kind of UDF. So it automatically is reset each time it is called/triggered.

 

-Dubious-

Edited by dubiousintent
Link to comment
Share on other sites

  • Recently Browsing   0 members

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