• 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.

[vJASS] why does it compile an error?

Status
Not open for further replies.

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
hi all,

i have a problem with: GetSpellAbilityId()

[Jass=]
library System initializer Init

globals
private unit hero
private player owner
private integer marker
private ability abi
private integer spell
endglobals

function Check takes nothing returns boolean // Check if casted ability is a recipe crafting ability
local integer i = 0
loop
if ( abi == LoadIntegerBJ(0, i, udg_recipe) ) then
set marker = i
return true
endif
exitwhen i == udg_itemCounter
set i = i + 1
endloop
return false
endfunction

private function Actions takes nothing returns nothing
set ability abi = GetSpellAbilityId()
set integer spell = GetSpellAbilityId()
set unit hero = GetTriggerUnit()
set player owner = GetOwningPlayer(hero)
set integer marker = 0
if ( not ( Check() ) ) then
set hero = null
set owner = null
set ti = null
return
else
call DisplayTextToPlayer(owner, 0.,0., ( "|c0000c400Troll:|r |c00ffff64Me haz crafted " + LoadStringBJ(11, marker, udg_recipe) ) )
endif
endfunction

//===========================================================================
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerAddAction( t, function Actions )
endfunction

endlibrary[/code]

it display: syntax error, unexpected: System__abi ?
if i remove abi, then it display exactly the same message for spell
it also does it for owner and hero....
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Just because you use local variables but don't declare them before :

JASS:
set ability abi = GetSpellAbilityId()    
        set integer spell = GetSpellAbilityId()
        set unit hero = GetTriggerUnit()          
        set player owner = GetOwningPlayer(hero) 
        set integer marker = 0

->

JASS:
        local integer spell = GetSpellAbilityId()
        local unit hero = GetTriggerUnit()          
        local player owner = GetOwningPlayer(hero) 
        local integer marker = 0

Also, the "ability" type is useless as far i know, and GetSpellAbilityId returns an integer, the rawcode of the spell.
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
then what the use of the globals if i have to declare these as local?
owner, marker, etc... are in the globals of the library.....
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
you dont need the "player, integer, unit," etc.

just

set yourVar = #

also, the "ability" variable type is worthless, do not use it.

GetSpellAbilityId() returns an integer anyway
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Thanks Arhowk and Radamantus

i have redone my trigger and didn't use the library...

i just noticed after you tell me my mistake....
i am so stupid, i wrote set integer spell instead of set spell, i had so much problem thinking about that trigger that i made udg_variable and local instead of use the globals :p
jass is really tricky about small detail....

right now my trigger work fine, it is a bit basic and not greatly coded....
but it don't crash the game and actually work... maybe i will try to improve it with some help.
i had to cut it into 3 pieces and use normal trigger call (GUI)
[Jass=]
function RS_Setup takes nothing returns nothing
// Firecamp
set udg_craftAbi = 'A05R'
set udg_craftItemCreate = 'wlsd'
set udg_craftCreateCharge = 1
set udg_craftNeedTotal = 3
set udg_craftItemNeed1 = 'hval'
set udg_craftItemNeed2 = 'clsd'
set udg_craftItemNeed3 = 'bgst'
set udg_craftItemNeed4 = 0
set udg_craftItemNeed5 = 0
set udg_craftItemNeed6 = 0
set udg_craftNeedCharges = 111000
set udg_craftName = "Firecamp !"
set udg_craftText = "|c0000c400Troll:|r |c00ffff64Me Needz 1 stone, 1 tinder and 1 flint... "
call TriggerExecute( gg_trg_RegisterRecipe )
// ???????
set udg_craftAbi = 'ZZZZ'
set udg_craftItemCreate = 'I000'
set udg_craftCreateCharge = 1
set udg_craftNeedTotal = 0
set udg_craftItemNeed1 = 0
set udg_craftItemNeed2 = 0
set udg_craftItemNeed3 = 0
set udg_craftItemNeed4 = 0
set udg_craftItemNeed5 = 0
set udg_craftItemNeed6 = 0
set udg_craftNeedCharges = 000000
set udg_craftName = "Not yet done !"
set udg_craftText = "|c0000c400Troll:|r |c00ffff64Me Needz ???... "
call TriggerExecute( gg_trg_RegisterRecipe )
endfunction

//===========================================================================
function InitTrig_RecipeSetup takes nothing returns nothing
set gg_trg_RecipeSetup = CreateTrigger( )
call TriggerRegisterTimerEventSingle( gg_trg_RecipeSetup, 0.00 )
call TriggerAddAction( gg_trg_RecipeSetup, function RS_Setup )
endfunction[/code]

