HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

jass function

06-07-2005, 08:50 PM#1
mogmiester
this function tht i created as an item crafting trigger isnt accepted by the WE - even though kattannas jass program has no problems at all : / :\ . can anyone take a look/put it in a map and see if it works plz? i no it will leak memory, but i can fix that later. thx

Code:
function Createitems takes integer numofitems, unit crafter, item i1, item i2, item i3, item i4, item i5, item i6, integer createditem returns nothing
local integer array a
set a[0]=1
set a[1]=numofitems
set a[2]=1
set a[3]=6
local integer array varloop
set varloop[0]=1
set varloop[1]=6
set varloop[2]=1
set varloop[3]=6
set varloop[4]=1
set varloop[5]=6
set varloop[6]=1
set varloop[7]=6
set varloop[8]=1
set varloop[9]=6
set varloop[10]=1
set varloop[11]=6
set varloop[12]=1
set varloop[13]=numofitems
local item array varitems
set varitems[0]=i1
set varitems[1]=i2
set varitems[2]=i3
set varitems[3]=i4
set varitems[4]=i5
set varitems[5]=i6
local boolean array varitemtrue
set varitemtrue[0]=false
set varitemtrue[1]=false
set varitemtrue[2]=false
set varitemtrue[3]=false
set varitemtrue[4]=false
set varitemtrue[5]=false
loop
exitwhen (a[0]>a[1])
     loop
     exitwhen set varloop[2*a[0]] > varloop[(2*a[0])+1]
     if ( ( UnitItemInSlotBJ(crafter, varloop[2*a[0]]) == varitems[2*a[0]] ) ) then
     set varitemtrue[a]=true
          if (varloop[13]=>varloop[12]) then
          loop
          exitwhen a[2]>a[3]
          if varitemtrue[a]=true then
          call RemoveItem( UnitItemInSlotBJ(crafter, a[2]) )
          endif
          set a[2] = a[2] + 1
          endloop
               call UnitAddItemSwapped( createditem, crafter )
               return
          endif
     else
     set varloop[2*a[0]] = varloop[2*a[0]]+1
     endif
     endloop
set a[0]=a[0]+1
endloop
endfunction
06-07-2005, 09:41 PM#2
PitzerMike
You must declare local integer array varloop at the top of your function and not in the middle.
Alos the other locals (varitems and the other one) must be declared at the top.
06-08-2005, 12:32 PM#3
mogmiester
thankyou very very much, rep given

EDIT:ok ive done that, but now how do i skip all of the remaining actions? return doesnt work, ind i c'nped that from a converted trigger.

EDIT2: ok, i changed some things, but now the we completely crashes (dissappears) when i try to save it. The code is
Code:
function createitems takes integer numofitems, unit crafter, item i1, item i2, item i3, item i4, item i5, item i6, integer createditem returns nothing
local integer array a
local integer array varloop
local item array varitems
local boolean array varitemtrue
set a[0]=1
set a[1]=numofitems
set a[2]=1
set a[3]=6
set varloop[0]=1
set varloop[1]=6
set varloop[2]=1
set varloop[3]=6
set varloop[4]=1
set varloop[5]=6
set varloop[6]=1
set varloop[7]=6
set varloop[8]=1
set varloop[9]=6
set varloop[10]=1
set varloop[11]=6
set varloop[12]=1
set varloop[13]=numofitems
set varitems[0]=i1
set varitems[1]=i2
set varitems[2]=i3
set varitems[3]=i4
set varitems[4]=i5
set varitems[5]=i6
set varitemtrue[0]=false
set varitemtrue[1]=false
set varitemtrue[2]=false
set varitemtrue[3]=false
set varitemtrue[4]=false
set varitemtrue[5]=false
loop
exitwhen (a[0]>a[1])
     loop
     exitwhen varloop[2*a[0]] > varloop[(2*a[0])+1]
     if ( ( UnitItemInSlotBJ(crafter, varloop[2*a[0]]) == varitems[2*a[0]] ) ) then
     set varitemtrue[a[0]]=true
          if (varloop[13]>=varloop[12]) then
          loop
          exitwhen a[2]>a[3]
          if varitemtrue[a[0]]==true then
          call RemoveItem( UnitItemInSlotBJ(crafter, a[2]) )
          endif
          set a[2] = a[2] + 1
          endloop
               call UnitAddItemSwapped( createditem, crafter )
          endif
     else
     set varloop[2*a[0]] = varloop[2*a[0]]+1
     endif
     endloop
set a[0]=a[0]+1
endloop
set a[0]=null
set a[1]=null
set a[2]=null
set a[3]=null
set varloop[0]=null
set varloop[1]=null
set varloop[2]=null
set varloop[3]=null
set varloop[4]=null
set varloop[5]=null
set varloop[6]=null
set varloop[7]=null
set varloop[8]=null
set varloop[9]=null
set varloop[10]=null
set varloop[11]=null
set varloop[12]=null
set varloop[13]=null
set varitems[0]=null
set varitems[1]=null
set varitems[2]=null
set varitems[3]=null
set varitems[4]=null
set varitems[5]=null
set varitemtrue[0]=null
set varitemtrue[1]=null
set varitemtrue[2]=null
set varitemtrue[3]=null
set varitemtrue[4]=null
set varitemtrue[5]=null
endfunction
06-12-2005, 04:08 PM#4
KaTTaNa
You should only set handle-types to null at end of the function. Integer, boolean, real, code and string should not (not 100% sure about string though).
You are setting varloop[..] and varitemtrue[..] to null, which is a type mismatch since null is a handle. What you are trying to do is set varloop to 0 and varitemtrue to false, but it is not even necissary.
Just remove the lines that set varloop and varitemtrue to null and try again.

And by the way, please do something about your indenting. It's particularly painful to read your loops. Try to follow the standard indenting way that blizzard uses.

And a last thing. Ever since I implemented that lousy syntax checker I have regretted it because people seem to rely on it even though the readme clearly says that it's not reliable.
But how many people read readme's anyway?
06-12-2005, 06:03 PM#5
mogmiester
so i should get rid of most of my null's to make it work? ok, thx, i thought id never get an answer : ) rep given
06-12-2005, 10:15 PM#6
Vexorian
And use a loop when setting multiple indexes of an array to the same value, please