• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Why Doesn't it Work?

Status
Not open for further replies.

ABM

ABM

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

this return an error but i don't understand why?
JASS:
function aaa takes nothing returns nothing
    local integer array id
    loop
           exitwhen i > 6
            set id[i] = GetItemTypeId(UnitItemInSlotBJ(hero, i)
    endloop
endfunction

the function is much bigger but the error seems:
set id = GetItemTypeId(UnitItemInSlotBJ(hero, i)

ItemID should be integer right?
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
ok my bad for not writting enough and making mistake in writting :p:

Here you have the full method ( it is in the structure RecipeSystem)

[Jass=]
private static method RecipeMain takes unit hero, player owner, integer marker returns nothing
local integer array id
local integer array ic
local integer array n
local integer i = 1
local integer j = 1
local item ti = null
loop
exitwhen i > 6
set id = GetItemTypeId(UnitItemInSlotBJ(hero, i)
set ic = GetItemCharges(UnitItemInSlotBJ(hero, i))
set ti = UnitItemInSlotBJ(hero, i)
if ( id == trecipe[3][marker] ) and ( ti != 0 ) then
set n[1] = ( n[1] + ic )
call RemoveItem( UnitItemInSlotBJ(hero, i) )
elseif ( id == trecipe[4][marker] ) and ( ti != 0 ) then
set n[2] = ( n[2] + ic )
call RemoveItem( ti )
elseif ( id == trecipe[5][marker] ) and ( ti != 0 ) then
set n[3] = ( n[3] + ic )
call RemoveItem( ti )
elseif ( id == trecipe[6][marker] ) and ( ti != 0 ) then
set n[4] = ( n[4] + ic )
call RemoveItem( ti )
elseif ( id == trecipe[7][marker] ) and ( ti != 0 ) then
set n[5] = ( n[5] + ic )
call RemoveItem( ti )
elseif ( id == trecipe[8][marker] ) and ( ti != 0 ) then
set n[6] = ( n[6] + ic )
call RemoveItem( ti )
endif
set ti = null
set i = i + 1
endloop
set i = 1
loop
exitwhen i > 6
set id(i) = 0
set ic(i) = 0
endloop
if ( n[1] >= trecipe[9][marker] ) and ( n[2] >= trecipe[10][marker] ) and ( n[3] >= trecipe[11][marker] ) and ( n[4] >= trecipe[12][marker] ) and ( n[5] >= trecipe[13][marker] ) and ( n[6] >= trecipe[14][marker] ) then
set n[1] = ( n[1] - trecipe[9][marker] )
set n[2] = ( n[2] - trecipe[10][marker] )
set n[3] = ( n[3] - trecipe[11][marker] )
set n[4] = ( n[4] - trecipe[12][marker] )
set n[5] = ( n[5] - trecipe[13][marker] )
set n[6] = ( n[6] - trecipe[14[marker] )
call UnitAddItemByIdSwapped( trecipe[2][marker], hero )
call DisplayTimedTextToPlayer(owner), 0.,0., 6.00, ( "|c0000c400Troll:|r |c00ffff64Me haz crafted " + trecipe[16][marker] ) )
else
call DisplayTimedTextToPlayer(owner), 0.,0., 6.00, ( "|c0000c400Troll:|r |c00ffff64Me haz no resourcez for " + trecipe[16][marker] ) )
call DisplayTimedTextToPlayer(owner), 0.,0., 6.00, trecipe[15][marker] )
endif
set i = 1
loop
exitwhen i > 6
if ( n > 0 ) then
set j = 1
loop
exitwhen j > n
call UnitAddItemByIdSwapped( trecipe[i+2][marker], hero )
set j = j + 1
endloop
endif
set i = i + 1
endloop
set i = 1
loop
exitwhen i > 6
set n(i) = 0
set i = i + 1
endloop
set marker = 0
set owner = null
set hero = null
endmethod

private static method callRecipe takes nothing returns nothing
set hero = GetTriggerUnit()
set owner = GetOwningPlayer(hero)
set abi = GetSpellAbilityId()
loop
if abi==trecipe[1] then
set marker = i
call thistype.RecipeMain(hero, owner, marker)
return
endif
set i = i + 1
exitwhen i==itemCounter
endloop
set marker = 0
set hero = null
set owner = null
endmethod
[/code]

what doesn't work seems to be the integer array id[] ....
it says:
set id = GetItemTypeId(UnitItemInSlotBJ(hero, i)
syntax error, unexpected: end of line?

....so the problem is actually not i... but i don't understand

if you need the full structure and library i can write it, but i think the problem right now is located in the part i described.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
It gives an "End of line"-error when you forget a bracket.
If you have Notepad++, you can easily check this (if you click the first bracket, it will highlight the bracket that closes it. If there is no closing bracket, it will turn into another color).
So yeah, add a bracket at the end of that line :).

Edit: actually, JNGP does this too. You can just keep adding brackets until one becomes flashy red :p.
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Yeahhhh !!! thanks
i just noticed there was a bracket missing :p

but another error just added:
set id(i) = 0
syntax error, unexpected: "="?

[Jass=]
set i = 1
loop
exitwhen i > 6
set id(i) = 0
set ic(i) = 0
set i = i + 1
endloop[/code]

???
i just corrected the i = i + 1 i forgot.
the error is still there....
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
wow you have good eyes ap0calypse !!
indeed, i didn't know it would make a difference :p

more error
call DisplayTimedTextToPlayer(owner), 0.,0., 6.00, ( "|c0000c400Troll:|r |c00ffff64Me haz crafted " + trecipe[16][marker] ) )
syntax error, unexpected: ","?

