TryToClear - ReferenceAlias

From the CreationKit Wiki
Jump to navigation Jump to search

Member of: ReferenceAlias Script

Clears this alias and returns whether anything was in it to begin with.

Syntax[edit | edit source]

bool Function TryToClear()
	if (GetReference())
		Clear()
		return True
	endif
	return False
EndFunction

Return Value[edit | edit source]

Whether the alias had a reference in it when it was cleared or not.

  • True - Alias has valid reference, Clear() function called on it
  • False - Nothing to clear from the alias

Examples[edit | edit source]

; Clear the alias
if OptionalAlias.Clear()
  Debug.Trace("Removed something from the alias")
else
  Debug.Trace("Didn't remove anything from the alias (already empty)")
endIf

Notes:[edit | edit source]

(AliasTryFunctions == TRUE) is NOT an accurate reflection of (AliasRef == HasExpectedResults) OR (Alias == HasNewOrNoValue)

  • It IS a reflection that the alias met the criteria to have the functions called upon them
  • Many, if not most of these functions are external dispatch to other scripts and do not wait for expected results
  • True means alias had valid reference, and is queued to run your desired function on it, or POSSIBLY already has
  • False means the alias does not have a reference, or does not have a reference of the appropriate type
  • Try functions do NOT return false if the function called(AddToFaction(), Clear() Etc) go on to fail for any reason
  • does NOT return false if Clear() fails due to non-optional alias

See Also[edit | edit source]