Thacker Posted March 16, 2011 Share Posted March 16, 2011 I'm running into a problem with my current script. I have it showing a different message for each of 4 different states. Whenever a state changes it correctly shows the new, relevant message. Unfortunately, since the script runs every 2 seconds, the messages are showing up every 2 seconds. It's not game breaking, but it is annoying. I tried making the messages show only once by doing a If MsgToggle == 1 ShowMessage Message01 set MsgToggle to 0 But the problem I run into is resetting MsgToggle at the start of each state, thus resulting in MsgToggle always equally 1 and the message always showing. I'm pretty sure there is a fairly simple way to do this. Sadly I cannot figure it out. Thus, help would be most appreciated. Thanks! Link to comment Share on other sites More sharing options...
davidlallen Posted March 16, 2011 Share Posted March 16, 2011 It isn't quite clear what you mean by a "state" here. Many scripts use the technique of setting a "DoOnce" variable successfully. For scripts such as quest scripts, the variables are persistent, which means that the value set at the end of one script execution is still there at the start of the next execution. I am not sure why you are finding variables "non persistent". Can you describe a little bit more about your script? If it is not huge, can you post it with [ code ] and/or [ spoiler ] tags so we can see? Link to comment Share on other sites More sharing options...
rickerhk Posted March 16, 2011 Share Posted March 16, 2011 If you are tracking 4 states, you should add some code so that MSgToggles don't get reset until a state changes. Its hard to be more specific without seeing more of your script but maybe something like this will help: short iCurrentState short iPrevState Begin GameMode ;================= ;Code here to determine what iCurrentState is if iCurrentState == iPrevState else ;do nothing if no change if iCurrentState == 1 showmessage State1 elsif iCurrentState == 2 showmessage State2 elseif iCurrentState == 3 showmessage State3 else showmessage State4 endif set iPrevState to iCurrentState endif END Link to comment Share on other sites More sharing options...
Thacker Posted March 16, 2011 Author Share Posted March 16, 2011 It isn't quite clear what you mean by a "state" here. Many scripts use the technique of setting a "DoOnce" variable successfully. For scripts such as quest scripts, the variables are persistent, which means that the value set at the end of one script execution is still there at the start of the next execution. I am not sure why you are finding variables "non persistent". Can you describe a little bit more about your script? If it is not huge, can you post it with [ code ] and/or [ spoiler ] tags so we can see? No prob. I guess I was being overly paranoid and trying not to tip my hand, since (far as I know) this mod hasn't been released for NV and I was hoping to get it out there as my debut :happy: Begin Gamemode If condition1 Showmessage message1 ElseIf condition2 Showmessage message2 ElseIf condition3 Showmessage message3 ElseIf condition4 Showmessage message4 EndIf End The code as written works for my purposes. The problem is this is a quest script that is running constantly. Thus, every time it is run, a message appears. I would prefer for the message to only appear the first time one of the conditions are met, and then when a new condition is met, for it's message to only display once, etc. Hope that makes sense. Link to comment Share on other sites More sharing options...
Thacker Posted March 17, 2011 Author Share Posted March 17, 2011 Hmmm, your code makes perfect sense, rickerhk, but for some reason the damn thing isn't working for me. I'll try tweaking it/checking it and make sure it's not something I mistyped or the like. Link to comment Share on other sites More sharing options...
PaladinRider Posted March 17, 2011 Share Posted March 17, 2011 (edited) Short DoOnce Begin GameMode if (condition1) && ( DoOnce == 0) set DoOnce to 1 Elseifs/Elses EndIf End Thats the simple way of making a script run only once. If you ever want it to run again, you just need to set DoOnce to 0 elsewhere... It really depends on what you're trying to achieve. Note, if this is a quest script, you can change DoOnce from another script by calling Set MyQuest.DoOnce to 0 The quest needs the specific script (with the DoOnce short) attached. Edited March 17, 2011 by PaladinRider Link to comment Share on other sites More sharing options...
Thacker Posted March 17, 2011 Author Share Posted March 17, 2011 Thanks rickerhk, got it to work. I was just sloppy typing in the code :D Thanks everyone who replied! Link to comment Share on other sites More sharing options...
Recommended Posts