• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[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 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