Jump to content

[LE] Script IF Statement help


gitsas

Recommended Posts

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 by gitsas
Link to comment
Share on other sites

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

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 by gitsas
Link to comment
Share on other sites

;------------------------------------ why it didn't work
If PlayerLevel >= 1 && HolyLightKnown == false ; they don't have the spell and are over level 0
Player.addspell(HolyLight) ; spell added
Debug.Messagebox("Holy Light Added") ; added announced
HolyLightKnown = true ; flag set to true
EndIf
; 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 = true
EndIf
I also find the >= level 1 suspect ... is it possible to be a level 0 ?
Edited by NexusComa2
Link to comment
Share on other sites

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 = true
EndIf
Link to comment
Share on other sites

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...