Edit corrected DisplayTimedTextToPlayer((owner), 0.,0., 6.00, ( "|c0000c400Troll:|r |c00ffff64Me haz crafted " + trecipe[16][marker] ) )
corrected another mistake too with () and []


I Now have a very bad bug.... it compile all up to 80% wait for 2 sec... a write out of memory and shut (stopping the saving of triggers)
here is the full library code
[Jass=]
library RecipeSystem uses RegisterPlayerUnitEvent, Table

struct RecipeSystem extends array
private static integer itemCounter = 0
private static integer marker = 0
private static unit hero
private static player owner
private static integer abi
private static TableArray trecipe

private static method RecipeMain takes unit hero, player owner, integer marker returns nothing
local integer array id
local integer array ic
local integer array n
local integer i = 1
local integer j = 1
local item ti = null
loop
exitwhen i > 6
set id = GetItemTypeId(UnitItemInSlotBJ(hero, i))
set ic = GetItemCharges(UnitItemInSlotBJ(hero, i))
set ti = UnitItemInSlotBJ(hero, i)
if ( id == trecipe[3][marker] ) and ( ti != 0 ) then
set n[1] = ( n[1] + ic )
call RemoveItem( UnitItemInSlotBJ(hero, i) )
elseif ( id == trecipe[4][marker] ) and ( ti != 0 ) then
set n[2] = ( n[2] + ic )
call RemoveItem( ti )
elseif ( id == trecipe[5][marker] ) and ( ti != 0 ) then
set n[3] = ( n[3] + ic )
call RemoveItem( ti )
elseif ( id == trecipe[6][marker] ) and ( ti != 0 ) then
set n[4] = ( n[4] + ic )
call RemoveItem( ti )
elseif ( id == trecipe[7][marker] ) and ( ti != 0 ) then
set n[5] = ( n[5] + ic )
call RemoveItem( ti )
elseif ( id == trecipe[8][marker] ) and ( ti != 0 ) then
set n[6] = ( n[6] + ic )
call RemoveItem( ti )
endif
set ti = null
set i = i + 1
endloop
set i = 1
loop
exitwhen i > 6
set id = 0
set ic = 0
set i = i + 1
endloop
if ( n[1] >= trecipe[9][marker] ) and ( n[2] >= trecipe[10][marker] ) and ( n[3] >= trecipe[11][marker] ) and ( n[4] >= trecipe[12][marker] ) and ( n[5] >= trecipe[13][marker] ) and ( n[6] >= trecipe[14][marker] ) then
set n[1] = ( n[1] - trecipe[9][marker] )
set n[2] = ( n[2] - trecipe[10][marker] )
set n[3] = ( n[3] - trecipe[11][marker] )
set n[4] = ( n[4] - trecipe[12][marker] )
set n[5] = ( n[5] - trecipe[13][marker] )
set n[6] = ( n[6] - trecipe[14][marker] )
call UnitAddItemByIdSwapped( trecipe[2][marker], hero )
call DisplayTextToPlayer((owner), 0.,0., ( "|c0000c400Troll:|r |c00ffff64Me haz crafted " + trecipe[16][marker] ) )
else
call DisplayTextToPlayer((owner), 0.,0., ( "|c0000c400Troll:|r |c00ffff64Me haz no resourcez for " + trecipe[16][marker] ) )
call DisplayTextToPlayer((owner), 0.,0., trecipe[15][marker] )
endif
set i = 1
loop
exitwhen i > 6
if ( n > 0 ) then
set j = 1
loop
exitwhen j > n
call UnitAddItemByIdSwapped( trecipe[i+2][marker], hero )
set j = j + 1
endloop
endif
set i = i + 1
endloop
set i = 1
loop
exitwhen i > 6
set n = 0
set i = i + 1
endloop
set marker = 0
set owner = null
set hero = null
endmethod

