This Toggle isn't working

Post » Wed Jun 20, 2012 10:09 pm

My script is supposed to prevent spamming of Play(), but in game it still spams (which is bad because Playing an effect shader stacks, causes frame rate drops).

Scriptname TestingLoop Extends ObjectReferenceVisualEffect Property Derp  Auto  EffectShader Property Derpette  Auto  Event OnInit()	 RegisterForSingleUpdate(0.1)EndEventEvent OnUpdate()Int Toggle = 0If Game.GetPlayer().IsGhost() == True && Toggle == 0	 Derpette.Play(Game.GetPlayer())	 Toggle = 1EndifIf Game.GetPlayer().IsGhost() == False && Toggle == 1	 Derpette.Stop(Game.GetPlayer())	 Toggle = 0EndIfRegisterForSingleUpdate(0.1)EndEvent

Any help?

[Edit] Oh wait, I know why. The OnUpdate() block keeps turning Toggle to 0. Here's the fixed script:

Scriptname TestingLoop Extends ObjectReferenceVisualEffect Property Derp  Auto  EffectShader Property Derpette  Auto  Int Toggle = 0Event OnInit()	 RegisterForSingleUpdate(0.1)EndEventEvent OnUpdate()If Game.GetPlayer().IsGhost() == True && Toggle == 0	 Derpette.Play(Game.GetPlayer())	 Toggle = 1EndifIf Game.GetPlayer().IsGhost() == False && Toggle == 1	 Derpette.Stop(Game.GetPlayer())	 Toggle = 0EndIfRegisterForSingleUpdate(0.1)EndEvent
User avatar
Jenna Fields
 
Posts: 3396
Joined: Mon Dec 11, 2006 11:36 am

Post » Thu Jun 21, 2012 6:19 am

Try:
ScriptName TestingLoop Extends ObjectReferenceActor Property PlayerREF AutoVisualEffect Property Derp AutoEffectShader Property Derpette AutoBool bToggleEvent OnInit()	RegisterForSingleUpdate(0.1)EndEventEvent OnUpdate()	If bToggle != PlayerREF.IsGhost()		bToggle = !bToggle		If bToggle			Derpette.Play(PlayerREF)		Else			Derpette.Stop(PlayerREF)		EndIf	Endif	RegisterForSingleUpdate(0.1)EndEvent
It'll be 'cheaper' as there's only one 'If' every iteration and 'cause a PlayerREF property is less expensive than using a function, particularly if at such tight intervals.
User avatar
Hope Greenhaw
 
Posts: 3368
Joined: Fri Aug 17, 2007 8:44 pm

Post » Wed Jun 20, 2012 8:13 pm

It'll be 'cheaper' as there's only one 'If' every iteration and 'cause a PlayerREF property is less expensive than using a function, particularly if at such tight intervals.

I always thought properties slowed down the script, and that functions were faster?
User avatar
Javaun Thompson
 
Posts: 3397
Joined: Fri Sep 21, 2007 10:28 am

Post » Wed Jun 20, 2012 6:07 pm

I recall Pap's pop, SmkViper, stating otherwise. *digs up post*

http://www.gamesas.com/topic/1352280-most-efficient-way-of-referencing-the-player/page__view__findpost__p__20378748
User avatar
Aliish Sheldonn
 
Posts: 3487
Joined: Fri Feb 16, 2007 3:19 am

Post » Wed Jun 20, 2012 6:56 pm

I recall Pap's pop, SmkViper, stating otherwise. *digs up post*

http://www.gamesas.com/topic/1352280-most-efficient-way-of-referencing-the-player/page__view__findpost__p__20378748

Alright thanks.
User avatar
Stacyia
 
Posts: 3361
Joined: Mon Jul 24, 2006 12:48 am


Return to V - Skyrim