Jump to content

[LE] If in if in if?


TangerineDog

Recommended Posts

In one of my scripts, I put a conditional statement inside another conditional statement. No problems there.

 

But in this scirpt, there's an if in an if in an if and it won't compile.

When I reduce the ifs to one conditional statement within another, it works, but adding a third one breaks the script every time.

 

Why?

 

 

ScriptName HungerChangeScript extends activemagiceffect

GlobalVariable Property HungerCount Auto
GlobalVariable Property HungerCount1 Auto
GlobalVariable Property HungerCount2 Auto
GlobalVariable Property HungerCount3 Auto
Spell Property SpellHunger01 Auto
Spell Property SpellHunger02 Auto
Spell Property SpellHunger03 Auto
int Property HungerCountMod Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)

If akTarget == Game.GetPlayer()
HungerCount.Mod(HungerCountMod)
if HungerCount.GetValue() < HungerCount1.GetValue()
If (Game.GetPlayer().HasMagicEffect(SpellHunger03))
Game.GetPlayer().RemoveSpell(SpellHunger03)
endif
If (Game.GetPlayer().HasMagicEffect(SpellHunger02))
Game.GetPlayer().RemoveSpell(SpellHunger02)
endif
If (Game.GetPlayer().HasMagicEffect(SpellHunger01))
Game.GetPlayer().RemoveSpell(SpellHunger01)
Debug.Notification("No more Hunger")
endif
elseif HungerCount.GetValue() < HungerCount2.GetValue()
if HungerCount.GetValue() >= HungerCount1.GetValue()
If (Game.GetPlayer().HasMagicEffect(SpellHunger03))
Game.GetPlayer().RemoveSpell(SpellHunger03)
endif
If (Game.GetPlayer().HasMagicEffect(SpellHunger02))
Game.GetPlayer().RemoveSpell(SpellHunger02)
endif
If (Game.GetPlayer().HasMagicEffect(SpellHunger01))
Debug.Notification("Placeholder")
Else
Game.GetPlayer().AddSpell(SpellHunger01)
endif
endif
endif
endif

EndEvent

 

Link to comment
Share on other sites

Too many IF conditions doesn't make sense. I've gone at least 5 deep without issue.

 

Also, your IF vs EndIF are correct. I copy/pasted to SublimeText where it shows lines when you indent and was able to line up each EndIf with an associating IF.

 

Why not post the actual compiler error alongside the code you are attempting to compile?

Link to comment
Share on other sites

This is the full error text, the script is still the same.

 

E:\SteamLibrary\steamapps\common\Skyrim\Data\scripts\Source>"E:\SteamLibrary\steamapps\common\Skyrim\Papyrus Compiler\PapyrusCompiler" E:\SteamLibrary\steamapps\common\Skyrim\Data\scripts\Source\HungerChangeScript.psc -f="TESV_Papyrus_Flags.flg" -i="E:\SteamLibrary\steamapps\common\Skyrim\Data\Scripts\Source" -o="E:\SteamLibrary\steamapps\common\Skyrim\Data\Scripts"
Starting 1 compile threads for 1 files...
Compiling "HungerChangeScript"...
E:\SteamLibrary\steamapps\common\Skyrim\Data\scripts\Source\HungerChangeScript.psc(17,25): type mismatch on parameter 1 (did you forget a cast?)
E:\SteamLibrary\steamapps\common\Skyrim\Data\scripts\Source\HungerChangeScript.psc(20,25): type mismatch on parameter 1 (did you forget a cast?)
E:\SteamLibrary\steamapps\common\Skyrim\Data\scripts\Source\HungerChangeScript.psc(23,25): type mismatch on parameter 1 (did you forget a cast?)
E:\SteamLibrary\steamapps\common\Skyrim\Data\scripts\Source\HungerChangeScript.psc(29,26): type mismatch on parameter 1 (did you forget a cast?)
E:\SteamLibrary\steamapps\common\Skyrim\Data\scripts\Source\HungerChangeScript.psc(32,26): type mismatch on parameter 1 (did you forget a cast?)
E:\SteamLibrary\steamapps\common\Skyrim\Data\scripts\Source\HungerChangeScript.psc(35,26): type mismatch on parameter 1 (did you forget a cast?)
No output generated for E:\SteamLibrary\steamapps\common\Skyrim\Data\scripts\Source\HungerChangeScript.psc, compilation failed.

Batch compile of 1 files finished. 0 succeeded, 1 failed.
Failed on E:\SteamLibrary\steamapps\common\Skyrim\Data\scripts\Source\HungerChangeScript.psc

E:\SteamLibrary\steamapps\common\Skyrim\Data\scripts\Source>pause

 

Link to comment
Share on other sites

Line 17: If (Game.GetPlayer().HasMagicEffect(SpellHunger03))

 

You are checking to see if the player has a magic effect but you are using a spell. You need to add properties for the actual effects you need to be checking for and change these statements to look for said effects rather than spells

Link to comment
Share on other sites

  • Recently Browsing   0 members

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