Jump to content

Having problems with While


antstubell

Recommended Posts

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 Auto
ObjectReference Property MyObj01 Auto

Event OnActivate(ObjectReference akActionRef)

While (MyGlobal.GetValue() < 999)
MyObj01.Disable()
Utility.Wait(2)
MyObj01.Enable()
MyGlobal.Mod(1)
EndWhile

EndEvent

 

 

 

Int Property Count =0 Auto
ObjectReference Property MyObj01 Auto

Event OnActivate(ObjectReference akActionRef)

While Count < 999
MyObj01.Disable()
Utility.Wait(2)
MyObj01.Enable()
Count = Count +1
EndWhile

EndEvent

 

 

Thanks for any help.

 

Link to comment
Share on other sites

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

(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

As suggested adding another Utility.Wait fixes it.

 

Int Property Count =0 Auto
ObjectReference Property MyObj01 Auto

Event OnActivate(ObjectReference akActionRef)

While Count < 999999
Utility.Wait(1)
MyObj01.Disable()
Utility.Wait(1)
MyObj01.Enable()
Count = Count +1
EndWhile

EndEvent

 

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 Auto
GlobalVariable Property RndNum Auto
ObjectReference Property MyObj01 Auto

Event OnActivate(ObjectReference akActionRef)

While Count < 999999
Number()
Utility.Wait(RndNum)
MyObj01.Disable()
Number()
Utility.Wait(RndNum)
MyObj01.Enable()
Count = Count +1
EndWhile

EndEvent
; -------------------------------------------------------------
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 by antstubell
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...