gitsas Posted March 12, 2021 Share Posted March 12, 2021 (edited) For some reason this script runs BOTH If statements?? Scriptname AAAGiveSpells extends activemagiceffect SPELL Property HolyLight Auto BOOL Property HolyLightKnown = False Auto Event OnEffectStart(Actor akTarget, Actor akCaster) Actor Player = Game.GetPlayer() INT PlayerLevel = Player.GetLevel() ;HOLY LIGHT If PlayerLevel >= 1 && HolyLightKnown == false Player.addspell(HolyLight) Debug.Messagebox("Holy Light Added") HolyLightKnown = true EndIf If PlayerLevel >= 1 && HolyLightKnown == true Debug.Messagebox("You already know this spell.") EndIf EndEvent Edited March 12, 2021 by gitsas Link to comment Share on other sites More sharing options...
HeyYou Posted March 12, 2021 Share Posted March 12, 2021 Yep. Because the spell is added in the first loop, so the second loop is always going to be true. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 12, 2021 Share Posted March 12, 2021 Multiple ways to fix this.Examples: Use an ElseIf so that if the first fails it tries the second If PlayerLevel >= 1 && HolyLightKnown == false Player.addspell(HolyLight) Debug.Messagebox("Holy Light Added") HolyLightKnown = true ElseIf PlayerLevel >= 1 && HolyLightKnown == true Debug.Messagebox("You already know this spell.") EndIf Reverse the order so that it checks for a true bool when it should be false - but both conditions will be checked every time thus a small but wasted amount of processing time If PlayerLevel >= 1 && HolyLightKnown == true Debug.Messagebox("You already know this spell.") EndIf If PlayerLevel >= 1 && HolyLightKnown == false Player.addspell(HolyLight) Debug.Messagebox("Holy Light Added") HolyLightKnown = true EndIf Check once for player level, then check the bool and use an Else statement to process one if true and the other if false If PlayerLevel >= 1 If HolyLightKnown == false Player.addspell(HolyLight) Debug.Messagebox("Holy Light Added") HolyLightKnown = true Else Debug.Messagebox("You already know this spell.") EndIf EndIf Link to comment Share on other sites More sharing options...
gitsas Posted March 12, 2021 Author Share Posted March 12, 2021 (edited) Multiple ways to fix this.Examples: Use an ElseIf so that if the first fails it tries the second If PlayerLevel >= 1 && HolyLightKnown == false Player.addspell(HolyLight) Debug.Messagebox("Holy Light Added") HolyLightKnown = true ElseIf PlayerLevel >= 1 && HolyLightKnown == true Debug.Messagebox("You already know this spell.") EndIf Reverse the order so that it checks for a true bool when it should be false - but both conditions will be checked every time thus a small but wasted amount of processing time If PlayerLevel >= 1 && HolyLightKnown == true Debug.Messagebox("You already know this spell.") EndIf If PlayerLevel >= 1 && HolyLightKnown == false Player.addspell(HolyLight) Debug.Messagebox("Holy Light Added") HolyLightKnown = true EndIf Check once for player level, then check the bool and use an Else statement to process one if true and the other if false If PlayerLevel >= 1 If HolyLightKnown == false Player.addspell(HolyLight) Debug.Messagebox("Holy Light Added") HolyLightKnown = true Else Debug.Messagebox("You already know this spell.") EndIf EndIf Thank you so much! it works! I also tried to add an animation: elseif Player.HasSpell(HolyLight) && PlayerLevel >= 1 Game.ForceThirdPerson() Debug.SendAnimationEvent(Player, "IdlePray") Utility.Wait(4.0) Debug.Messagebox("You now know Holy Light.") Everything works great, but the animation never stops.Do you by any chance know how I can stop it? I tried: Debug.SendAnimationEvent(Player, "ActionIdleStop") But it doesn't work. Thanks again for the help!! Edited March 12, 2021 by gitsas Link to comment Share on other sites More sharing options...
gitsas Posted March 12, 2021 Author Share Posted March 12, 2021 Figured it out its: debug.SendAnimationEvent(Player,"IdleForceDefaultState") Link to comment Share on other sites More sharing options...
NexusComa2 Posted March 13, 2021 Share Posted March 13, 2021 (edited) ;------------------------------------ why it didn't work If PlayerLevel >= 1 && HolyLightKnown == false ; they don't have the spell and are over level 0Player.addspell(HolyLight) ; spell added Debug.Messagebox("Holy Light Added") ; added announced HolyLightKnown = true ; flag set to trueEndIf ; at this point in the script they now have the spell and the flag is set to true so the next if statement will fire too If PlayerLevel >= 1 && HolyLightKnown == true ; they do have the spell and are over level 0 Debug.Messagebox("You already know this spell.") ; known announced EndIf ;------------------------------------ fix (one of many ways) If HolyLightKnown == true ;most unlikely checked 1st Debug.Messagebox("You already know this spell.")Elseif PlayerLevel >= 1 ; fix with a double meaning (no need for the &&) elseif statement Player.addspell(HolyLight) Debug.Messagebox("Holy Light Added") HolyLightKnown = trueEndIf I also find the >= level 1 suspect ... is it possible to be a level 0 ? Edited March 13, 2021 by NexusComa2 Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 13, 2021 Share Posted March 13, 2021 I also find the >= level 1 suspect ... is it possible to be a level 0 ? Not possible to be level 0. The player always starts out at level 1. Link to comment Share on other sites More sharing options...
NexusComa2 Posted March 13, 2021 Share Posted March 13, 2021 I didn't think so and would make that part of the script redundant. So ... if HolyLightKnown == true ;most unlikely checked 1st Debug.Messagebox("You already know this spell.")Else ;simple else statement Player.addspell(HolyLight) Debug.Messagebox("Holy Light Added") HolyLightKnown = trueEndIf Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 13, 2021 Share Posted March 13, 2021 Unless they are testing the script to ensure that it behaves properly before adding in the correct level requirement. In which case, the level check would still need to be present. Link to comment Share on other sites More sharing options...
NexusComa2 Posted March 13, 2021 Share Posted March 13, 2021 True. The only real issue was "syntax logic". The "old true/false", if statement logic error in with the syntax. Just looking for a way to slip in how an else statement would be used ...The combinations of: if, else, elseif and endif can be used to ask any question or direct program flow and logic. Well worth the time to really dig into how the combinations can be used (along with, used with flags).I just looked at your [ Spoiler ] ... I see you did cover that ... Link to comment Share on other sites More sharing options...
Recommended Posts