HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

GUI -> JASS Trouble

07-25-2007, 09:55 PM#1
Slin
Hello and thanks for looking.

I want to rewrite one very big GUI trigger (2000 lines converted to custom text) into JASS. The main purpose of the trigger is to associate a certain Item-type with a Unit.

It looks something like this:

Trigger:
if (SummonItemtype == FootmanItem) then
set SummonedUnit = FootmanUnit
else
if (SummonItemtype == GruntItem) then
set SummonedUnit = GruntUnit
else

etc

This is very bothersome in GUI since there are so many associations. If I place everyone of them in a big if/else GUI style it won't go through compile because the function names gets too big. (e.g. Trig_Summon_Func007Func004Func001Func001Func001Func001Func001Func001Func001Func001Func001Func001Func 001Func001Func001Func001Func001Func001Func001Func001Func001Func001C etc.) So naturally I want to rewrite the trigger in JASS, which would go fine if not for this big problem:

FootmanItem is saved in "custom text" as a (hex?) code e.g. 'I009' or something similar, as is FootmanUnit. This makes it very bothersome when something is subject to change. Because if the code changes it's no problem in GUI it just auto updates but with custom script it doesn't. I also have no good way of tracking the code back to the unit or item-type.

Do I have to remake the whole system in another way if I want to change it or is there a smart solution to this problem?

Thanks for reading.
Slin
07-25-2007, 11:05 PM#2
Earth-Fury
On map initialization, or in a triggers init function, makes 2 large arrays:
ItemType
UnitType
both integer arrays.
go throgh assininging each pair to the same index in the arrays (eg:)
Collapse JASS:
set ItemType[0] = 'h000' // footman
set UnitType[0] = 'i000' // foorman item
set ItemType[1] = 'h001' // peon
set UnitType[1] = 'i001' // peon item

then use a loop to compare one of the arrays to say, the unit type of triggering unit
Collapse JASS:
local integer i = 0
loop
    exitwhen i > ARRAYS_HIGHEST_INDEX
    if UnitType[i] == (Triggering units type) then
        // Do stuff, i is the correct index number
        exitwhen true
    endif
    set i = i + 1
endloop


Edit: also, rawcodes ('h000') are base 255 (ASCII), not base 16 (hex) which means they can have any ASCII charicter in them. They are infact just integers, tho. (a unique way to declare an integer, but an integer none the less)
07-25-2007, 11:39 PM#3
Slin
Ah lol. Why didn't I think of that ^^. There is even a "database" already. Thank you.
07-26-2007, 01:32 AM#4
Slin
I've been trying to get this to work for hours now but failing. It goes through compile but when testing stops at wc3 start screen. The map works if I remove this.
Trigger:
Custom script: set udg_SummonedUnit = Summon_Unit_From_Item(udg_SummonItemtype)

SummonedUnit is a global unittype.

SummonItemtype is a global itemtype.

Collapse JASS:
function Summon_Unit_From_Item takes itemtype x returns unittype
      local integer i = 0
      loop
          exitwhen (i >= udg_Maxcards)
          if (udg_CodeItemtype[i] == x) then
              return udg_CodeUnittype[i]
          endif
          set i = i + 1
     endloop
     return udg_CodeUnittype[0]
endfunction



Maxcards is a global integer.
CodeItemtype is a global itemtype array.
CodeUnittype is a global unittype array.

I've triple-checked so all the variables are correctly spelled. The code is copy pasted. Can you spot what error I've made?

EDIT: When saving this because I was gonna quit and go to bed it suddenly found some compile errors. I thought it would find them when pressing test map but now I know it doesn't. Anyway the compile errors didn't help me.

On this line: "if ( udg_CodeItemtype[i] == x ) then" it says comparing to values of different type is not allowed. Yet as I said CodeItemtype is a global itemtype array. Or at least it says Item-Type in "Variables". Is Item-Type in GUI not the same as the handle extension itemtype?

Other errors: return udg_CodeUnittype[0] says Cannot convert returned value from integer to unittype.

set udg_SummonedUnit = Summon_Unit_From_Item(udg_SummonItemtype) says Cannot convert integer to item type & Cannot convert unittype to integer.

Am I too tired to see some really obvious error here? I'm posting it anyway before going to bed.

Thanks for reading.
07-26-2007, 05:25 AM#5
Earth-Fury
ok, step 1: download JASS New Gen Pack
http://wc3campaigns.net/showthread.php?t=90999
Step 2: Code it in 100% jass, not a mix of GUI and JASS. Why? because GUI has diffrent (wrong) names for soem things, flawed implimentation of other things, and really, doesn't meld well with decently written JASS code.

Now, what does jass new gen let you do? well, for a noob to jass, i suggest staying away from structs and the like till you get fully comfortable with jass itself, but you can declare globals anywhere using vJASS (the language extension that New Gen uses) example:
Collapse JASS:
globals
    integer myint = 0
endglobals

// Whatever

globals
    boolean myBool = false
    constant integer MAX_WHATEVER = 42
endglobals

Now, as for how you're doing things.... why use "unittype" and "itemtype" ? use integers with rawcodes, really. example:
Collapse JASS:
local integer MyUnitTypeVar = 'a000'
to see rawcodes in the object editor, press CTRL+D. ALWAYS work using rawcodes. Hell, i don't think i've ever needed to use the "unittype" type for anything. ever. i really have no clue why it exists, even functions like CreateUnit() take rawcodes.
Collapse JASS:
native CreateUnit takes player id, integer unitid, real x, real y, real face returns unit
(if you've never seen a native decliration before, they are in common.j, and describe functions implimented internally in the engine instead of in JASS itself. JASS functions are in blizzard.j)


Thats... all i can think of right now... ill try to remember to check this thread tomorrow to help ya out some more :)
07-26-2007, 09:34 AM#6
Slin
Quote:
Originally Posted by Earth-Fury
ok, step 1: download JASS New Gen Pack
http://wc3campaigns.net/showthread.php?t=90999
I use it already, does the normal editor show compile errors like I wrote above?

As for 100% JASS, indeed that would be the best. But the map is very big and 99% GUI. I don't want to remake it from scratch. I just want to improve it a bit.

Right now I just want to get this to function properly.

EDIT: Yay! I got it to work. Since all the involved variables were global I did everything in the function instead:
Collapse JASS:
function Summon_Unit_From_Item takes nothing returns nothing
  local integer i = 0
  loop
      exitwhen (i >= udg_Maxcards)
          if (udg_CodeItemtype[i] == udg_SummonItemtype) then 
              set udg_SummonedUnit = udg_CodeUnittype[i]
              exitwhen true

          endif
   set i = i + 1
   endloop
endfunction