HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Wc3 error on my spell

04-12-2006, 01:19 PM#1
The)TideHunter(
Ok, iv made a simple spell, switches unit hp, and makes 2 effects from 1 to the other, i keep getting a fatal error when saving.. any sugggestions?
thx in advance

Collapse JASS:
function IsUnitMagicImmune takes unit who returns boolean
    return IsUnitType(who, UNIT_TYPE_MAGIC_IMMUNE)
endfunction

function IsUnitDead takes unit who returns boolean
    return IsUnitDeadBJ(who)
endfunction

function SetUnitHp takes unit who, real amount returns nothing
    call SetUnitLifeBJ(who, amount)
endfunction

function SwapHPValue takes unit uUnit, unit uUnit2, real MinHP, boolean MagicImmunity returns nothing
    local real uUnitHP = GetUnitStateSwap(UNIT_STATE_LIFE, uUnit)
    local real uUnit2HP = GetUnitStateSwap(UNIT_STATE_LIFE, uUnit2)
    if(MagicImmunity == false) and (IsUnitMagicImmune(uUnit) == false) then
        call SetUnitHp(uUnit, uUnit2HP)
        if(GetUnitStateSwap(UNIT_STATE_LIFE, uUnit) < MinHP) then
            call SetUnitHp(uUnit, MinHP)
        endif
    endif
    if(MagicImmunity == false) and (IsUnitMagicImmune(uUnit2) == false) then
        call SetUnitHp(uUnit2, uUnitHP)
        if(GetUnitStateSwap(UNIT_STATE_LIFE, uUnit2) < MinHP) then
            call SetUnitHp(uUnit2, MinHP)
        endif
    endif
endfunction

function Spell_SoulSwap takes unit uUnit, unit uUnit2, real MinHP, boolean MagicImmunity returns nothing
    local real DistanceBetweenTargets = DistanceBetweenPoints(GetUnitLoc(uUnit), GetUnitLoc(uUnit2))
    local real ProjectileTime = 2.00
    local real ProjectileSpeed = DistanceBetweenTargets / ProjectileTime
    local unit Projectile1
    local unit Projectile2
    call CreateNUnitsAtLocFacingLocBJ(1, 'h000', GetOwningPlayer(uUnit), GetUnitLoc(uUnit), GetUnitLoc(uUnit2))
    set Projectile1 = GetLastCreatedUnit()
    call CreateNUnitsAtLocFacingLocBJ(1, 'h000', GetOwningPlayer(uUnit2), GetUnitLoc(uUnit2), GetUnitLoc(uUnit))
    set Projectile2 = GetLastCreatedUnit()
    call SetUnitMoveSpeed(Projectile1, ProjectileSpeed)
    call SetUnitMoveSpeed(Projectile2, ProjectileSpeed)
    call IssuePointOrderLocBJ(Projectile1, "move", GetUnitLoc(uUnit2))
    call IssuePointOrderLocBJ(Projectile2, "move", GetUnitLoc(uUnit))
    call UnitApplyTimedLifeBJ(ProjectileTime * 5.00 + 1.00, 'BTLF', Projectile1)
    call UnitApplyTimedLifeBJ(ProjectileTime * 5.00 + 1.00, 'BTLF', Projectile2)
    loop
        exitwhen (DistanceBetweenPoints(GetUnitLoc(Projectile1), GetUnitLoc(uUnit2)) <= 25.00) or (DistanceBetweenPoints(GetUnitLoc(Projectile2), GetUnitLoc(uUnit)) <= 25.00) or (IsUnitDead(Projectile1) == true) or (IsUnitDead(Projectile2) == true)
        call IssuePointOrderLocBJ(Projectile1, "move", GetUnitLoc(uUnit2))
        call IssuePointOrderLocBJ(Projectile2, "move", GetUnitLoc(uUnit))
        call TriggerSleepAction(0.25)
    endloop
    call SwapHPValue(uUnit, uUnit2, MinHP, MagicImmunity
endfuncion

The spell has a minium hp value, if a unit is under this value, it should set to the minium.
Anyway... i dunno whats going wrong cause of the crashs.
-Tidey

EDIT: i just noticed on my distance between points, i dident but GetUnitLoc... il change that and see if it works
04-12-2006, 01:51 PM#2
vile
Huh? Where is your Init_Trig ?
Collapse JASS:
if(MagicImmunity == false)

MagicImmunity isnt a boolean and neither a function, its not even declared as far as i can see, this can cause a crash. Even if it is set up somewhere, you have to use either MagicImmunity() if it returns a boolean, or MagicImmunity(arguments) if it takes any.

You are also leaking heaps of locations and other things.
Why are you using jass for this if you don't know about leaks?
You're also using useless BJ functions, which is another reason why I think you should just use GUI. Otherwise I suggest taking tutorials about jass and then optimizing your script up.
04-12-2006, 02:24 PM#3
The)TideHunter(
1) MagicImmunity is passed into the function
Collapse JASS:
function SwapHPValue takes unit uUnit, unit uUnit2, real MinHP, boolean MagicImmunity returns nothing

2) Yea, i know there are loads of leaks, im not bothered about memory usage just yet, im more bothered about it working.
3) I do know about leaks
4) Im quite familair with JASS, im not using GUI cause the only reason im making this spell is to become more experienced with JASS

Sorry if this post seems abit harsh
04-12-2006, 02:36 PM#4
vile
I still cant see where your Init_Trig is. You have to have an Initialization trigger for each trigger.

Sorry about MagicImmunity, I didn't notice you are using arguments there, I presumed it takes nothing and returns nothing.

Post your Init_trig, if you dont have one, it will crash.
04-12-2006, 02:51 PM#5
The)TideHunter(
It has no Init_Trig ... its not in a trigger.
Its a simple set of bare functions that are declared before Map Init
Functions dont require a Init_Trig unless you are refering to a trigger
04-12-2006, 03:21 PM#6
vile
well, it would've saved a few posts if you would have mentioned that.

Found your error
Quote:
call SwapHPValue(uUnit, uUnit2, MinHP, MagicImmunity
endfuncion

You are missing a ) after magicimmunity
and change endfuncion to endfunction

Tip:
If you want to find out why your script is crashing, put a // before each line and slowly start saving and removing the //, until you find out the cause of the crash.
04-12-2006, 03:50 PM#7
The)TideHunter(
Cheers dude.
Works fine now without any errors, now il optimize it abit and remove the leaks.
Thx again :))