private static method callRecipe takes nothing returns nothing
set hero = GetTriggerUnit()
set owner = GetOwningPlayer(hero)
set abi = GetSpellAbilityId()
loop
if abi==trecipe[1] then
set marker = i
call thistype.RecipeMain(hero, owner, marker)
return
endif
set i = i + 1
exitwhen i==itemCounter
endloop
set marker = 0
set hero = null
set owner = null
endmethod

private static method onInit takes nothing returns nothing
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_CAST,function thistype.callRecipe)
set trecipe = TableArray[0x3000]
endmethod

//API:
static method registerRecipe takes integer abi, integer i(0), integer i(1),integer i(2), integer i(3),integer i(4), integer i(5),integer i(6), integer c(1),integer c(2), integer c(3),integer c(4), integer c(5),integer c(6), string itext, string iname returns nothing
local integer i = -1
loop
if trecipe[1]== abi then
debug call BJDebugMsg("registerRecipe ERROR: "+I2S(i(0))+" can only be registered once!")
return
endif
set i = i + 1
exitwhen i==itemCounter
endloop
set trecipe[1][itemCounter] = abi
set trecipe[2][itemCounter] = i(0)
set trecipe[3][itemCounter] = i(1)
set trecipe[4][itemCounter] = i(2)
set trecipe[5][itemCounter] = i(3)
set trecipe[6][itemCounter] = i(4)
set trecipe[7][itemCounter] = i(5)
set trecipe[8][itemCounter] = i(6)
set trecipe[9][itemCounter] = c(1)
set trecipe[10][itemCounter] = c(2)
set trecipe[11][itemCounter] = c(3)
set trecipe[12][itemCounter] = c(4)
set trecipe[13][itemCounter] = c(5)
set trecipe[14][itemCounter] = c(6)
set trecipe[15][itemCounter] = itext
set trecipe[16][itemCounter] = iname
set itemCounter = itemCounter + 1
endmethod

endstruct

endlibrary [/code]
 
Last edited:

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
ap0calypse look up i have another problem the save compiler shut down due to memory
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Hmh, so:
ti != 0 is invalid, because you're comparing an item with an integer. I think the "0" must be "null".
The DisplayTextToPlayer's also have a bracket-problem and "trecipe" isn't a string, you have to convert it first.

The function "callRecipe" doesn't have an integer i, so that could cause trouble.
The function "registerRecipe" takes a lot of variables with brackets. Brackets aren't allowed in variable names, you have to rename them.
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
thanks a lot ap0calypse

i will try to change all what you pointed and then i will write the result...

wow many thanks now it compile normally ^^

but what do you mean ? " The function "registerRecipe" takes a lot of variables with brackets. Brackets aren't allowed in variable names, you have to rename them. "
trecipe is a tablearray so it has trecipe[x][x] = value
i am not sure what table array is, but table usually have 2D... hashtable (x, x) so i suppose it is the same... no?
it use Bribe Table but i don't understand that much :p

i tried to add reputation to you (ap0calypse), but it says i have to spread some reputation around before to give it to you...??

Edit====LOL
it doesn't compile, i just realize i had desactivated the trigger,
and when i reactivated it doesn't work still out of memory... :(
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
thanks a lot ap0calypse

i will try to change all what you pointed and then i will write the result...

wow many thanks now it compile normally ^^

but what do you mean ? " The function "registerRecipe" takes a lot of variables with brackets. Brackets aren't allowed in variable names, you have to rename them. "
trecipe is a tablearray so it has trecipe[x][x] = value
i am not sure what table array is, but table usually have 2D... hashtable (x, x) so i suppose it is the same... no?
it use Bribe Table but i don't understand that much :p

