Talk:Dissecting the Scripts for Weapon Racks
Erroneous assertion
It's written: « I'm not going to try and explain states here, but it's redundant and has no utility if you only have a single state in a script. »
Actually, a singleton state can be essential e.g. when monitoring things, while using RegisterForSingleUpdateGameTime for instance. One example which is quite self-explanatory:
Scriptname FactionDetectionScript extends ObjectReference
{Script to be attached to some object in the cell you wish to be monitoring for the player to be a member of some allowed faction}
Actor Property PlayerREF Auto
Bool ShouldWaitForAllowedFaction = True
Event OnLoad()
If ShouldWaitForAllowedFaction
GoToState("WaitForAllowedFaction")
EndIf
EndEvent
State WaitForAllowedFaction
Event OnBeginState()
If PlayerREF.IsInFaction(AllowedFaction)
ShouldWaitForAllowedFaction = False
; Do what you want to do
Else
RegisterForSingleUpdateGameTime(0.9)
EndIf
EndEvent
Event OnUpdateGameTime()
GoToState("WaitForAllowedFaction")
EndEvent
EndState
--HawkFest (talk) 2013-01-29T15:34:42 (EST)
Variables vs. Hidden Literal Properties
A recurring theme that I see in Bethesda scripts is the use of Hidden Properties to represent literal values. This snippet is taken from WeaponRackTriggerSCRIPT.psc:
Bool Property HasBeenTriggered Auto Hidden
Int Property numInTrig Auto Hidden
Bool Property AlreadyInit Auto Hidden
I'm relatively new to Papyrus, but based on my understanding of the language, the fact that these are Hidden means that they're private; inaccessible outside this script. This would seem to make them functionally equivalent to variables:
;Wouldn't this be the same?
bool HasBeenTriggered
int numInTrig
bool AlreadyInit
Is there a reason Properties are used in these instances instead of variables? --Geekofalltrades (talk) 2013-12-15T15:42:35 (EST)