[SOLVED] Storing Local Variable On PC
RandomStranger
Member Posts: 10
Hello,
I am trying to edit a module to change something to my liking. To do so I need to set some data and I decided to store in on the PC object. However I run into a problem: I use the exactly same method of storing the local variable as the module does - but the problem is that my new variable is only set up until the moment I leave the area where it was set. When I arrive to another area, it's lost (while the existing module variables are still fine).
Why could it be the case? Is there any variables registry where I need to add mine too? Are there any triggers / events that reset variables? (Just in case, I've checked the "Events" of the module and both areas in the toolset and there's nothing suspicious there).
Here's how I set it:
and I do so in the conversation tab of "Actions Taken". In the existing (subsequent) branches of the conversation there are some module existing variables set to some values via exactly the same method.
Now if I run the module:
Which hints that everything works here. The same method of console value retrieval is working of the module existing variables. But when I am moved to another area, "dm_getvarint MyAddedVar" starts to return me "0" and any branches conditional on it being "1" subsequently fail.
Any ideas why it is so? Any help is appreciated.
I am trying to edit a module to change something to my liking. To do so I need to set some data and I decided to store in on the PC object. However I run into a problem: I use the exactly same method of storing the local variable as the module does - but the problem is that my new variable is only set up until the moment I leave the area where it was set. When I arrive to another area, it's lost (while the existing module variables are still fine).
Why could it be the case? Is there any variables registry where I need to add mine too? Are there any triggers / events that reset variables? (Just in case, I've checked the "Events" of the module and both areas in the toolset and there's nothing suspicious there).
Here's how I set it:
void main () { object me = GetFirstPC (); SetLocalInt (me, "MyAddedVar", 1); SendMessageToPC (me, "It was set to 1"); }
and I do so in the conversation tab of "Actions Taken". In the existing (subsequent) branches of the conversation there are some module existing variables set to some values via exactly the same method.
Now if I run the module:
- I am able to see my added dialogue branch properly
- If I go through this branch, I see "It was set to 1" in yellow in the log, as intended
- If I try "dm_getvarint MyAddedVar" on the PC in console before going through the branch, I see "0" as a result
- If I try "dm_getvarint MyAddedVar" on the PC in console after going through the branch, I see "1" as a result
Which hints that everything works here. The same method of console value retrieval is working of the module existing variables. But when I am moved to another area, "dm_getvarint MyAddedVar" starts to return me "0" and any branches conditional on it being "1" subsequently fail.
Any ideas why it is so? Any help is appreciated.
Post edited by RandomStranger on
0
Comments
TR
Thanks. Well - I'm completely new to NWN scripts (not new to the whole scripting though). So I don't understand why the existing variables set by the module work and mine doesn't.
Apart from that, the module has several chapters (part 1,2 etc) which are separate modules. If I understand it correctly, it stores variables in the PC object precisely because it wants to transfer them through those separate chapters. If I set a variable on the module - won't it be lost if I move between chapters (because they're technically different module files)?
Well, the module variables set on PC somehow work though. Adding an item seems to be an okay idea, but I struggle to make it lore-friendly (the item would need to be responsible for some decisions PC makes or events that unfold - but it's not the "journal" type)
Seems that somewhere in your module MyAddedVar is reset to 0.
Btw if you don't have many locals you can use dm_dumplocals instead of dm_getvarint MyAddedVar (quicker to type). You can even put that on the quickbar.
Wow, that's incredibly useful! And helped me a lot! It turns out that if I check all variables after every step of the dialogue where I set it, I see that:
So.. it has nothing to do with changing areas (and that alone is a huge progress!), but rather - it only exists when I am on that specific dialogue entry and immediately disappears right after. Any ideas, why is that?
Also, good idea that maybe I accidentally used a name that's also used somewhere else in the module but it's unlikely. I made it very obscure and added some random jibberish at the end of its name just to be sure it can't be the case.
Setting local variables on PCs works exactly as expected - in a single player module, the variable persists until some script deletes it.
Passing variables between modules or server sessions is more complicated, but that doesn't seem to be the issue here.
So it works now, all the stuff is set and the branches I added later react on the variable as I'd expect.
Now, there's another question - likely for another topic, but still:
How to test dialogues / scripts etc on a large module? I mean it can be several hours of gameplay till I get to the point I want to test. Or worse - I need to take certain plot route to even get there. The thing is - as far as I observed, if I make a change to the module, I always need to start a new game with it in order to see changes. This severely complicates any testing of my changes.
So - how does everybody does it? I doubt that when dozens of hours of playtime are involved, it really requires that for any change in the logic (which maybe faulty as my experience above shows - I was just lucky that my change is possible to test after 5-10 minutes of gameplay)
If that is the case then just save game right before you enter the area with the custom changes and load that save for testing.
It's not OC, but rather a big module (not my making, but I just want to do some local edits to add some stuff and alter some plot routes). I tried exactly what you said: save in the area before the one I'm going into - where the dialogue I've been working on is triggered. And it didn't work. Not only the scripts weren't triggered, even the new branches I added in the editor never showed up. It was all as if I'm playing the cached version of it.
Also, the size of the save file is larger than the size of the module itself (the module is ~80Mb and the save is ~150Mb - holy cow! I found what's eating my disk space) - that hints me that the game just writes the whole module into it therefore confirming my guess about caching. If that's the case then I have no idea how to test anything, really.
Once it's working to my satisfaction, I delete all that extra stuff and put the start location back to where it should be.
Here's an article about how NWN loads content:
https://nwn.wiki/display/NWN1/Content+Load+Order
For unit testing, in the toolset, use Paint Start Location (top right icon) to start at the desired point. Build > Test Module to launch at that point, by-passing character generation.
Run a script in game to set up anything that would normally have happened earlier, for example
You'll find that for a given test, you generally need to set very few things. For example, to test an advanced stage of a conversation, you may only need to set one journal to a higher state.
However, since tests often need to be repeated, I find it convenient to have everything in one script, with the unwanted sections dummied out. For example,
is dummied out, but if you simply add // to the start of the comment, the whole section will be executed (the final //*/ enables that trick).
When the entire module seems to be ready for release, remember to Paint Start Location at the original position, and do plenty of end-to-end testing, ideally for each race and class.
But the article says "all files except .mod" ? I.e. if I modify the module that I need to test, even if I place it into the development folder, it will be ignored? And the next in the load order is already a .sav file. If I didn't miss anything, placing .mod into the development folder will not help here?
that's not exactly what unit-tests are, but thanks, I got the idea on how to test certain things in the module. Will give it a go.
I didn't know I can do that, I mean - that it's possible to extract anything from the module. Where is that "temp0" folder? I don't have it in my "modules" location.
Ah, that's good to know - it exists there indeed when I open it. I will try!
Thanks, everyone, this was most helpful!