i tried to add reputation to you (ap0calypse), but it says i have to spread some reputation around before to give it to you...??

Edit====LOL
it doesn't compile, i just realize i had desactivated the trigger,
and when i reactivated it doesn't work still out of memory... :(

than get a better computer or fix your syntax errors. my map has atleast 50K lines of code in it and compiles fine in ~10 seconds

how much memory do u have + whats ur jasshelper vers
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Arhowk
it is JassNewGen pack5e
it should be the latest or almost
and my computer is very fast and 16go memory (os 64bit)

but my coding sux, and i have probably many error...
that's why i need help fixing them.

i fixed some error but now it display this:
call SaveInteger(Table__ht, (((s__RecipeSystem_trecipe) + (15))), (s__RecipeSystem_itemCounter), ( itext)) // INLINED!!
'cannot convert string to integer'
[Jass=]
set trecipe[15][itemCounter] = itext
set trecipe[16][itemCounter] = iname
[/code]
can't i store string into the trecipe [x] [x] (hashtable) ??
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
but what do you mean ? " The function "registerRecipe" takes a lot of variables with brackets. Brackets aren't allowed in variable names, you have to rename them. "
trecipe is a tablearray so it has trecipe[x][x] = value
I'm talking about the round brackets, not square ones :D (in general: if I say "brackets", they're always round unless specified otherwise).
It's in this line by the way:
JASS:
static method registerRecipe takes integer abi, integer i(0), integer i(1),integer i(2), integer i(3),integer i(4), integer i(5),integer i(6), integer c(1),integer c(2), integer c(3),integer c(4), integer c(5),integer c(6), string itext, string iname returns nothing
Brackets (round ones) mean that whatever's before it is a function.
Like "set i = hello(1)", "hello" is a function and "hello(1)" can never be a variable name.
You will have to rename them to i1, i2, i3, ...


I've never gotten a memory error, so I don't know what that usually means :S.
Are there any other triggers in the map? If so, maybe disable all of them except for the 3 libraries you're working with (Table, PlayerUnitEvent and the one you just created).
I was able to parse the library without any errors (after patching it up a little. I also didn't actually check whether it works or not).
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Thanks ap0calypse
i changed it but i have some string to integer problem it seems...

but the memory problem was caused by what you said with the bracket
[Jass=]
library RecipeSystem uses RegisterPlayerUnitEvent, Table

struct RecipeSystem extends array
private static integer itemCounter = 0
private static integer marker = 0
private static unit hero
private static player owner
private static integer abi
private static TableArray trecipe

private static method RecipeMain takes unit hero, player owner, integer marker returns nothing
local integer array id
local integer array ic
local integer array n
local integer i = 1
local integer j = 1
local item ti = null
loop
exitwhen i > 6
set id = GetItemTypeId(UnitItemInSlotBJ(hero, i))
set ic = GetItemCharges(UnitItemInSlotBJ(hero, i))
set ti = UnitItemInSlotBJ(hero, i)
if ( id == trecipe[3][marker] ) and ( ti != null ) then
set n[1] = ( n[1] + ic )
call RemoveItem( UnitItemInSlotBJ(hero, i) )
elseif ( id == trecipe[4][marker] ) and ( ti != null ) then
set n[2] = ( n[2] + ic )
call RemoveItem( ti )
elseif ( id == trecipe[5][marker] ) and ( ti != null ) then
set n[3] = ( n[3] + ic )
call RemoveItem( ti )
elseif ( id == trecipe[6][marker] ) and ( ti != null ) then
set n[4] = ( n[4] + ic )
call RemoveItem( ti )
elseif ( id == trecipe[7][marker] ) and ( ti != null ) then
set n[5] = ( n[5] + ic )
call RemoveItem( ti )
elseif ( id == trecipe[8][marker] ) and ( ti != null ) then
set n[6] = ( n[6] + ic )
call RemoveItem( ti )
endif
set ti = null
set i = i + 1
endloop
set i = 1
loop
exitwhen i > 6
set id = 0
set ic = 0
set i = i + 1
endloop
if ( n[1] >= trecipe[9][marker] ) and ( n[2] >= trecipe[10][marker] ) and ( n[3] >= trecipe[11][marker] ) and ( n[4] >= trecipe[12][marker] ) and ( n[5] >= trecipe[13][marker] ) and ( n[6] >= trecipe[14][marker] ) then
set n[1] = ( n[1] - trecipe[9][marker] )
set n[2] = ( n[2] - trecipe[10][marker] )
set n[3] = ( n[3] - trecipe[11][marker] )
set n[4] = ( n[4] - trecipe[12][marker] )
set n[5] = ( n[5] - trecipe[13][marker] )
set n[6] = ( n[6] - trecipe[14][marker] )
call UnitAddItemByIdSwapped( trecipe[2][marker], hero )
call DisplayTextToPlayer(owner, 0.,0., ( "|c0000c400Troll:|r |c00ffff64Me haz crafted " + I2S(trecipe[16][marker] ) ) )
else
call DisplayTextToPlayer(owner, 0.,0., ( "|c0000c400Troll:|r |c00ffff64Me haz no resourcez for " + I2S(trecipe[16][marker] ) ) )
call DisplayTextToPlayer(owner, 0.,0., I2S(trecipe[15][marker]) )
endif
set i = 1
loop
exitwhen i > 6
if ( n > 0 ) then
set j = 1
loop
exitwhen j > n
call UnitAddItemByIdSwapped( trecipe[i+2][marker], hero )
set j = j + 1
endloop
endif
set i = i + 1
endloop
set i = 1
loop
exitwhen i > 6
set n = 0
set i = i + 1
endloop
set marker = 0
set owner = null
set hero = null
endmethod

private static method callRecipe takes nothing returns nothing
local integer i = 0
set hero = GetTriggerUnit()
set owner = GetOwningPlayer(hero)
set abi = GetSpellAbilityId()
loop
if abi==trecipe[1] then
set marker = i
call thistype.RecipeMain(hero, owner, marker)
return
endif
set i = i + 1
exitwhen i==itemCounter
endloop
set marker = 0
set hero = null
set owner = null
endmethod

private static method onInit takes nothing returns nothing
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_CAST,function thistype.callRecipe)
set trecipe = TableArray[0x3000]
endmethod

