antstubell Posted July 24, 2021 Share Posted July 24, 2021 I feel pretty dumb because I've done this successfully before but for the life of me can't get it working now.The While statement. The following two scripts I've tired but all I get is the object disabled then nothing. GlobalVariable Property MyGlobal AutoObjectReference Property MyObj01 AutoEvent OnActivate(ObjectReference akActionRef)While (MyGlobal.GetValue() < 999)MyObj01.Disable()Utility.Wait(2)MyObj01.Enable()MyGlobal.Mod(1)EndWhileEndEvent Int Property Count =0 AutoObjectReference Property MyObj01 AutoEvent OnActivate(ObjectReference akActionRef)While Count < 999MyObj01.Disable()Utility.Wait(2)MyObj01.Enable()Count = Count +1EndWhileEndEvent Thanks for any help. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted July 24, 2021 Share Posted July 24, 2021 Because the loop is relying on a count value, it is doing the following: Disabling, waiting 2 seconds, enabling, advancing count, repeating. What is most likely happening is that the disabling is taking affect before the object can fully enable. You can add a wait after the enable such that you will see the object enable before it disables. But if that isn't what you want to have seen (the appearance of a flicker I suppose), you'll need to re-think the While condition. Link to comment Share on other sites More sharing options...
ReDragon2013 Posted July 24, 2021 Share Posted July 24, 2021 (1) You did not check, who is actionRef. In your code it could be any ObjectReference, actor as well (not only the player).(2) Whatever you do, do never use a while loop inside event OnActivate() without a state change before.(3) By using a wait longer or equal than 0.25, all code after wait() is stopped until the object (self in this script) has finished activation (sounds curious I know). (4) your counter is Zero at the begin of your loop, if not changed by other events or external script action. While Count < 999 That means your while loop runs a long time, because of a two second wait(2.0) inside. A minute has 60 seconds (you know). After a minute your counter would have a value of 30, which is far away from 999. It's better to explain what is your aim, than trying such horrible script construct. Link to comment Share on other sites More sharing options...
antstubell Posted July 25, 2021 Author Share Posted July 25, 2021 (edited) As suggested adding another Utility.Wait fixes it. Int Property Count =0 AutoObjectReference Property MyObj01 AutoEvent OnActivate(ObjectReference akActionRef)While Count < 999999Utility.Wait(1)MyObj01.Disable()Utility.Wait(1)MyObj01.Enable()Count = Count +1EndWhileEndEvent Thanks. EDIT Expanding the script, you'll see where I'm going with this, I'm having further trouble. I kind of get what the problem is but don't know what 'type' the Utility.Wait wants. Int Property Count =0 AutoGlobalVariable Property RndNum AutoObjectReference Property MyObj01 AutoEvent OnActivate(ObjectReference akActionRef)While Count < 999999Number()Utility.Wait(RndNum)MyObj01.Disable()Number()Utility.Wait(RndNum)MyObj01.Enable()Count = Count +1EndWhileEndEvent; -------------------------------------------------------------Function Number()Int iRand = Utility.RandomInt(1, 5)RndNum.SetValue(iRand as Int)EndFunction type mismatch on parameter 1 (did you forget a cast?)type mismatch on parameter 1 (did you forget a cast?) Edited July 25, 2021 by antstubell Link to comment Share on other sites More sharing options...
IsharaMeradin Posted July 25, 2021 Share Posted July 25, 2021 You are putting in a Global Variable instead of a float.Try:Utility.Wait( RndNum.GetValue() ) Link to comment Share on other sites More sharing options...
antstubell Posted July 26, 2021 Author Share Posted July 26, 2021 Ok, now the 'effect' is like a strobe light even if I extend the range (1, 9). I thought the Utility.Wait would use seconds. If I use Utility.Wait(1) it waits 1 second. What random numbers are being generated? Link to comment Share on other sites More sharing options...
Recommended Posts