My scripts are turning into a labyrinth of conditions, and I'm getting myself all confused again.
Is there a layman's explanation for when I should use Elseif and when I should use Else If? When I looked online the only explanations seemed to be in pseudo code which really didn't help!
The latest script for my Advanced Shrines mod is being problematic, in that I'm getting lost...I thought I had it all sorted, as it all looks fine to me in Sublime text, but I'm still getting a missing endif on line 107 on compile.
I suspect that it's because I'm using a mixture of Elseifs and Else If, and for any given use I really don't know why I'm using one and not the other...
Scriptname ShrineDonationArkay extends ObjectReference
import debug
Perk Property Merchant Auto
MiscObject Property Gold001 Auto
Spell Property TempleBlessing Auto
Message Property BlessingMessage Auto
Message Property AltarRemoveMsg Auto
Message Property _ShrineDonationZenitharMessage Auto
message property need100Gold auto ;You do not have 100 gold to offer as a donation!
message property need500Gold auto ;You do not have 500 gold to offer as a donation!
Idle Property IdlePray Auto
Actor property PlayerRef auto
import utility
Actor myTarget
Event OnActivate(ObjectReference akActionRef)
if akActionRef == PlayerRef
myTarget = akActionRef as Actor
int MyButton = _ShrineDonationArkayMessage.Show()
if ( MyButton == 0)
;make the player pray - very small chance of being granted blessing
int iRand = RandomInt(1,10)
if iRand > 9
TryBlessing(100)
elseif debug.notification("You pray to Arkay, but he does not respond on this occasion.")
endif
Game.ForceThirdPerson()
PlayerRef.PlayIdle(IdlePray)
Utility.Wait(4.0)
Debug.SendAnimationEvent(PlayerRef, "IdleForceDefaultState")
Game.ForceFirstPerson()
elseIf ( MyButton == 1)
If PlayerRef.GetItemCount(Gold001) < 100
need100Gold.Show()
else
PlayerRef.RemoveItem(Gold001, 100)
int iRand = RandomInt(1,10)
if iRand > 7
TryBlessing(100)
elseif debug.notification("You make your donation, but Arkay does not respond on this occasion.")
endif
endif
elseIf( MyButton == 2)
If PlayerRef.GetItemCount(Gold001) < 500
;make the transaction fail
need500Gold.Show()
Else
PlayerRef.RemoveItem(Gold001, 500)
TryBlessing(500)
endif
elseIf (MyButton == 3)
;do nothing
endif
endif
EndEvent
function TryBlessing(int iDonationAmount)
If PlayerRef.HasPerk(Necromancy)
debug.messagebox("You have travelled too far down the path of Necromancy! Arkay rejects your offering!")
Else
If PlayerRef.HasPerk(Necromancy)
debug.messagebox("You have travelled too far down the path of Necromancy! Arkay rejects your offering!")
Else
If PlayerRef.HasSpell(VampireHuntersSight)
debug.messagebox("You are a vile undead creature of the night! Arkay rejects your offering! Your spirit must return to the grave, or you must return to the world of the living before it is too late!")
Else
If (Game.QueryStat("Undead Killed") > 500)
if iDonationAmount == 100
debug.messagebox("You have returned many undead back to the cycle, which pleases Arkay greatly - he grants a blessing for free!")
PlayerRef.AddItem(Gold001, 100)
ApplyBlessing()
elseif iDonationAmount == 500
debug.messagebox("You have returned many undead back to the cycle, which pleases Arkay greatly - he grants a blessing for free!")
PlayerRef.AddItem(Gold001, 500)
ApplyBlessing()
else
debug.messagebox("You have returned many undead back to the cycle, which pleases Arkay greatly - he grants a blessing for free!")
ApplyBlessing()
endif
Else
If (Game.QueryStat("Undead Killed") > 250)
if iDonationAmount == 100
debug.messagebox("You have killed a number of undead and returned them to the cycle - this is encouraged by Arkay - he grants a blessing for just 50 gold! Continue to return the undead back to the cycle!")
PlayerRef.AddItem(Gold001, 50)
ApplyBlessing()
elseif iDonationAmount == 500
debug.messagebox("You have killed a number of undead and returned them to the cycle - this is encouraged by Arkay - he grants a blessing for just 250 gold! Continue to return the undead back to the cycle!")
PlayerRef.AddItem(Gold001, 250)
ApplyBlessing()
else
debug.messagebox("You have killed a number of undead and returned them to the cycle - this is encouraged by Arkay - on this occasion he grants his blessing for free! Continue to return the undead back to the cycle!")
ApplyBlessing()
endif
Else
ApplyBlessing()
debug.messagebox("You have shown respect for the balance of life and death - Arkay grants his blessing! Arkay wills you to help return those undead spirits back to the cycle, and frowns upon acts of necromancy.")
endif
endFunction
function ApplyBlessing()
Game.ForceThirdPerson()
PlayerRef.PlayIdle(IdlePray)
TempleBlessing.Cast(myTarget, myTarget)
AltarRemoveMsg.Show()
BlessingMessage.Show()
Utility.Wait(4.0)
Debug.SendAnimationEvent(PlayerRef, "IdleForceDefaultState")
Game.ForceFirstPerson()
endFunction