//API:
static method registerRecipe takes integer abi, integer i0, integer i1,integer i2, integer i3,integer i4, integer i5,integer i6, integer c1,integer c2, integer c3,integer c4, integer c5,integer c6, string itext, string iname returns nothing
local integer i = -1
loop
if trecipe[1]== abi then
debug call BJDebugMsg("registerRecipe ERROR: "+I2S(i(0))+" can only be registered once!")
return
endif
set i = i + 1
exitwhen i==itemCounter
endloop
set trecipe[1][itemCounter] = abi
set trecipe[2][itemCounter] = i0
set trecipe[3][itemCounter] = i1
set trecipe[4][itemCounter] = i2
set trecipe[5][itemCounter] = i3
set trecipe[6][itemCounter] = i4
set trecipe[7][itemCounter] = i5
set trecipe[8][itemCounter] = i6
set trecipe[9][itemCounter] = c1
set trecipe[10][itemCounter] = c2
set trecipe[11][itemCounter] = c3
set trecipe[12][itemCounter] = c4
set trecipe[13][itemCounter] = c5
set trecipe[14][itemCounter] = c6
set trecipe[15][itemCounter] = itext
set trecipe[16][itemCounter] = iname
set itemCounter = itemCounter + 1
endmethod

endstruct

endlibrary [/code]

problem is with :
set trecipe[15][itemCounter] = itext
set trecipe[16][itemCounter] = iname

what is the Jass code? S2I(itext) to make string inside trecipe [15] [itemcounter]

Arhowk
thanks for the help but i am jass begginer so i don't know all Jass language code...
i will try S2I() since it seems logical but if it doesn't work could you tell me the correct way?

ok what should i do with this?
call DisplayTextToPlayer(owner, 0.,0., ( "|c0000c400Troll:|r |c00ffff64Me haz crafted " + I2S(trecipe[16][marker] ) ) )
should i do
call DisplayTextToPlayer(owner, 0.,0., ( "|c0000c400Troll:|r |c00ffff64Me haz crafted " + trecipe[16][marker] ) )
or
call DisplayTextToPlayer(owner, 0.,0., ( "|c0000c400Troll:|r |c00ffff64Me haz crafted " + I2S(S2T(trecipe[16][marker]) ) ) )
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
If you want to store a string by doing "set trecipe[15][itemCounter] = S2I( "text" ), then that's a bad idea.
S2I does indeed convert a string to an integer, but it's for strings that actually contain integers (like the string "15" will convert to the integer 15).
Normal strings will just return 0.

