FiftyTifty Posted November 15, 2021 Share Posted November 15, 2021 Quick wee question. Is there a way to check if a property has been filled, or not? Other languages support this, such as Lua, where you can compare it like so: if varToCheck == nil thenBut I can't find any mention on doing that for properties. Specifically, I want to check if a Cell property in my script has been filled, or is the default value set by the CK if it's not been set. In the script, the property is simply: Cell Property cellForMusic Auto Any idea? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted November 15, 2021 Share Posted November 15, 2021 You can check if a property has data assigned to it within an event or function. If myPropertyVar ;has valid data Else ;does not have valid data i.e returns as NONE, NIL or 0 as the property type warrants. EndIfBut to know if a property is filled with a pre-defined value vs a script defined value, not possible without knowing the values ahead of time to compare against the property. This is easily done with integers, floats, bools and strings. But with properties containing form records of some type it gets trickier. In these cases it ends up requiring a second variable (property or local) that contains the original value as the property in question. Link to comment Share on other sites More sharing options...
ReDragon2013 Posted November 15, 2021 Share Posted November 15, 2021 In additional to IsharaMeradins posting a papyrus script sample as follow: Cell PROPERTY cellForMusic auto Cell PROPERTY DefaultcellForMusic auto Hidden EVENT OnInit() IF ( cellForMusic ) DefaultcellForMusic = cellForMusic ; to hold the default value for comparing ENDIF ENDEVENT ;---------------------------- Bool FUNCTION IsDefaultCell() ;---------------------------- IF ( cellForMusic ) RETURN (DefaultcellForMusic == cellForMusic) ; if equal TRUE, else False ENDIF ;--------- Return False ENDFUNCTIONKeep in mind if you do not fill the cell property with CreationKit the default value will be None. Link to comment Share on other sites More sharing options...
Sphered Posted November 17, 2021 Share Posted November 17, 2021 I use Bool checks If WhateverCell as Bool DoThings()EndIf With numbers though Bool will say True if its anything other than 0. If its negative 1 for example that is True as Bool. For these do WhateverDigit != 0 to know if it has any value Link to comment Share on other sites More sharing options...
FiftyTifty Posted November 22, 2021 Author Share Posted November 22, 2021 You can check if a property has data assigned to it within an event or function. If myPropertyVar ;has valid data Else ;does not have valid data i.e returns as NONE, NIL or 0 as the property type warrants. EndIfBut to know if a property is filled with a pre-defined value vs a script defined value, not possible without knowing the values ahead of time to compare against the property. This is easily done with integers, floats, bools and strings. But with properties containing form records of some type it gets trickier. In these cases it ends up requiring a second variable (property or local) that contains the original value as the property in question. Sorry for the late reply. Aye that is perfect. Just need to check if the property has been filled in the CK. If so, do a bunch of code. Hit a roadblock though; my script won't compile if I'm doing a check against a property in the initial state. Here's the script: Scriptname AAAER_Script_MusicHandler extends ReferenceAlias Location Property locationForMusic Auto MusicType Property musictypeAddedMusic Auto Bool Property bOnlyRemoveMusic Auto Bool Property bAddIfInExterior Auto Bool Property bAddIfInInterior Auto Quest Property questToCheck Auto Int[] Property iarrayQuestStages Auto ReferenceAlias Property aliasPlayer Auto Cell cellPlayerIsIn Bool bIsCellInterior Bool bRemove ObjectReference refPlayer Auto State stateInitial if (locationForMusic) GoToState("stateForEvents") else GoToState("stateEmpty") EndIf EndState State stateEmpty EndState State stateForEvents Event OnLocationChange(Location locationPlayerLeft, Location locationPlayerEntered) ;Do stuff endEvent EndState The compiler says: (32,1): mismatched input 'if' expecting ENDSTATE Any idea why that is? I can't figure it out In additional to IsharaMeradins posting a papyrus script sample as follow: Cell PROPERTY cellForMusic auto Cell PROPERTY DefaultcellForMusic auto Hidden EVENT OnInit() IF ( cellForMusic ) DefaultcellForMusic = cellForMusic ; to hold the default value for comparing ENDIF ENDEVENT ;---------------------------- Bool FUNCTION IsDefaultCell() ;---------------------------- IF ( cellForMusic ) RETURN (DefaultcellForMusic == cellForMusic) ; if equal TRUE, else False ENDIF ;--------- Return False ENDFUNCTIONKeep in mind if you do not fill the cell property with CreationKit the default value will be None. Ooh. So a property defining a record returns "None". That's good. So I'd just check "if cellForMusic == None" ? I use Bool checks If WhateverCell as Bool DoThings()EndIf With numbers though Bool will say True if its anything other than 0. If its negative 1 for example that is True as Bool. For these do WhateverDigit != 0 to know if it has any value The problem with bool checks is that they're redundant, if all they are is just a meta variable, as we can compare against the actual variables themselves. Less work, less code, less mess. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted November 22, 2021 Share Posted November 22, 2021 States cannot be treated like events. You still need to define events inside of the states before running any other code. Change: Auto State stateInitial if (locationForMusic) GoToState("stateForEvents") else GoToState("stateEmpty") EndIf EndState into: Auto State stateInitial Event OnBeginState() if (locationForMusic) GoToState("stateForEvents") else GoToState("stateEmpty") EndIf EndEvent EndState Link to comment Share on other sites More sharing options...
FiftyTifty Posted November 22, 2021 Author Share Posted November 22, 2021 States cannot be treated like events. You still need to define events inside of the states before running any other code. Change: Auto State stateInitial if (locationForMusic) GoToState("stateForEvents") else GoToState("stateEmpty") EndIf EndState into: Auto State stateInitial Event OnBeginState() if (locationForMusic) GoToState("stateForEvents") else GoToState("stateEmpty") EndIf EndEvent EndState See, I read that the OnBeginState event doesn't fire for auto states. Is that just simply outdated/wrong info? Link to comment Share on other sites More sharing options...
ReDragon2013 Posted November 23, 2021 Share Posted November 23, 2021 (edited) Next should work.. you are free in decision to take a script name, but imho a better name would be AAAER_MusicHandlerAliasScript. AAAER_Script_MusicHandler Scriptname AAAER_Script_MusicHandler extends ReferenceAlias ; https://forums.nexusmods.com/index.php?/topic/10724293-papyrus-check-if-property-is-filled-or-empty/ Quest PROPERTY questToCheck auto Int[] PROPERTY iarrayQuestStages auto Location PROPERTY locationForMusic auto MusicType PROPERTY musictypeAddedMusic auto Bool PROPERTY bOnlyRemoveMusic auto Bool PROPERTY bAddIfInExterior auto Bool PROPERTY bAddIfInInterior auto Cell cellPlayerIsIn Bool bIsCellInterior Bool bRemove ;ReferenceAlias Property aliasPlayer Auto ;ObjectReference refPlayer ; -- EVENTs -- EVENT OnInit() ; -- ver A -- IF ( locationForMusic ) ; IF (locationForMusic != None) gotoState("Action") ; ### STATE ### ELSE gotoState("Waiting") ; ### STATE ### ENDIF ;----------------------------------- ; -- ver B -- ; IF ( !locationForMusic ) ; IF (locationForMusic == None) ; gogoState("Waiting") ; ### STATE ### ; ELSE ; gotoState("Action") ; ### STATE ### ; ENDIF ENDEVENT ;=============================== State Waiting ;============ endState ;=============================== State Action ;=========== EVENT OnCellLoad() ; *** in case this script runs on a playerAlias *** cell c = self.GetReference().GetParentCell() Debug.Trace("Player enters " + c) ENDEVENT EVENT OnLocationChange(Location akOldLoc, Location akNewLoc) ; https://www.creationkit.com/index.php?title=OnLocationChange_-_Actor gotoState("Waiting") ; ### STATE ### make sure following script code will not be interrupted/overlapped by another location event thread ;Do stuff gotoState("Action") ; ### STATE ### now let this event trigger again ENDEVENT ;======= endState Edited November 23, 2021 by ReDragon2013 Link to comment Share on other sites More sharing options...
IsharaMeradin Posted November 23, 2021 Share Posted November 23, 2021 (edited) <snip>See, I read that the OnBeginState event doesn't fire for auto states. Is that just simply outdated/wrong info? I, honestly, do not know about that. Edited November 23, 2021 by IsharaMeradin Link to comment Share on other sites More sharing options...
Recommended Posts