• 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] local integer in an integer loop?

Status
Not open for further replies.
Level 28
Joined
Mar 25, 2008
Messages
2,955
So, i got this loop using a local integer (C)
JASS:
    set C = 1
    loop
        exitwhen C > 8
        set x = ( x + 45.00 )
        set div_cross_ball_pkt_create = PolarProjectionBJ(divine_cross_caster_punkt, 500.00, ( x + 45.00 ))
        call CreateNUnitsAtLoc( 1, 'o01Q', GetOwningPlayer(GetTriggerUnit()), div_cross_ball_pkt_create, bj_UNIT_FACING )
        set judgement_blitz_anfang[C] = GetLastCreatedUnit()
        set divine_cross_ball_punkt[C] = GetUnitLoc(judgement_blitz_anfang[C])
        set C = C + 1
    endloop
Is this even possible or do h have to use a global variable for that?
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
no, a local loop variable is just fine, though I think a global one would be more efficient (not sure about that though)
The loop itself would be much more effecient if you used native functions :)
 
Level 28
Joined
Mar 25, 2008
Messages
2,955
Huh? What is a native function? o_O
The problem with that loop is, it doesn't work - so i thought, it could be caused by that local integer.. i've set all the important locals at the start but nothing happens..
JASS:
    local location divine_cross_caster_punkt
    local location div_cross_ball_pkt_create
    local location array divine_cross_ball_punkt
    local unit array judgement_blitz_anfang
So, what's wrong?
I'm sure, I forgot something
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
no, a local loop variable is just fine, though I think a global one would be more efficient (not sure about that though)
Although the difference would be negligible, I'm pretty sure a local loop variable is more efficient than a global loop variable.

Squiggy, have you actually initialized the locations?
I also don't see c declared at all. Have you written
local integer C = 1 somewhere?
In WE newgen you can see if a function is native by looking at the function. If it's preceded by the word "native", then it's a native. Non-native functions are functions with a visible body, that use natives instead and are usually less efficient than simply using the natives directly.

For instance:
JASS:
function IsUnitDeadBJ takes unit whichUnit returns boolean
    return GetUnitState(whichUnit, UNIT_STATE_LIFE) <= 0
endfunction
This function is not a native function, it checks the unit state of a unit and returns true if it's less than 0. Instead of using "if IsUnitDeadBJ(unit) then", you could just as easily use
'if GetUnitState(whichUnit, UNIT_STATE_LIFE) <= 0 then"
because GetUnitState is a native function.
 
Level 28
Joined
Mar 25, 2008
Messages
2,955
to be honest, only part of it, as it seems.
I declared
JASS:
local integer c
at the beginning, but i didn't know that it was necessary to do it like
JASS:
local integer c = 1
because there's a set C = 1 above the loop..
You think that's it?
And thanks for the explanation ;)
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
hm, abd I dont know if you are doing it on purpose or not, but since Jass is case sensitive a declared "c" will not be interpret as a "C". Maybe that could be a reason why it wouldnt work.
 
Status
Not open for further replies.
Top