Object scripts do not retain set variables?

Post » Sat Feb 19, 2011 6:04 am

I have recently been moving from quest scripts to using object scripts. But for years I primarily used quests scripts. In quest scripts once you set a variable such as

short Mycountbegin gamemodeif player.issneaking == 1 && MyCount == 0    set Mycount to 5endifmessage"Mycount %.2f"Mycountend



MyCount would stay that way! But now if use an object script and I set this to 5 then SAVE and then reload the save MyCount will be set to 0 :banghead:


That is really REALLY inconvenient. I am hoping I am wrong about this and my variables are getting reset to 0 for some other reason.
User avatar
Keeley Stevens
 
Posts: 3398
Joined: Wed Sep 06, 2006 6:04 pm

Post » Sat Feb 19, 2011 2:57 am

mmm... well I test this again by putting this in a separate object script (out of the script I am having issues with) and indeed the MyCount STAYED set to 5 even after a reloaded.

So thankfully I was wrong, I guess there is something else in my other script resting the variables.
User avatar
Milagros Osorio
 
Posts: 3426
Joined: Fri Aug 25, 2006 4:33 pm

Post » Fri Feb 18, 2011 8:25 pm

no no no....it happen again. I am not imagining this. I think it is after a RESTART of the game not just a simple save then reload save game.

more testing....
User avatar
Michelle Serenity Boss
 
Posts: 3341
Joined: Tue Oct 17, 2006 10:49 am

Post » Sat Feb 19, 2011 6:47 am

Strange!

After putting the following in my script I no longer am having issues (but more testing needs to be done to be sure):

if getcontainer != player
return
endif


So there would seem to be another instance of the script running someplace. This makes no sense because the items is a quest items and only ONE
was placed in an NPC inventory in the mod.

I will run this on a Global called test:

If doonce == 0
set test to 1
set doonce to 1
elseif test > 1 && doonce == 1
messagebox"more than one."
endif



Conclusion for tonight:

My Test global only registered ONE item existed, but the script is acting as if there was more than one instance of the script running in the game.
But that It is NOT in the player inventory.

So my "patch" to see if the item is in the player's inventory before allowing it to run will solve the issue but not the problem. I am too tired to dig into this anymore. I may just note this situation and keep my patch in my script for now and move on with the rest of the project. I need to get this mod done as it is way past the dealine I wanted.

User avatar
Rob Smith
 
Posts: 3424
Joined: Wed Oct 03, 2007 5:30 pm

Post » Fri Feb 18, 2011 8:02 pm

I vaguely recall hearing something about Scripts Resetting-- but it's not something I've ever encountered myself....

Probably a stupid question, but are you sure you are not adding more than one, or have something in your Script that re-adds the item after x-time; also, .resurrect may cause the item to reload, adding a new version. Not sure if this applies to Quest Objects, but usually NPCs re-spawn their inventory on resurrection.
User avatar
Lance Vannortwick
 
Posts: 3479
Joined: Thu Sep 27, 2007 5:30 pm

Post » Sat Feb 19, 2011 1:07 am

mmmm ...I will check to see if the NPC has more than one, in fact I may just get the name of the actor that the item is in the inventory.

But based on my other tests (see above in my edited comments) I am think there is only one item in the game, but the script acts like there is more than one.

Thanks for trying to help, I am off to bed (only 4 hours past my bed time)...


I vaguely recall hearing something about Scripts Resetting-- but it's not something I've ever encountered myself....

Probably a stupid question, but are you sure you are not adding more than one, or have something in your Script that re-adds the item after x-time; also, .resurrect may cause the item to reload, adding a new version. Not sure if this applies to Quest Objects, but usually NPCs re-spawn their inventory on resurrection.

User avatar
dean Cutler
 
Posts: 3411
Joined: Wed Jul 18, 2007 7:29 am

Post » Sat Feb 19, 2011 12:43 am

Object scripts DON'T reset their vars under any circumstances, as far as I know.
One or multiple objects running the same script does not make any difference. Each object keeps its own set of variables. I've had up to 1,000 similar objects running the same script without problems, each keeping its own set of variables.

Of course, when a new instance of the object is created, a fresh new set of variables is created as well.

The most common situation is when you drop a dynamic item from the inventory, the item created in the world is NOT the same as the one in inventory. The one in inventory is destroyed (along with its script vars) and a new object is created anew in the world. This may give the impression of resetting vars when you drop something.
User avatar
Reanan-Marie Olsen
 
Posts: 3386
Joined: Thu Mar 01, 2007 6:12 am

Post » Fri Feb 18, 2011 10:27 pm

They definitely don't, or Imperial Furniture wouldn't work very well! :) You can have a look at some of the scripts in IFR if you like. You might find them helpful because IFR items have multiple states. They go from marker, to havoked object to static. The link is in my sig.
User avatar
Matt Terry
 
Posts: 3453
Joined: Sun May 13, 2007 10:58 am

Post » Sat Feb 19, 2011 6:18 am

If doonce == 0   set test to 1   set doonce to 1elseif test > 1 && doonce == 1   messagebox"more than one."endif


You would never get a value in this script greater than 1. If you want to test if multiple are running, try this.

(I renamed 'test' to 'testGBL' to identify it as a global variable.)

If doonce == 0   set testGBL to testGBL + 1   set doonce to 1elseif testGBL > 1 && doonce == 1   messagebox "more than one."endif

User avatar
{Richies Mommy}
 
Posts: 3398
Joined: Wed Jun 21, 2006 2:40 pm

Post » Fri Feb 18, 2011 6:36 pm

:facepalm: yes... yes.... PLUS ONE ....um... boy I was so tied last night while working on that...4 hours of sleep in 2 days is not good. I just get so obsessed with overcoming an issue before I can go to sleep.

Thanks WillieSea

I am very sure I have another instance of that script running somewhere in my dirty saves (as a droped object or a phantom script in the save).

I need to start the quest over (clean) and work my way back up to the the point I get the object for the player.
Years ago I wrote about my suspicion of dirty save games where scripts could run a few dozen frames from the save game even when the mod was taken out of the load order. Back then most other modders thought I was crazy to think such a thing.

In the mean time the patch I wrote works great just to get me through my modding of my quest...ha ha

("Mickey Mouse" laugh if you know what I mean) yeah...its bed time....



If doonce == 0   set test to 1   set doonce to 1elseif test > 1 && doonce == 1   messagebox"more than one."endif


You would never get a value in this script greater than 1. If you want to test if multiple are running, try this.

(I renamed 'test' to 'testGBL' to identify it as a global variable.)

If doonce == 0   set testGBL to testGBL + 1   set doonce to 1elseif testGBL > 1 && doonce == 1   messagebox "more than one."endif


User avatar
Kate Schofield
 
Posts: 3556
Joined: Mon Sep 18, 2006 11:58 am


Return to IV - Oblivion