• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] endloop?

Status
Not open for further replies.
Level 9
Joined
Nov 19, 2011
Messages
516
function Trig_QBenefit_Actions takes nothing returns nothing
set bj_forLoopAIndex = 1
set bj_forLoopAIndexEnd = 4
loop
exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
call AddHeroXPSwapped( udg_exp, udg_Hero[GetForLoopIndexA()], true )
call AdjustPlayerStateBJ( udg_gold, ConvertedPlayer(GetForLoopIndexA()), PLAYER_STATE_RESOURCE_GOLD )
set bj_forLoopAIndex = bj_forLoopAIndex + 1
endloop
RemoveInt(exp)
RemoveInt(gold)
endfunction

'endloop expected'. But where?
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
im not sure how the memory for them gets cleared but there is no destroy function. and u dont need to null them. Also u shouldnt use for each integer A instead create ur own variable. Integer A is less efficient.

Edit: are u coding in Jass or GUI ?

The problem with integer A is not efficiency.
There is only one problem with it - Overuse will make your triggers collide. Especially with loops.
If you consider this, then you can use it.
 
so what about memory? I have 2 vars that I need only for few sec...

A general rule of thumb: anything that you make with "Add" or "Create" should be destroyed/removed when you no longer need them. (except for trackables, but that is because the API for them is somewhat incomplete)

Integers, booleans, strings, reals, and code are not handles; you don't need to worry about clearing them from memory.

Also, if you are using JNGP, then note that any function that is highlighted in purple is a native and any BJ is red. If the function name isn't highlighted (such as if you were to type RemoveInt()), then either that function doesn't exist or it is one you defined yourself. You can use the "function list" tool in TESH to look up functions.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
@ Xonok
didnt i show u b4 that integer A is less efficient ? Remember if u use a create units in each loop and display the integer that integer A always runs less instances when u hit the op-limit than ur own integer does.
When I compare the loops (whether it is variable increment, unit creation or whatnot), both hit the OP limit at the exact same moment.
Could you perhaps verify this again (and either show the test-code or upload the test-map)?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
here u go just start it up and wait till after u see all the tempInt messages on the screen. Then wait about 1 second and press the Esc button to see the different values.
The reason this happens is because of this here:
JASS:
call DisplayTextToForce( GetPlayersAll(), ( "Integer A = " + I2S(GetForLoopIndexA()) ) )
To be more precise: GetForLoopIndexA(). Replacing this with the bj solves it all.

The variable itself ("bj_forLoopAIndex") isn't slower/less efficient by any means, but the BJ is.
Because of that, you are indeed correct :D (as you nearly always use that BJ in an A/B-loop).

But that's enough derailing for one thread.
 
Status
Not open for further replies.
Top