I don't think Table is meant to do that :p.
Then again, I've never used Table (nor any other library) before, so I might be incorrect.
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Thanks ap0calypse and Arhowk for all your help
this is really kind of you ^^

So storing string in a resipient that supposed to store integer will return a bad string?
So it is not possible to store string into the table?

Then maybe i can store an integer into the
set trecipe[15][itemCounter] = 1
add a string array itext
and put in itext[1] = the string i wanted to store
and do the same for iname....

the library is compiling fine now, i think all error has been fixed.
then i will have to check if it actually work :p
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
I looked up how to use Table, and it seems different than the way you use it.

In a regular Table (not an array), it would be something like this:
JASS:
set trecipe.string[15] = itext
set trecipe.string[16] = iname

With an array Table (what you have), it might be more like this:
JASS:
set trecipe[itemCounter].string[15] = itext
set trecipe[itemCounter].string[16] = iname
I'm actually not sure of this, I should probably test stuff like that first, but whatever :p.
For integers, you don't need to add ".integer" (it's already implied).
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Argh....
the map crash upon loading..... can't even test
i think the code is wrong :(

[Jass=]
library RecipeSystem uses RegisterPlayerUnitEvent, Table

struct RecipeSystem extends array
private static integer itemCounter = 0
private static integer marker = 0
private static unit hero
private static player owner
private static integer abi
private static TableArray trecipe

private static method RecipeMain takes unit hero, player owner, integer marker returns nothing
local integer array id
local integer array ic
local integer array n
local integer i = 1
local integer j = 1
local item ti = null
loop
exitwhen i > 6
set id = GetItemTypeId(UnitItemInSlotBJ(hero, i))
set ic = GetItemCharges(UnitItemInSlotBJ(hero, i))
set ti = UnitItemInSlotBJ(hero, i)
if ( id == trecipe[3][marker] ) and ( ti != null ) then
set n[1] = ( n[1] + ic )
call RemoveItem( UnitItemInSlotBJ(hero, i) )
elseif ( id == trecipe[4][marker] ) and ( ti != null ) then
set n[2] = ( n[2] + ic )
call RemoveItem( ti )
elseif ( id == trecipe[5][marker] ) and ( ti != null ) then
set n[3] = ( n[3] + ic )
call RemoveItem( ti )
elseif ( id == trecipe[6][marker] ) and ( ti != null ) then
set n[4] = ( n[4] + ic )
call RemoveItem( ti )
elseif ( id == trecipe[7][marker] ) and ( ti != null ) then
set n[5] = ( n[5] + ic )
call RemoveItem( ti )
elseif ( id == trecipe[8][marker] ) and ( ti != null ) then
set n[6] = ( n[6] + ic )
call RemoveItem( ti )
endif
set ti = null
set i = i + 1
endloop
set i = 1
loop
exitwhen i > 6
set id = 0
set ic = 0
set i = i + 1
endloop
if ( n[1] >= trecipe[9][marker] ) and ( n[2] >= trecipe[10][marker] ) and ( n[3] >= trecipe[11][marker] ) and ( n[4] >= trecipe[12][marker] ) and ( n[5] >= trecipe[13][marker] ) and ( n[6] >= trecipe[14][marker] ) then
set n[1] = ( n[1] - trecipe[9][marker] )
set n[2] = ( n[2] - trecipe[10][marker] )
set n[3] = ( n[3] - trecipe[11][marker] )
set n[4] = ( n[4] - trecipe[12][marker] )
set n[5] = ( n[5] - trecipe[13][marker] )
set n[6] = ( n[6] - trecipe[14][marker] )
call UnitAddItemByIdSwapped( trecipe[2][marker], hero )
call DisplayTextToPlayer(owner, 0.,0., ( "|c0000c400Troll:|r |c00ffff64Me haz crafted " + I2S(trecipe[16][marker] ) ) )
else
call DisplayTextToPlayer(owner, 0.,0., ( "|c0000c400Troll:|r |c00ffff64Me haz no resourcez for " + I2S(trecipe[16][marker] ) ) )
call DisplayTextToPlayer(owner, 0.,0., I2S(trecipe[15][marker]) )
endif
set i = 1
loop
exitwhen i > 6
if ( n > 0 ) then
set j = 1
loop
exitwhen j > n
call UnitAddItemByIdSwapped( trecipe[i+2][marker], hero )
set j = j + 1
endloop
endif
set i = i + 1
endloop
set i = 1
loop
exitwhen i > 6
set n = 0
set i = i + 1
endloop
set marker = 0
set owner = null
set hero = null
endmethod

private static method callRecipe takes nothing returns nothing
local integer i = 0
set hero = GetTriggerUnit()
set owner = GetOwningPlayer(hero)
set abi = GetSpellAbilityId()
loop
if abi==trecipe[1] then
set marker = i
call thistype.RecipeMain(hero, owner, marker)
return
endif
set i = i + 1
exitwhen i==itemCounter
endloop
set marker = 0
set hero = null
set owner = null
endmethod

private static method onInit takes nothing returns nothing
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_CAST,function thistype.callRecipe)
set trecipe = TableArray[0x3000]
endmethod

