• 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] For x to x loop

Status
Not open for further replies.
Level 16
Joined
May 1, 2008
Messages
1,605
Seas =)

So I want to create units with the A Loop functions.

In GUI it would look like:
  • For each (Integer A) from 1 to 36, do (Actions)
    • Loop - Actions
      • Set TempArray[(Integer A)] = (TempPoint1 offset by 450.00 towards (10.00 x (Real((Integer A)))) degrees)
Now in Jass I used this:
JASS:
set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 36
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set udg_TempArray[bj_forLoopIndexA()] = PolarProjectionBJ(udg_TempPoint1, 450.00, ( 45.00 * I2R(GetForLoopIndexA()) ))
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop

1) I use this bj_forLoopIndexA because JNGP don't mark it with red so I think its ok. Now I want change "PolarProjectionBJ". I asked the function list and WTF! is this:

bf67q77bogvq3m6yl.gif

Sorce? dist + Cos and Sin and angel + bj_what?

And please - you know that my english isn't that good so try to explain it that a stupid-stupide one can understand it =P
 
Ok, just use a local instead of the bj_loop thingy :O

PolarProjectionBJ uses coordinates.
The entire wc3 map is a huge coordinate system. Each position has it's own, unique and individual x- and y-coordinates.

GetLocationX(source) takes the original location and gets it's x-coordinate. The part after it are calculations. If you don't understand the math, just accept that you have to add "distance*Cos(angle)". The distance is the distance you type into the GUI stuff. Cos is short for Cosinus, an algebraic function (spelled like this?).
It looks like this:
url

the angle is the angle you typed again in the GUI window. It is multiplied with bj_DEGTORAD. bj_DEGTORAD is a value that calculates degrees into radians (bj_DEG(rees) TO RAD(ians)). For the y-coordiante the same is done with sin(us).

Example: GUI - Create a new point called "NewPoint" from "OldPoint" offset 1000 in an angle of 45.
-> Jass
JASS:
local real x = GetLocationX(OldPoint)
local real y = GetLocationY(OldPoint)

set NewPoint = Location(x+1000*Cos(45*bj_DEGTORAD), y+1000*Sin(45*bj_DEGTORAD))
 
Level 11
Joined
Apr 6, 2008
Messages
760
bj_forLoopIndexA is a global

i rather use a local integer instead

and for polarprojection the correct formula is

JASS:
x = GetLocationX(Loc)+450*Cos((10*Index)*bj_DEGTORAD)
y = GetLocationY(Loc)+450*Sin((10*Index)*bj_DEGTORAD)

small eg.

JASS:
function Action takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local real x2
    local real y2
    local integer index = 0

    loop
        exitwhen index >= 36
        set x2 = x+450*Cos(10*index*bj_DEGTORAD)
        set y2 = y+450*Sin(10*index*bj_DEGTORAD)
        //Do the stuff at that cords
        set index = index + 1
    endloop

    set u = null
endfunction
 
Status
Not open for further replies.
Top