[Jass=]
function RR_Register takes nothing returns nothing
call SaveIntegerBJ( udg_craftAbi, 0, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( udg_craftItemCreate, 1, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( udg_craftCreateCharge, 2, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( udg_craftNeedTotal, 3, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( udg_craftItemNeed1, 4, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( udg_craftItemNeed2, 5, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( udg_craftItemNeed3, 6, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( udg_craftItemNeed4, 7, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( udg_craftItemNeed5, 8, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( udg_craftItemNeed6, 9, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( udg_craftNeedCharges, 10, udg_itemCounter, udg_recipe )
call SaveStringBJ( udg_craftName, 11, udg_itemCounter, udg_recipe )
call SaveStringBJ( udg_craftText, 12, udg_itemCounter, udg_recipe )
set udg_itemCounter = udg_itemCounter + 1
endfunction

//===========================================================================
function InitTrig_RegisterRecipe takes nothing returns nothing
set gg_trg_RegisterRecipe = CreateTrigger( )
call TriggerAddAction( gg_trg_RegisterRecipe, function RR_Register )
endfunction[/code]

[Jass=]
function RS_check takes integer udg_spell, integer udg_marker returns boolean // Check if casted ability is a recipe crafting ability
local integer i = 0
loop
if ( udg_spell == LoadIntegerBJ(0, i, udg_recipe) ) then
set udg_marker = i
return true
endif
exitwhen i == udg_itemCounter
set i = i + 1
endloop
return false
endfunction

function RS_recipe takes nothing returns nothing
local integer array id // itemtype id of item carried by unit in slot (i)
local integer array ic // charge of item carried by unit in slot (i)
local integer array n // pool all charge from matching needed item (1-2-3-4-5-6)
local integer array md // decompress and store the charge needed for recipe from item (1-2-3-4-5-6)
local integer i
local integer j
local item ti // item carried by unit in slot (i)
local unit hero = GetTriggerUnit() // unit that is casting ability
local player owner = GetOwningPlayer(hero) // owner of the casting unit
local integer size = UnitInventorySizeBJ(hero) // size of inventory of the casting unit
set udg_spell = GetSpellAbilityId() // store ability to compare if it is a recipe crafting ability
set udg_marker = 0 // tracker that point to the current recipe based on ability casted
if ( not ( RS_check(udg_spell, udg_marker) ) ) then
set hero = null
set owner = null
set ti = null
return
else
set i = 1
loop
exitwhen i > size // Check every item in inventory to match item needed in recipe
set ti = UnitItemInSlotBJ(hero, i)
set id = GetItemTypeId(ti)
set ic = GetItemCharges(ti)
set j = 1
loop
exitwhen j > LoadIntegerBJ(3, udg_marker, udg_recipe)
if ( id == LoadIntegerBJ(j+3, udg_marker, udg_recipe) ) and ( ti != null ) then
set n[j] = ( n[j] + ic )
call RemoveItem( UnitItemInSlotBJ(hero, i) ) // remove matching item and pool the charge
endif
set j = j + 1
endloop
set ti = null
set i = i + 1
endloop
set md[0] = LoadIntegerBJ(10, udg_marker, udg_recipe) // Charge of item 1-2-3-4-5-6
set md[6] = ModuloInteger(md[0], 10) // Charge of item 6
set md[0] = ( ( md[0] - md[6] ) / 10 )
set md[5] = ModuloInteger(md[0], 10) // Charge of item 5
set md[0] = ( ( md[0] - md[5] ) / 10 )
set md[4] = ModuloInteger(md[0], 10) // Charge of item 4
set md[0] = ( ( md[0] - md[4] ) / 10 )
set md[3] = ModuloInteger(md[0], 10) // Charge of item 3
set md[0] = ( ( md[0] - md[3] ) / 10 )
set md[2] = ModuloInteger(md[0], 10) // Charge of item 2
set md[0] = ( ( md[0] - md[2] ) / 10 )
set md[1] = ModuloInteger(md[0], 10) // Charge of item 1
// compare the pooled charge with the charge needed in the recipe and remove charge needed if success
if ( n[1] >= md[1] ) and ( n[2] >= md[2] ) and ( n[3] >= md[3] ) and ( n[4] >= md[4] ) and ( n[5] >= md[5] ) and ( n[6] >= md[6] ) then
set n[1] = ( n[1] - md[1] )
set n[2] = ( n[2] - md[2] )
set n[3] = ( n[3] - md[3] )
set n[4] = ( n[4] - md[4] )
set n[5] = ( n[5] - md[5] )
set n[6] = ( n[6] - md[6] )
call UnitAddItemByIdSwapped( LoadIntegerBJ(1, udg_marker, udg_recipe), hero )
call SetItemCharges( GetLastCreatedItem(), LoadIntegerBJ(2, udg_marker, udg_recipe) )
call DisplayTextToPlayer(owner, 0.,0., ( "|c0000c400Troll:|r |c00ffff64Me haz crafted " + LoadStringBJ(11, udg_marker, udg_recipe) ) )
else
call DisplayTextToPlayer(owner, 0.,0., ( "|c0000c400Troll:|r |c00ffff64Me haz no resourcez for " + LoadStringBJ(11, udg_marker, udg_recipe) ) )
call DisplayTextToPlayer(owner, 0.,0., LoadStringBJ(12, udg_marker, udg_recipe) )
endif
set i = 1
loop
exitwhen i > LoadIntegerBJ(3, udg_marker, udg_recipe)
if ( n > 0 ) then
set j = 1
loop
exitwhen j > n // give back the pooled charge that weren't used
call UnitAddItemByIdSwapped( LoadIntegerBJ(i+3, udg_marker, udg_recipe), hero )
set j = j + 1
endloop
endif
set i = i + 1
endloop
set i = 0
loop // reset the integers to 0
exitwhen i > 6
set id = 0
set ic = 0
set md = 0
set n = 0
set i = i + 1
endloop
set udg_marker = 0
set owner = null
set hero = null
endif
endfunction

//===========================================================================
function InitTrig_RecipeSystem takes nothing returns nothing
set gg_trg_RecipeSystem = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_RecipeSystem, EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerAddAction( gg_trg_RecipeSystem, function RS_recipe )
endfunction[/code]

:) is there anything to do to improve it efficiency? or to make it betterly coded?
 
Last edited:
Status
Not open for further replies.
Top