Help with first JASS function - Updated
Hey, I finally took the time to write a JASS function, I have some errors that are making me go :banghead: though, hopefully someone can help me out.
The aim of the function is to have a unit purchase an item to learn a skill (such as tome of critical strike in this case) and here's, code:
One error: "Syntax error" on this line:
Any more pointers?
Hey, I finally took the time to write a JASS function, I have some errors that are making me go :banghead: though, hopefully someone can help me out.
The aim of the function is to have a unit purchase an item to learn a skill (such as tome of critical strike in this case) and here's, code:
JASS:
scope CriticalStrike initializer Init
globals
private constant integer itemID = 039;I002039; //item ID
private constant integer abilID = 039;AOcr039; //ability ID
private constant integer cost = 0 //return cost if error in purchase
private constant integer abilmaxlv = 3 //max ability level
//private constant real abilmaxc = 7 //max number of abilitys per unit -- unused atm
endglobals
private function True takes nothing returns boolean
return true
endfunction
private function Cons takes nothing returns boolean
return GetItemTypeId(GetManipulatedItem()) == itemID
endfunction
private function Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local player p = GetOwningPlayer(u)
local integer l = GetUnitAbilityLevel(u, abilID)
if (l == abilmaxlv ) then
call SetPlayerStateBJ( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, ( GetPlayerState(GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD) + cost ) )
else
if l < abilmaxlv
call SetUnitAbilityLevel(u, abilID, GetUnitAbilityLevel(u)+1)
else
UnitAddAbility(u, abilID)
endif
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
loop
exitwhen i > 15
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_ATTACKED, Filter(function True))
set i = i + 1
endloop
call TriggerAddCondition(t, Filter(function Cons))
call TriggerAddAction(t, function Actions)
endfunction
endscope
One error: "Syntax error" on this line:
JASS:
if l < abilmaxlv
Any more pointers?