tsdobbi Posted July 20, 2020 Share Posted July 20, 2020 (edited) Basically this on update should fire every 1200 seconds. i.e. it should be onInit update will fire in 1200 seconds. update fires (performs logic) registers for another single update in another 1200 seconds. I put a debug message box at the beginning of the update and its literally firing non stop. (I have to literally close the game from task manager because I cant get out of the dialogue box to get to the menu it happens so fast). For reference, the script is attached to an Xmarker I placed. (FYI this script worked fine and wasn't doing that when I initially made the script, the update was firing when it should, confirmed by a debug mbox) I wanted to test a change to the NPC that gets spawned, so I lowered the update time to 30 seconds and thats when I noticed this happening. I'm assuming maybe there is something I don't understand about updates and if "over time" something is breaking. What is also disconcerting is the logic isn't firing correctly either. (i.e. its reporting the player having the perk as false...when it is true). Like I said, literally all I changed since it had been working was the seconds for the registerForSingleUpdate. The whole thing just seems to have imploded for no apparent reason. I have other scripts (attached to NPC's and the Player alias) that use similar functionality and are not breaking like this, and have been running far longer (i.e. OnInit register for single update > do stuff > register for another single update) including using the if(Game.GetPlayer().HasPerk(Perk)) to check if the player has a perk and it's reporting correctly. For some reason this script just stopped working (isn't reporting correct values, executing updates way too fast etc.). Reconfirmed the properties for the script were set up correctly (i.e. the perk is pointing to the right perk). I'm curious if attaching it to the Xmarker is the cause of the issue. Scriptname InitSpawn extends ObjectReference import game import debug import utility import sound event OnInit() RegisterForSingleUpdate(1200) gotoState("waiting") endEvent STATE waiting Event OnUpdate() if(active == false) if(Game.GetPlayer().HasPerk(Perk)) SpawnNPC(NPC) endif endif deadCountUpdate = currentActiveNPC.GetDeadCount() if(deadCountUpdate > deadCount) active = false EndIf RegisterForSingleUpdate(1200) EndEvent endSTATE STATE done endSTATE function SpawnNPC(ActorBase target) currentActiveNPC = target startMarker.PlaceActorAtMe(target,3) active = true deadCount = currentActiveNPC.GetDeadCount() EndFunction Edited July 20, 2020 by tsdobbi Link to comment Share on other sites More sharing options...
cumbrianlad Posted July 20, 2020 Share Posted July 20, 2020 You say it worked fine and then didn't when you changed the properties. How are you testing? If you are testing on a save that has seen your mod when the script had the original value in, then it's not a valid test. Changing scripts or script properties often doesn't work when you test on an old save. They are baked into your save. Link to comment Share on other sites More sharing options...
tsdobbi Posted July 20, 2020 Author Share Posted July 20, 2020 (edited) You say it worked fine and then didn't when you changed the properties. How are you testing? If you are testing on a save that has seen your mod when the script had the original value in, then it's not a valid test. Changing scripts or script properties often doesn't work when you test on an old save. They are baked into your save. I didn't change the properties at all (I just double checked them in the CK to make sure they were correct). All I did was change the registerForSingleUpdate from 1200 to 30 and added a debugMessageBox so I knew when it triggered. So I did a few tests: 1. New Game - Script is executing as expected.2. reloaded a save (a couple of saves after I added this script) again functioning as intended (even with the change to 30 second updates and adding the debug box) its triggering an update every 30 seconds.3. any more recent save. It's totally screwed and constantly firing updates and not reporting the correct value for the player having the perk. I get that the "orginal script" may be baked into the save, but the behavior of the script at this point is making zero sense even in that regard. i.e. I don't think the change to the update seconds and adding the debug box caused this problem. I think it revealed a problem. (because I loaded an earlier save, that already had the script loaded, with those same changes and it didn't cause the same behavior, only recent saves display this behavior). I think one further test I am going to do is to load a new game and just let it run for like 3-4 hours with debug notifications and see if at any point it just starts spamming notifications indicating its in the broken state I was seeing. Edited July 20, 2020 by tsdobbi Link to comment Share on other sites More sharing options...
cumbrianlad Posted July 20, 2020 Share Posted July 20, 2020 I'm reserving judgement. If it performed right on a new game, that backs up what I'm saying... there may be nothing wrong with the script, just the save it was used on.Always and always test any changes to scripts or property chnages to scripts. on a clean save. In fact, test everything on a clean save until you know what you can update in CK without it being affected. When you can test on an old save: There aren't many that I've found, but adding new plants/statics doesn't mess it up. Err... that's about it! Any other changes made in CK won't be reflected in your game, if it relies on an old save. Link to comment Share on other sites More sharing options...
tsdobbi Posted July 20, 2020 Author Share Posted July 20, 2020 (edited) I'm reserving judgement. If it performed right on a new game, that backs up what I'm saying... there may be nothing wrong with the script, just the save it was used on.Always and always test any changes to scripts or property chnages to scripts. on a clean save. In fact, test everything on a clean save until you know what you can update in CK without it being affected. When you can test on an old save: There aren't many that I've found, but adding new plants/statics doesn't mess it up. Err... that's about it! Any other changes made in CK won't be reflected in your game, if it relies on an old save. I agree with you I (hope) that the change to the script in a save where it was already introduced was the cause. (Mainly because as far as I understand it, I use register for single update correctly in this case). Quick Q, if you have this level of understanding of it, just trying to understand how the updates work. 1. As far as I understand it, you should ALWAYS use register for single update where possible.2. As far as running the first update from "OnInit". I assume this runs every time the game loads. So my question is, I load the game and save a few minutes later. There was an update registered (and it was in the process of waiting for the count to tick down). When I load the save again, onInit registering an update when you load into the game as I understand. So the update that was registered before the save, is that still there and running in parallel to the new registered update from onInit when I loaded the game? In summary, would constantly loading and making new saves be propagating registered updates running in parallel or can there only every be one running for a specific script with registerForSingleUpdate. (i.e. should "checking" if an update is already registered be something we do here? I want to know if what I am doing is considered bad practice. Edited July 20, 2020 by tsdobbi Link to comment Share on other sites More sharing options...
IsharaMeradin Posted July 21, 2020 Share Posted July 21, 2020 OnInit normally runs only once and that is when the object holding the script is initialized (or loaded) for the first time. There is an exception to this and that is with start game enabled quests, in this case it will fire twice. This is why many use a single update registration on their quest scripts. It prevents their code from running twice since a second registration for an update overrides the prior registration for an update. There can ever only be one time frame registered for an update. Exception is that there can be a registration for game time update along side registration for single update as the two utilize different timers and different update events. Link to comment Share on other sites More sharing options...
cumbrianlad Posted July 21, 2020 Share Posted July 21, 2020 I can't add anything to what IsharaMeradin has said. Hopefully your problem is now solved. Link to comment Share on other sites More sharing options...
Recommended Posts