• 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] calling a region with variable in the call name

Status
Not open for further replies.
Level 5
Joined
Jul 17, 2006
Messages
145
ok, i have a bunch of regions set up in a grid named "1 1" through "6 8" (coordinates). What i want to do is call each of these regions with a loop and variables, instead of having to copy and paste each function for each region i want to call. This proablly doesnt make much sense, so let me give you an example:

JASS:
//     (Using Vexorians CSGame Cache system)

function Trig_Set_Square_Coordinates_Actions takes nothing returns nothing
    local integer x = 1
    local integer y = 1
    loop
    call AttachInt("gg_rct_"+I2S(x)+"_"+I2S(y), "x", x)
    call AttachInt("gg_rct_"+I2S(x)+"_"+I2S(y), "y", y)
    set x = x+1
    if x > udg_MaxX then  // udg_MaxX is the maximum X value on my grid of regions
        set x = 1
        set y = y+1
    endif
        exitwhen y > udg_MaxY   // udg_MaxY is the maximum Y value on my grid of regions
    endloop
endfunction

//===========================================================================
function InitTrig_Set_Square_Coordinates takes nothing returns nothing
    set gg_trg_Set_Square_Coordinates = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Set_Square_Coordinates, function Trig_Set_Square_Coordinates_Actions )
endfunction

of course, i cant use a string for the name of the region, because WE wont let me do that... :S (and theres no string to region function that i know of)

anyways, i hope thats clear (if its not tell me and ill try to explain better)...anyone have any suggestions.
 
