antstubell Posted June 28, 2019 Share Posted June 28, 2019 How do I generate a random number, let's say between 0-9 and save it in a global variable? Link to comment Share on other sites More sharing options...
Evangela Posted June 28, 2019 Share Posted June 28, 2019 There's 2 functions for this. An integer and a float. (Examples only) GlobalVariable property myGlobal auto Function Something() Int iRand = Utility.RandomInt(0, 50) myGlobal.SetValue(iRand as Float) EndFunction Function Something2() Float fRand = Utility.RandomFloat(0.0, 50.0) myGlobal.SetValue(fRand) EndFunction Link to comment Share on other sites More sharing options...
antstubell Posted June 28, 2019 Author Share Posted June 28, 2019 Thanks. Link to comment Share on other sites More sharing options...
antstubell Posted July 29, 2019 Author Share Posted July 29, 2019 (edited) This script always gives me 0Help please. ObjectReference Property ChairMarkerREF AutoActor Property PlayerRef AutoSound Property MySND0 AutoSound Property MySND1 AutoGlobalVariable Property RndNum AutoFunction Something()Int iRand = Utility.RandomInt(0, 2)RndNum.SetValue(iRand as Int)EndFunctionEvent OnActivate(ObjectReference akActionRef)if akActionRef == PlayerREFChairMarkerREF.Activate(PlayerREF)Utility.wait(4.0)If RndNum.GetValue() == 0Debug.Notification ("Random 0 returned")MySND0.play(self)EndifIf RndNum.GetValue() == 1Debug.Notification ("Random 1 returned")Game.DisablePlayerControls()MySND1.play(self)Utility.wait(4.0)Game.EnablePlayerControls()EndifIf RndNum.GetValue() == 2Debug.Notification ("Random 2 returned")EndifendifEndEvent Changed...RndNum.SetValue(iRand as int)toRndNum.SetValue(iRand as float) Still 0 Edited July 29, 2019 by antstubell Link to comment Share on other sites More sharing options...
IsharaMeradin Posted July 29, 2019 Share Posted July 29, 2019 Script as written has nothing calling the Something function. As a result, there is no random value generated or applied to the global variable. Thus the returned value of the global variable will always be the initial value that you gave the record. Which in this case seems to have been 0. Call the function inside the OnActivate event prior to checking for the random value. Function Something() Int iRand = Utility.RandomInt(0, 2) RndNum.SetValue(iRand as Int) EndFunction Event OnActivate(ObjectReference akActionRef) if akActionRef == PlayerREF Something() ChairMarkerREF.Activate(PlayerREF) Utility.wait(4.0) If RndNum.GetValue() == 0 Debug.Notification ("Random 0 returned") MySND0.play(self) Endif If RndNum.GetValue() == 1 Debug.Notification ("Random 1 returned") Game.DisablePlayerControls() MySND1.play(self) Utility.wait(4.0) Game.EnablePlayerControls() Endif If RndNum.GetValue() == 2 Debug.Notification ("Random 2 returned") Endif endif EndEvent Link to comment Share on other sites More sharing options...
Evangela Posted July 29, 2019 Share Posted July 29, 2019 (edited) Something() function is not called. You wont need that though, you can put the code for that right in the Event you're using. Then it will start generating a random number on every activation. Edit: ninja'd lol Edited July 29, 2019 by Rasikko Link to comment Share on other sites More sharing options...
antstubell Posted July 29, 2019 Author Share Posted July 29, 2019 Got it.Thanks guys. Link to comment Share on other sites More sharing options...
Recommended Posts