Jump to content

Having issues with global variables and papyrus


YaBoyChrisB

Recommended Posts

The functionality you want to achieve is probably best handled in a permanently running (or rather: listening for events) fashion. Most mod authors use a Quest for running a script in the background. Attaching scripts to ObjectReferences is good for controlling things that go on locally in some cell but you want to handle things globally. That doesn't mix well.

 

Imagine a script that is "always on" and basically listens for OnCellLoad events, and when it receives one of them, polls the state of a global variable and, accordingly, performs some actions to nearby references of a certain type.

Link to comment
Share on other sites

Okay so what I'm basically trying to do is create my own version of the SomeGuySeries. I've been sitting on a mod series for awhile and recently got the itch to make some more and want to have an intertwining series of mods.

 

So for this test, I have my ESM and two ESPs. The ESM holds a GlobalVariable set at 0. In ESP1, there's an actor in a cell with a script attached it him, when he dies his script is meant to change the ESMs GlobalVariable to 1. In ESP2, there's a static table (initially disabled) in a cell, and it has a script attached to it that's supposed to enable it when the ESMs GlobalVariable is set to 1.

 

I'm trying to set this up so that, in future mods, I can have an event where the player makes a choice in a quest, and then in a different mod there's a reaction to that choice.

Link to comment
Share on other sites

Why separate ESMs and ESPs what are you achieving with that ?

 

What is the trigger you want to use that will cause the static table attached script to check the global variable ?

 

This looks like a design issue, not scripting code.

Link to comment
Share on other sites

The ESM is meant to hold the variables, the ESPs are connected to the ESM. I have seperate ESPs so I can make mulitple mods connected to the same ESM so they can communicate when the player makes different choices.

 

I tried OnLoad to trigger the table script, it compiled but nothing happened. I then tried OnPlayerLoadGame but kept getting the compile error that the script wasn't flagged as native, which I don't know how to do.

Link to comment
Share on other sites

The functionality you want to achieve is probably best handled in a permanently running (or rather: listening for events) fashion. Most mod authors use a Quest for running a script in the background. Attaching scripts to ObjectReferences is good for controlling things that go on locally in some cell but you want to handle things globally. That doesn't mix well.

 

Imagine a script that is "always on" and basically listens for OnCellLoad events, and when it receives one of them, polls the state of a global variable and, accordingly, performs some actions to nearby references of a certain type.

 

So I have a script in one ESP that's listening for something in the ESM to change, then when another script in a different ESP triggers that ESM to change, that first ESP script will notice and then complete its task? That's along the lines of what I'm trying to do

Link to comment
Share on other sites

Not exactly. The script would be running in a Quest contained in the ESM and poll for variables also in the ESM, which are manipulated by other scripts contained in an ESP. Without the ESPs, the variables would then remain at their default value.

Link to comment
Share on other sites

Gotcha! I was thinking something along those lines. So would the quest just needs scripts, or would I have to set some things in the Stages tab? Like conditionals and such. I'm assuming I could have multiple scripts in one quest.

 

I also got my initial OnLoad attempt working by playing with the values of the global variable. It works as intended but it doesn't seem like the cleanest method, so thanks for filling me in on this one!

Link to comment
Share on other sites

You should take a look at how other mods do this. You could use PIRAD from my signature, it has a quest for its startup procedure, the source code (Scripts\Source\TrueRads\StartupQuestScript.psc) is packed up in the Main BA2 archive. Its continuous effects run in a different record (multiple MGEFs attached to a SPEL attached to a PERK) but the Quest record and script should get you started at something.

 

Regardless, what you want to ultimately do is far beyond my capabilities so you'll have to research how to make Quests.

Edited by payl0ad
Link to comment
Share on other sites

  • Recently Browsing   0 members

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