Level 5
Joined
Jul 17, 2006
Messages
145
:(
i cant find a way to nest arrays so i can make like, Coordinates[1][4] or something. it would have to be an array with a 1 through 48 as the number in the array, and that would defeat the purpose. i might as well just spell them out in a big long jass line :S
 
Level 5
Joined
Jul 17, 2006
Messages
145
ok well this map is what i have so far(see attachment). It creates the circles of power in a straight line from the unit (the rifleman's movement is 3), but it doesnt put it in between the lines, to show that the unit can move there as well by turning. I am also hoping i can make terrain (like forests) that slow down units as well, so i would somehow need a system that calculates every possible route and creates circles of power along the way... :S I cant figure out how to do this....

anyways look at what i have already and any help you could give me would be great appreciated :)
(sorry for the double post btw, but i wanted to nudge the topic to make sure someone reads this, so they dont just see my thank you message and assume the problem has been solved :/ )
 

Attachments

  • Xeno Wars Core v1.0.w3x
    23.5 KB · Views: 38
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
Wait, sorry, what's the problem?

You want it to calculate every possible route, not only straight ones?

By the way, I think you stored into the array wrong. My formula was also wrong - it should be x*yLen + y... blegh

Here is a "diagram" of your points, with all their ideal array slots (this one assumes a 7x7 grid - 00 to 06)

(00)(01)(02)(03)(04)(05)(06)
(07)(08)(09)(10)(11)(12)(13)
(14)(15)(16)(17)(18)(19)(20)
(21)(22)(23)(24)(25)(26)(27)
(28)(29)(30)(31)(32)(33)(34)
(35)(36)(37)(38)(39)(40)(41)
(42)(43)(44)(45)(46)(47)(48)
 
Level 5
Joined
Jul 17, 2006
Messages
145
no, your first formula was right >_>

x+y*ylen will begin storing (1,1) at value 7, and each time the x increases it goes up by one, and each time the y increases it goes up by 6.
here:
(it is a 6X8 grid)
(1,8)(2,8)(3,8)(4,8)(5,8)(6,8)
(1,7)(2,7)(3,7)(4,7)(5,7)(6,7)
(1,6)(2,6)(3,6)(4,6)(5,6)(6,6)
(1,5)(2,5)(3,5)(4,5)(5,5)(6,5)
(1,4)(2,4)(3,4)(4,4)(5,4)(6,4)
(1,3)(2,3)(3,3)(4,3)(5,3)(6,3)
(1,2)(2,2)(3,2)(4,2)(5,2)(6,2)
(1,1)(2,1)(3,1)(4,1)(5,1)(6,1)
(notice how the number start low in the bottom left and increase as they go out. It must be in this form because all the coordinates of the graph are positive, and therefore they are all in quadrant 2. (or at least the top right one, i think thats quadrant 2) They start at 1 because i didn't really wanna use 0 in my graph, and because i wanted the x/y value to represent the number over it is (er, if i start at 0, point 0,3 is accualy the fourth point up and the fist point right - so its easer to visualize if i use 1,4 >_>))

point 1,1 is [7] in the array. point 2,1 is number [8]. the number of the array increases by one for every point to the right you would go on the graph

for every point up, the number increases by 6. therefore point 1,2 is 13.

in short, x+y*ylen counts the points from left to right. when it gets to point (6,1) it stores it as 12, and when goes up on on the graph and all the way to the left it stores it as 13.

x*ylen+y doesnt work because the point (1,8) would have the same array number as point (2,2), and there are other sets of re-occurring points.

anyways, if fixed my own problem (heh) (and yes, what you said was what my probem was >_>) by getting the coordinates of the unit selected, putting circles on each of the points next to it, then feeding the coordinates of each of those points back into the function so finds the coordinates of the points next to the newly created circles. every time it feeds the new circles into itself it increases a var by one, and when the var is greater then the number of steps the unit is supposed to have, it stops.

of course, i had to make a boolean array the same size as the grid array, to store a bool for each of the coordinates on the graph so it wouldn't create a circle on a point that already had a circle on it. pretty much whenever i made a circle i made the bool for that coordinates true, and so it cant create a circle on a point that already has a circle on it.

whenever you unselect the unit, it removes all the movement circles and resets the bool array.

no doubt i did a horrible job of explaining all of that (>_>), so heres my map so you can see how i did it:
 

Attachments

  • Xeno Wars Core v1.0.w3x
    23.8 KB · Views: 33
Level 5
Joined
Jul 17, 2006
Messages
145
because if i use a variable i can do a simple if then check, instead of writing out several lines of code each time, so its not as cluttered >_>
..also because i didnt know you could do that and now im to lazy to change it :D (at least for now anyways)

ok well i have a few more questions: is there any way that i can disable the "attack" and the "stop" abilities, to give the unit a blank er..ability slot thing thats to the right? I know that i can disable the move and patrol by making the units move speed 0. Im pretty much just planning on having the units move to the circles via a spell based off channel and triggering >_>
 
Level 5
Joined
Jul 17, 2006
Messages
145
alright thanks ^^

mm more problems... this code isnt working:

JASS:
function Trig_Move_Conditions takes nothing returns boolean
    return (GetSpellAbilityId() == 'A000')
endfunction

function Trig_Move_Actions takes nothing returns nothing
    local unit cast = GetSpellAbilityUnit()
    local location l = GetUnitLoc(GetSpellTargetUnit())

    call SetUnitOwner( cast, Player(PLAYER_NEUTRAL_PASSIVE), false )
    call SetUnitMoveSpeed( cast, 522.00 )
    call IssuePointOrderLocBJ( cast, "move", l )

    call RemoveLocation(l)
    set l = null
    set cast = null
endfunction

//===========================================================================
function InitTrig_Move takes nothing returns nothing
    set gg_trg_Move = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Move, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Move, Condition( function Trig_Move_Conditions ) )
    call TriggerAddAction( gg_trg_Move, function Trig_Move_Actions )
endfunction

its just the code that tells a unit to move after someone has used the "move" spells. It changes the unit to neutral so the player cant mess with the unit while its moving, then sets the move speed to max (i have it default to 0 so the player cant move the unit), and tells the unit to move. It works fine, except for some reason it doesnt change the move speed of the unit... :S
 
Last edited:
Level 5
Joined
Jul 17, 2006
Messages
145
hmm apparently if you have the move speed of a unit set to 0 it disables moving completely, and you cant change to move speed with triggers or anything. I can fix this by setting the move speed to max, and then giving the unit an ability that increases his move speed by -100%, and just take that away when i move, but then i have the "move", "stop", and "stand ground" buttons :S is there any way to get rid of those buttons without setting the move speed to 0?
 
Level 5
Joined
Jul 17, 2006
Messages
145
well, i suppose i could do it with dialogs, or would that be too annoying (in other words, whenever you click a unit, a dialog pops up that says like, Wait, move, or attack if your next to an enemy). whats your opinion :S
 
Status
Not open for further replies.
Top