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

[JASS] Question about Globals

Status
Not open for further replies.
Level 19
Joined
Oct 12, 2007
Messages
1,821
Hey there.

I'm trying to make a JASS spell and I know I'm not good at it but had a question regarding Globals.
In GUI you can make variables and well they get made at map initialisation basically. Now I want to do exact the same thing in JASS so I want to make a trigger that does nothing but making a few 'variables' at map initialisation for later use.

How should I do this?

The globals I need to store are:
real SpellUnitX[11][200] and real SpellUnitY[11][200]

Please dont ask me lots of questions about the "why". I just want to try this thing on my way. I don't care if there are more efficient ways but I just like to do something on my own and see how it goes.:D

Some better explanation:

I use SpellUnitX[][] and SpellUnitY[][] in 2 different triggers so I got to make them global but I don't know how I should do that because the 1st trigger activates on spellcast and the other one has a 0.04 repeating timer.
 
You can make a hashtable called Hash (variable editor) which saves you from having to create a bunch of trivial udg_-prefixed globals like you mentioned

JASS:
call SaveReal(udg_Hash,0,0,GetUnitX(GetTriggerUnit()) //save the x position
call SaveReal(udg_Hash,0,1,GetUnitY(GetTriggerUnit()) //save the y position
 
//then in the timed loop -
 
local real x = LoadReal(udg_Hash,0,0) //load the x position
local real y = LoadReal(udg_Hash,0,1) //load the y position

But, like using globals, this is not MUI. I can give you MUI if you want, but it will be more complicated.
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
You can make a hashtable called Hash (variable editor) which saves you from having to create a bunch of trivial udg_-prefixed globals like you mentioned

JASS:
call SaveReal(udg_Hash,0,0,GetUnitX(GetTriggerUnit()) //save the x position
call SaveReal(udg_Hash,0,1,GetUnitY(GetTriggerUnit()) //save the y position
 
//then in the timed loop -
 
local real x = LoadReal(udg_Hash,0,0) //load the x position
local real y = LoadReal(udg_Hash,0,1) //load the y position

But, like using globals, this is not MUI. I can give you MUI if you want, but it will be more complicated.

Hmm..
Well I just need Variables with 2 arrays. That's not possible in GUI so I had to make this in JASS. And I believe I should make them as globals right? So I can use the variables in multiple triggers.
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
The thing is. I just want to give this little thing a try.
It might be so that hashtables are better but the own thing I want to know is how can I make those things I said ( UnitX[][] and UnitY[][] ) as globals I can use in every trigger in the map.

I got this but it says syntax error:

globals
constant real UnitX[11][200]
constant real UnitY[11][200]
endglobals
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
No, Jass only supports 1 dimensional Arrays.

Then why did the Oakwood coder, RaiN., make working jass systems with 2 dimensional arrays? I just don't want to bother RaiN. with this rather easy question.

Now to the topic.

What IF the globals I wanted to make are 1 dimensional.. How would you make it then?

Please I really think I'm not asking such a hard question.
 
JASS:
struct MassiveArray
    static thistype array Dex
    real array x
    real array y
    static method onInit takes nothing returns nothing
        local integer i = 0
        local integer i2
        local MassiveArray this
        loop
            set .Dex[i] = MassiveArray.create()
            set this = .Dex[i]
            set i2 = 0
            loop
                set .x[i2] = //some value
                set .y[i2] = //some value
                set i2 = i2 + 1
                exitwhen i2 == 200
            endloop
            exitwhen i == 11
            set i = i + 1
        endloop
    endmethod
endstruct
 
// for example, reference it like:
local MassiveArray ref = MassiveArray.Dex[GetPlayerId(GetTriggerPlayer())]
 
    SetUnitPosition(u,ref.x[22],ref.y[26])
    call UnitDamageTarget(u,target,ref.x[55],true,false,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_LIGHTNING,WEAPON_TYPE_WHOKNOWS)

JASS:
//Reference it like:
    local unit u = GetTriggerUnit()
    local integer i = 0
    local integer get = StringHash(I2S(GetPlayerId(GetTriggerPlayer())) + "x")  // or "y"
    loop
        call SetUnitX(u,LoadReal(udg_Hash,get,i))
        set i = i + 1
        exitwhen i > 200
    endloop
 
//initialize it like:
 
function InitArrays takes nothing returns nothing
    local real value
    local integer Player_Number = 0
    local integer i
    local integer index
    loop
      // setup the x arrays
        set index = StringHash(I2S(Player_Number) + "x")
        set i = 0
        loop
            call SaveReal(udg_Hash,index,i,value) //wheras "value" is the real # you want to save
            set i = i + 1
            exitwhen(i > 200.)
        endloop
      // setup the y arrays
        set index = StringHash(I2S(Player_Number) + "y")
        set i = 0
        loop
            call SaveReal(udg_Hash,index,i,value)
            set i = i + 1
            exitwhen(i > 200.)
        endloop
        set Player_Number =(Player_Number + 1)
        exitwhen(Player_Number > 11)
    endloop
endfunction
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
I appreciate your help Bribe but this aint useful to me because.. I don't understand Jass well enough to put this in my code. I'm more looking for something I'm 99% sure of it's possible that will work for me. It might not be as efficient as this but well..
I'm getting the feeling I'm making myself look totally dumb right now and maybe I even want things that aren't possible but I really get the feeling you don't understand what I try to get here.
So I appreciate your help but I still got the same issue at the moment.
 
Level 3
Joined
Apr 20, 2010
Messages
46
Sorry, I stick to JASS as in World Editor without any extensions. So "original" JASS or whatever it can be called, to my knowledge, doesn't actively support multidimensional arrays.


Without any meddling, you can at least pretend to have multiple dimensions on an array though
Example: IntArray[a], with maximum range of [a] is 16 and maximum range of is 16
IntArray[1][1] = IntArray[1*16+1]
IntArray[a] = IntArray[b*(aMax+1)+a]
IE: IntArray[2][13] = IntArray[13*(16+1)+2] = IntArray[223]
IntArray[0][0] = IntArray[0*(16+1)+0] = IntArray[0]
IntArray[16][16] = IntArray[16*(16+1)+16] = IntArray[288]

From my previous knowledge, arrays can only reach up to 8192 members, meaning (a*b) must never exceed that number. Ofcourse I'm not as familiar with JASS and its data structures as other people, so I could be quite wrong.

Hashtables are more powerful but a lot more complicated.

Hope I've been helpful.
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
Sorry, I stick to JASS as in World Editor without any extensions. So "original" JASS or whatever it can be called, to my knowledge, doesn't actively support multidimensional arrays.


Without any meddling, you can at least pretend to have multiple dimensions on an array though
Example: IntArray[a], with maximum range of [a] is 16 and maximum range of is 16
IntArray[1][1] = IntArray[1*16+1]
IntArray[a] = IntArray[b*(aMax+1)+a]
IE: IntArray[2][13] = IntArray[13*(16+1)+2] = IntArray[223]
IntArray[0][0] = IntArray[0*(16+1)+0] = IntArray[0]
IntArray[16][16] = IntArray[16*(16+1)+16] = IntArray[288]

From my previous knowledge, arrays can only reach up to 8192 members, meaning (a*b) must never exceed that number. Ofcourse I'm not as familiar with JASS and its data structures as other people, so I could be quite wrong.

Hashtables are more powerful but a lot more complicated.

Hope I've been helpful.


Yeah true that would be a good solution to solve it. That's also what I did before I knew double arrays were possible.
 
Status
Not open for further replies.
Top