RegisterForUpdate bugged?

Post » Mon Jun 18, 2012 2:41 pm

I'm trying to implement a timer into my script. The script compiles and works fine, but there is no delay when I use the OnUpdate event. Here is the script:

Event OnInit()RegisterForUpdate(5)EndEventEvent OnUpdate()if self.isdisabled() == 0    if utility.randomint() < 20        NewProperty.movetonode(self, myLocationOffset)        CliffracerSound.play(NewProperty)    endifendifEndEvent

Theoretically the script should play a sound effect with a random chance of 20% every 5 seconds (so statistically it should play about every 25 seconds once). But in game the sound effects plays far more often than that. It often plays multiple times in succession without any delay at all. And if the object gets disabled the sound effect keeps playing for a few seconds. I tried to add a RegisterForUpdate line to the last block (in case you need to call it for each update), but that didn't help.

Either I'm doing something wrong or this function is bugged. Ideas?
User avatar
Jacob Phillips
 
Posts: 3430
Joined: Tue Aug 14, 2007 9:46 am

Post » Tue Jun 19, 2012 1:11 am

I tried to use the utility.wait function, but the same happens. I constantly hear the sound effect. Sometimes it stops for a few seconds, then it plays multiple times in succession. What the hell? They say it's much better than timer - getsecondspassed on the Wiki, but apparently it's so incredibly unreliable that it's useless. Any other way to implement a working timer? Or is it my fault and it simply doesn't work like that?
User avatar
neil slattery
 
Posts: 3358
Joined: Wed May 16, 2007 4:57 am

Post » Mon Jun 18, 2012 3:22 pm

This may be a silly question, but what is the script attached to? Is it possible that multiple copies of the script are being run at the same time?
User avatar
jadie kell
 
Posts: 3497
Joined: Sat Jul 29, 2006 3:54 pm

Post » Tue Jun 19, 2012 6:09 am

The way I usually implement this block is:

Event OnInit()RegisterForUpdate(5)gotostate("check")EndEventstate checkEvent OnUpdate()if self.isdisabled() == 0    if utility.randomint() < 20        NewProperty.movetonode(self, myLocationOffset)        CliffracerSound.play(NewProperty)    endifendifEndEventendstate

Not sure if this makes a difference. RegisterForUpdate has seemed pretty reliable for me so far.
User avatar
Nomee
 
Posts: 3382
Joined: Thu May 24, 2007 5:18 pm

Post » Mon Jun 18, 2012 6:41 pm

This may be a silly question, but what is the script attached to? Is it possible that multiple copies of the script are being run at the same time?

It is on my cliffracers, but there are only two of them flying around in my test spot and it definitely plays more often than it should. Sometimes the sound effect plays about 10 times in succession (without any delay or half a second at most), which is should be impossible. I set the update time to 10 and it didn't make a difference either. And of course I always load a save before I applied the script (otherwise changes to the init part wouldn't work).

EDIT: @Chesko: Will try that, thanks!
User avatar
Eve(G)
 
Posts: 3546
Joined: Tue Oct 23, 2007 11:45 am

Post » Mon Jun 18, 2012 6:33 pm

I wonder if the problem is with the function playing the sound? Try putting some debugging comments in there and see if they also display too often.

P.S. we now have proper "bool" functions (yay!), so instead of "== 0" you can do "== false". I hope Papyrus' compiler is good enough to optimise either choice just as well, but the latter is more semantically correct, at least.

Cipscis
User avatar
Charlotte Lloyd-Jones
 
Posts: 3345
Joined: Fri Jun 30, 2006 4:53 pm

Post » Mon Jun 18, 2012 5:22 pm

I wonder if the problem is with the function playing the sound? Try putting some debugging comments in there and see if they also display too often.

P.S. we now have proper "bool" functions (yay!), so instead of "== 0" you can do "== false". I hope Papyrus' compiler is good enough to optimise either choice just as well, but the latter is more semantically correct, at least.

Cipscis

I tried with debug messages, but they show up just as often.

Now I had a weird problem. Suddenly the debug messages showed up while I was in Whiterun (which didn't happen during my previous tests), miles away from the next cliffracer I placed. This leads me to believe that object reference scripts run all the time, no matter where the reference is? And not like in Oblivion where it would only run while it is in the loaded area? Maybe that is my problem. Since they're not even close I have no idea why I can hear the sounds.
User avatar
willow
 
Posts: 3414
Joined: Wed Jul 26, 2006 9:43 pm

Post » Tue Jun 19, 2012 1:45 am

I looked at the Wiki and it says OnUpdate is for a Form script. Maybe that's why it runs all the time for all cliffracer instances in the game world (there are 18, which could explain the huge amount of debug messages popping up, still not sure why I hear the sounds though)?

So what do I use to implement a good old activator gamemode script like in Oblivion? I just want this $%ยง$ script to run every x seconds while the cliffracer reference it is applied to is in the loaded area. And only then.
User avatar
Dustin Brown
 
Posts: 3307
Joined: Sun Sep 30, 2007 6:55 am

Post » Mon Jun 18, 2012 7:39 pm

You could try using a script that uses http://www.creationkit.com/OnInit with a check for http://www.creationkit.com/Is3DLoaded_-_ObjectReference for the cliffracers maybe? Just a thought.
User avatar
FirDaus LOVe farhana
 
Posts: 3369
Joined: Thu Sep 13, 2007 3:42 am

Post » Mon Jun 18, 2012 3:23 pm

Hmm, it's possibly because registering a reference to receive updates causes it to be http://www.creationkit.com/Persistence_(Papyrus)#Registered_events, if you have more flying around that you'd reasonably assumed to not have their scripts running.

Cipscis
User avatar
Euan
 
Posts: 3376
Joined: Mon May 14, 2007 3:34 pm

Post » Mon Jun 18, 2012 2:07 pm

Ok, I think I solved it with this script:

Scriptname PTCliffracerScript extends ObjectReferenceSound Property CliffracerSound AutoString Property myLocationOffset AutoObjectReference Property NewProperty Autofloat randomevent OnCellAttach()	random = utility.randomfloat(10, 30)	RegisterForUpdate(random)endEventevent OnCellDetach()	UnregisterForUpdate()endEventevent OnUpdate()	if self.isdisabled() == false		if self.is3dLoaded() == true			NewProperty.movetonode(self, myLocationOffset)			CliffracerSound.play(NewProperty)                        random = utility.randomfloat(10, 30)			RegisterForUpdate(random)		else		UnregisterForUpdate()		endif	else	UnregisterForUpdate()	endifendEvent

Pretty weird and complicated way to get a simple timer working. Guess that is not one of the advantages of the new scripting language. MoveToNode is great at least.

Thanks for the help! Oh, and if anyone knows an easier way let me know.
User avatar
Astargoth Rockin' Design
 
Posts: 3450
Joined: Mon Apr 02, 2007 2:51 pm

Post » Tue Jun 19, 2012 12:39 am

Wow. I wouldn't have thought to put the update timer itself as the random factor. This gives me a few ideas...
User avatar
Jason Rice
 
Posts: 3445
Joined: Thu Aug 16, 2007 3:42 pm


Return to V - Skyrim