dizietemblesssma Posted February 2 Share Posted February 2 I'm getting myself confused with 'Return' Does the call 'Return' exit out of all nested function or just the one function it is in? In the following: Event OnTriggerEnter(ObjectReference triggerRef) ;this is triggered when entering the trigger box dbg = mcm_script.toggle_debug DEBUG_TRACE(triggerRef As Actor,"undress triggerbox entered") If triggerRef == PlayerRef && dz_player_is_undressed.getValue() == 0 && dz_player_changes() == True ;checks to see if the trigger is the player dz_undress_player() ;if so call the function to undress the player dz_undress_marker.DisableNoWait() DEBUG_TRACE(PlayerRef,"calling player clean function") mcm_script.dz_player_clean_function(PlayerRef) Return EndIf If triggerRef as Actor && !dz_undressed_NPCs.HasForm(triggerRef) && dz_NPC_changes(triggerRef As Actor) == True ;is the trigger an actor (NPC)? dz_undress_NPC(triggerRef as Actor) ;then call the function to undress the NPC DEBUG_TRACE(triggerRef As Actor,"calling NPC clean function") mcm_script.dz_npc_clean_function(triggerRef As Actor) Return EndIf EndEvent does return from the first If/EndIf statement prevent the second from being evaluated? I think perhaps it doesn't and this will explain why the PC is appears to be getting caught by both. diziet Link to comment Share on other sites More sharing options...
IsharaMeradin Posted February 2 Share Posted February 2 My typical usage has been to return values from a custom function for use in a separate function or event. And thus I have always thought that, Return exits the current function or event and goes back to the function or event that originally called upon the function or event using Return. Now if Return only goes back to the previous level, then it could be possible to have both IF statements running. On the other hand, it could be possible that OnTriggerEnter is getting triggered more than once. I think you would benefit from a slight change to the code: Event OnTriggerEnter(ObjectReference triggerRef) ;this is triggered when entering the trigger box dbg = mcm_script.toggle_debug DEBUG_TRACE(triggerRef As Actor,"undress triggerbox entered") If triggerRef == PlayerRef If dz_player_is_undressed.getValue() == 0 && dz_player_changes() == True ;checks to see if the trigger is the player dz_undress_player() ;if so call the function to undress the player dz_undress_marker.DisableNoWait() DEBUG_TRACE(PlayerRef,"calling player clean function") mcm_script.dz_player_clean_function(PlayerRef) Return EndIf ElseIf triggerRef as Actor If !dz_undressed_NPCs.HasForm(triggerRef) && dz_NPC_changes(triggerRef As Actor) == True ;is the trigger an actor (NPC)? dz_undress_NPC(triggerRef as Actor) ;then call the function to undress the NPC DEBUG_TRACE(triggerRef As Actor,"calling NPC clean function") mcm_script.dz_npc_clean_function(triggerRef As Actor) Return EndIf EndIf EndEvent With this change the first block runs only when it is the player and the second block only runs when it is not the player. The way you had it, the player would trigger the second statement because the player character filling the triggerRef parameter would also returns as an actor. Link to comment Share on other sites More sharing options...
dizietemblesssma Posted February 3 Author Share Posted February 3 Thanks I shall try that edit, cheers:) diziet Link to comment Share on other sites More sharing options...
dafydd99 Posted February 4 Share Posted February 4 Generally in high-level programming languages 'return' will exit the current function, with an optional value. 'break' is used in some languages to break out of the current level of (eg) 'if' or 'for loop' or 'while loop' you're in. Papyrus doesn't support 'break'. Link to comment Share on other sites More sharing options...
scorrp10 Posted February 6 Share Posted February 6 In my first-hand experience... Event OnEffectStart(Actor akTarget, Actor akCaster) effectActor = akTarget isPlayer = (effectActor == HLFX.PlayerRef) If !isPlayer If !HLFX.EnabledNPCs RemoveEffect() Return EndIf EndIf ; Register the effect with central formlist If(!HeelsFixTargetList.HasForm(effectActor) && !isPlayer) HeelsFixTargetList.AddForm(effectActor) EndIf If(effectActor.GetRace().IsChildRace()) DebugLog(" is a CHILD, Excluding from fixes") If HLFX.SPIDMode RemoveEffect() EndIf Else isFemale = effectActor.GetLeveledActorBase().GetSex() Float _distance = HLFX.PlayerRef.GetDistance(effectActor) CheckRacemenuHH() DebugLog("Effect Start, isPlayer " + isPlayer + ", isFemale " + isFemale + ", distance " + _distance) CheckHeelsHeight("OnEffectStart") EndIf EndEvent The Return in the first clause fully exits from the function. Link to comment Share on other sites More sharing options...
Recommended Posts