[Papyrus] Why isn't this random number generator script work

Post » Mon Jun 18, 2012 11:36 pm

I'm trying to write a (fairly) simple script to return a number between -4 and 4, and set a global variable equal to that number every day at 12:00 PM. While I'd be adding quite a few additional calculations (hence the calling of Globals and Properties that aren't referenced in the script, I'm just trying to get one piece of the script working at a time. Of course, as of now, none of the script is working. It's compiling, and I've set the properties

I'm not quite sure what exactly is causing this problem, and would appreciate any help the denizens of this forums could provide.


ScriptName CohRandomizerScript Extends Quest;GlobalsGlobalVariable Property cohRandomSeed autoGlobalVariable Property cohMoonPhase autoGlobalVariable Property GameHour auto;Localsbool Property bkeepupdating = true autoint Property ChanceVariable autoEvent OnInit()RegisterForSingleUpdate(1)EndEventEvent OnUpdate()ChanceVariable == utility.RandomInt( -4 , 4 )while GameHour.Value != 12; idleEndWhilecohRandomSeed.SetValue( ChanceVariable )endifif bkeepupdating == trueRegisterForSingleUpdate(1)endifEndEvent
User avatar
Andrew Perry
 
Posts: 3505
Joined: Sat Jul 07, 2007 5:40 am

Post » Mon Jun 18, 2012 8:09 pm

You should use RegisterForUpdate() instead of a RegisterForSingleUpdate() chain. Unless there's something wrong with RegisterForUpdate(), then you can disregard this line :tongue:
There's an unmatched endIf in your code as well.

Having a while loop that executes for that long just doesn't seem like a good idea (to me). It's also completely unnecessary; it can be replaced with a single if statement:
if (GameHour.getValue() == 12)  cohRandomSeed.SetValue( Utility.RandomInt( -4 , 4 ) )endIf
User avatar
Guy Pearce
 
Posts: 3499
Joined: Sun May 20, 2007 3:08 pm

Post » Tue Jun 19, 2012 3:07 am

herpaderp. I can't believe I didn't think of that. Complete brain fart.

I was using the RegisterForSingeUpdate chain because, according to the wiki, they prevent multiple instances of a script from running at once.



I probably shouldn't be writing scripts at 3 in the morning. I think, for some reason, I thought that I'd need that architecture later. I actually don't.
User avatar
Your Mum
 
Posts: 3434
Joined: Sun Jun 25, 2006 6:23 pm

Post » Tue Jun 19, 2012 8:19 am

herpaderp. I can't believe I didn't think of that. Complete brain fart.
It happens :tongue:

I was using the RegisterForSingeUpdate chain because, according to the wiki, they prevent multiple instances of a script from running at once.
Hmmm... not sure which is better anymore... With a script this short, I don't think it really makes a difference. Could be wrong, though.
User avatar
CSar L
 
Posts: 3404
Joined: Fri Nov 09, 2007 9:36 pm

Post » Mon Jun 18, 2012 9:33 pm

It might be more useful still if you changed to a RegisterForUpdateGameTime() event instead.
User avatar
Charlie Ramsden
 
Posts: 3434
Joined: Fri Jun 15, 2007 7:53 pm

Post » Mon Jun 18, 2012 11:59 pm

I was under the impression that RegisterForUpdateGameTime() 's name was nonindicative; that it would only update when the player was in playing mode, not waiting mode or menu mode. What I'm looking for is "updates during waiting, sleeping, and game mode, but not MenuMode". It sounded like that was just regular "RegisterForUpdate()", but the wiki is so unclear on some of these things. :dry:
User avatar
Siidney
 
Posts: 3378
Joined: Fri Mar 23, 2007 11:54 pm

Post » Mon Jun 18, 2012 6:48 pm

I don't know about RegisterForUpdateGameTime, but basically if you want your OnUpdate event to run every X seconds then use RegisterForUpdate, and if you want X seconds in between your OnUpdate events, use a RegisterForSingleUpdate chain.

If you can't guarantee that your OnUpdate event will be complete by the time the next one fires, you should probably receive updates less frequently or switch to using a chain. The only harm in using a chain, though, would be if you want your OnUpdate event to fire every X seconds regardless of how long they each take to complete.

Cipscis
User avatar
Nicole M
 
Posts: 3501
Joined: Thu Jun 15, 2006 6:31 am


Return to V - Skyrim