//API:
static method registerRecipe takes integer abi, integer i0, integer i1,integer i2, integer i3,integer i4, integer i5,integer i6, integer c1,integer c2, integer c3,integer c4, integer c5,integer c6, integer t1 returns nothing
local integer i = -1
loop
if trecipe[1]== abi then
debug call BJDebugMsg("registerRecipe ERROR: "+I2S(i(0))+" can only be registered once!")
return
endif
set i = i + 1
exitwhen i==itemCounter
endloop
set trecipe[1][itemCounter] = abi
set trecipe[2][itemCounter] = i0
set trecipe[3][itemCounter] = i1
set trecipe[4][itemCounter] = i2
set trecipe[5][itemCounter] = i3
set trecipe[6][itemCounter] = i4
set trecipe[7][itemCounter] = i5
set trecipe[8][itemCounter] = i6
set trecipe[9][itemCounter] = c1
set trecipe[10][itemCounter] = c2
set trecipe[11][itemCounter] = c3
set trecipe[12][itemCounter] = c4
set trecipe[13][itemCounter] = c5
set trecipe[14][itemCounter] = c6
set trecipe[15][itemCounter] = t1
set itemCounter = itemCounter + 1
endmethod

endstruct

endlibrary [/code]

[Jass=]
function Trig_Setup takes nothing returns nothing

//Recipe Name | AbiID| ItemID| Item1| Item2| Item3| Item4| Item5| Item6|Charge1|Charge2|Charge3|Charge4|Charge5|Charge6|Textinteger|
// Variable | Abi | i0 | i1 | i2 | i3 | i4 | i5 | i6 | c1 | c2 | c3 | c4 | c5 | c6 | t1 |
// Firecamp
call RecipeSystem.registerRecipe('A05R', 'wlsd', 'sbch', 'hval', 'clsd', 'bgst', 0, 0, 1, 1, 1, 1, 0, 0, 1)

endfunction

//===========================================================================
function InitTrig_SetupRecipe takes nothing returns nothing
set gg_trg_SetupRecipe = CreateTrigger( )
call TriggerRegisterTimerEventSingle( gg_trg_SetupRecipe, 0.00 )
call TriggerAddAction( gg_trg_SetupRecipe, function Trig_Setup )
endfunction[/code]

i tried with only one recipe to check, but it crashed......
it seems there is a problem with the setup function// call RecipeSystem.registerRecipe
 
Last edited:
Level 19
Joined
Aug 8, 2007
Messages
2,765
that struct is an absolute waste. it generates a bunch of worthless space. especially since everything your using is static.

also, are you sure all of the arguments your passing into the recipe are valid?
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Arhowk
i made this structure copying different structure i have seen (Advanced equipment system and metal ressource)...
because i have no idea on how to use a structure correctly....
so basically i think how did they do what they did? i try to understand and copy...
if he use static , i use static, etc....


if you understand what i am try to do (the recipe system)
then tell me how should i code it correctly..?
could you tell me what to change?
or do the structure for me?

i try to list all the recipe into array and then pass the recipe into the system
to get the recipe the pointer is the abilityID linked to the recipe.

if anyone can help?
because i don't know what i am doing wrong, since i don't really know what i am doing at all... i don't master Jass or VJass but still need to do the recipe system... :(
 
Status
Not open for further replies.
Top