• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Newbie JASS Question

Status
Not open for further replies.
Level 4
Joined
Aug 1, 2007
Messages
66
I'm trying to learn jass. I've converted my triggers to script and am going through changing things. I'm up to my ability triggers and am trying to switch from globals to locals. I haven't been able to figure out what's causing errors on this script:

JASS:
function Trig_Transfusion_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A0L1' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Transfusion_Actions takes nothing returns nothing
    local unit caster = GetSpellAbilityUnit()
    local unit target = GetSpellTargetUnit()
    local integer level = GetUnitAbilityLevel(caster,'A0L1')()
    local real damage
    local real array percentage
    set percentage[1] = 0.05
    set percentage[2] = 0.06
    set percentage[3] = 0.08
    set percentage[4] = 0.10
    set percentage[5] = 0.12
    set percentage[6] = 0.15
    set percentage[7] = 0.19
    set percentage[8] = 0.24
    set percentage[9] = 0.30
    set percentage[10] = 0.37
    set damage = ( GetUnitStateSwap(UNIT_STATE_LIFE, target) * percentage[level] )
    call SetUnitLifeBJ( caster, ( GetUnitStateSwap(UNIT_STATE_LIFE, caster) + damage ) )
    call UnitDamageTargetBJ( caster, target, damage, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
endfunction

//===========================================================================
function InitTrig_Transfusion takes nothing returns nothing
    set gg_trg_Transfusion = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Transfusion, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Transfusion, Condition( function Trig_Transfusion_Conditions ) )
    call TriggerAddAction( gg_trg_Transfusion, function Trig_Transfusion_Actions )
endfunction

Here's the errors I'm getting:

Syntax error on the local unit target line
Undeclared variable on the set percentage[1] line
Percentage not an array on all the set percentage lines
Undeclared variable on the set damage line

This spell was created by Nightsong and credit is given.

Thanks alot for any help.
 
Level 15
Joined
Feb 15, 2006
Messages
851
Improved the code a little bit:

JASS:
function Trig_Transfusion_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A0L1'
endfunction

function Trig_Transfusion_Actions takes nothing returns nothing
    local unit caster = GetSpellAbilityUnit()
    local unit target = GetSpellTargetUnit()
    local integer level = GetUnitAbilityLevel(caster,'A0L1')
    local real damage
    local real array percentage
    set percentage[1] = 0.05
    set percentage[2] = 0.06
    set percentage[3] = 0.08
    set percentage[4] = 0.10
    set percentage[5] = 0.12
    set percentage[6] = 0.15
    set percentage[7] = 0.19
    set percentage[8] = 0.24
    set percentage[9] = 0.30
    set percentage[10] = 0.37
    set damage = ( GetWidgetLife(target) * percentage[level] )
    call SetWidgetLife( caster, ( GetWidgetLife(caster) + damage ) )
    call UnitDamageTarget( caster, target, damage, true, true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
    set caster = null
    set target = null
endfunction

//===========================================================================
function InitTrig_Transfusion takes nothing returns nothing
    set gg_trg_Transfusion = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Transfusion, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Transfusion, Condition( function Trig_Transfusion_Conditions ) )
    call TriggerAddAction( gg_trg_Transfusion, function Trig_Transfusion_Actions )
endfunction
 
Status
Not open for further replies.
Top