• 🏆 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!

[Trigger] What's the use of this ?

Status
Not open for further replies.
Level 6
Joined
Sep 13, 2013
Messages
155
For each integer A, Do actions
For each integer B, Do actions
For each integer variable, Do actions

I wonder when to use this functions. I just don't know what they exactly do. little explain please ?
 
You can make:
  • Unit - Kill Hero[1]
  • Unit - Kill Hero[2]
  • Unit - Kill Hero[3]
  • Unit - Kill Hero[4]
  • Unit - Kill Hero[5]
  • Unit - Kill Hero[6]
  • Unit - Kill Hero[7]
Or you can use this loop function:
  • For each (Integer A) from 1 to 7, do (Actions)
    • Schleifen - Aktionen
      • Unit - Kill Hero[IntegerA]
Both will do the same.

So you see with using this you can short your code, and it's easier to modify it.

Edit:
You can use Integer A, Integer B or your own Integer variable as you already noted.
Using your own Integer variable is recommended.
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
Integer A/B are slower and less efficient. They can also create bugs in your map when using them.

Please elaborate. Why are these slower?
A/B are just global variables passed by a function defined in Blizzard.j. If you optimize your map these functions get inlined and there is no difference to other integer globals. In fact if you always use A/B you get a smaller globals block which saves memory (not saying that the difference is noticable, but at least it shouldnt be slower).

Also, what bugs? Im curious...
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,184
Please elaborate. Why are these slower?
A/B are just global variables passed by a function defined in Blizzard.j. If you optimize your map these functions get inlined and there is no difference to other integer globals. In fact if you always use A/B you get a smaller globals block which saves memory (not saying that the difference is noticable, but at least it shouldnt be slower).

Also, what bugs? Im curious...

since the variable the loop use is global it cant be used at the same time from 2 different triggers.
 
Based on experience of many people, using A/B even just in successive loops causes bugs SOMETIMES, which when you used a normal Global, it works fine... maybe it has something to do with how A/B were coded by the makers of wc3 or something...

for example: this bugged for some

For Integer A
For Integer B

-> The for integer B didn't run for some reason

but this one worked completely fine

For Integer (X)
For Integer (Y)

and as most people experienced, it was kind of random... random in a sense that it just suddenly happens for some triggers...
 
Level 7
Joined
Mar 6, 2006
Messages
282
and as most people experienced, it was kind of random... random in a sense that it just suddenly happens for some triggers...

Probably because it was overwritten somewhere.

@muzzel

I guess people say "they're bugged" because they have a high potential to cause bugs and it's safer to use a local iterator or a custom global iterator.

IcemanBo said:
Wait.. you say A/B are bad because they are globals, and in other way using own global variables is better? :eek:

Yeah, so you wanna do

  • For each (Integer myInteger) from 1 to 10, do (Actions)
    • Loop - Actions
 
Nope... It even happens when you don't have any other A/B loops... and also, because everything is "instant", even if you had, it shouldn't even been overwritten... coz if that's the case, then most systems that share a certain set of globals would have had those bugs as well...

anyway, some people experienced it, some don't... but as always, better work safely, so avoid them as much as possible...
 
Ok, but I doubt we will find someone like this.. because I guess it's only problem of wrong usage.

Sure it will bug, if you use Loop Integer A + wait and in other trigger you also use a loop with Integer A at same time.

But we just talk about the comparrison of one custom variable with Integer A.. of course both have to be used correctly.

I might be wrong with this, anyone who reads this is welcome to show me the opposite.
 
Nah, even I experienced it in a trigger without any waits (maybe 3 years ago or something)... nor any other trigger that uses them... just a single trigger doing

Integer A
Integer B

but since the chances of it is quite small, it might be hard to find someone right now... anyway, as I have said so many times before, better safe than sorry... Using your own var will probably has less chance of wrong usage anyway
 
That's the weird thing about it, it was random...

theoretically yes, same algorithms should work the same always...

but from my experience working with other engines... sometimes, they have these weird bugs too... like you test your code, it doesn't work... then you just stare at it, test again and suddenly it works...

it might be some inconsistencies or internal speed problem probably where we have no control over...
 
Depends, maybe you would not need anywehere else varibales maybe, so why create one for only this loop.

And why saying, custom variables is safer, only because someone says A/B is bugged and cant prove it.

When I would say: Never name your variables "apple", sometimes it will cause random bugs." , you would recommend not to use "apple" as a variable.. even it's not proven.
 
IDK, but normally in programming/scripting languages, you do use your own variable when you make loops... so it's not really that kind of not normal thing to do...

Plus using a custom variable just for that loop is always safer than using a global one... [not talking about locals exactly, but rather a global that is used only for that coz this is in GUI... of course if it's in JASS/vJASS, then we'd suggest just using locals for that]

anyway, there have been some threads for those bugs... you could try searching for them if you really want to look deeply into it...
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
For the bug some of GUIs BJs use them in the BJ. It then messes them up without the person knowing. They also seem to mess up when doing simple nested loops and other things.

Also this never gets inlined.
JASS:
function GetForLoopIndexA takes nothing returns integer
    return bj_forLoopAIndex
endfunction
The above is what is called every time you use Integer A as an index or anything else.

This has been discussed many times. This is also in my tutorial things a GUIer should know.

They should not be used and they are less efficient. Just because they are globals has nothing to do with it. It is the way they are used by us and by blizzard.

The randomness is also thought of to be a result of Blizzard using it for some things that run in game that we can't control.

I have experienced times were using it have bugged.
Like a nested Integer a then integer b loop.
Where when testing i found out counted like this. Both were set from 1 to 10.
int A = 1
int B = 1
int B = 2
int B up to B = 10
Then when the A = 2 was supposed to start it jumped to 6 and continued.
Note the only thing in the loop was the game display message. No waits and no other triggers of any type in the map.
Then i tried doing same thing with new map and it worked fine. But with all of the bugs about it it just isn't worth using.
 
It is useful but should never be used.

Do not use integer A / B create your own integer and use the action that says this. For each integer variable, Do actions

Integer A/B are slower and less efficient. They can also create bugs in your map when using them.
Generally I just mean, that saying like this might be well.. but as I've seen him posting this more often, I just asked myself.. why he is so sure that it's less efficient and can cause bugs.

I believe that wc3 can have bugs. And maybe yes, maybe IntegerA/B can be bugged under special circumstances. But if so, I would be interested which they are.

Until that I'm out of here, already spammed this thread too much.. sorry for that. :wwink:
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
Generally I just mean, that saying like this might be well.. but as I've seen him posting this more often, I just asked myself.. why he is so sure that it's less efficient and can cause bugs.

I believe that wc3 can have bugs. And maybe yes, maybe IntegerA/B can be bugged under special circumstances. But if so, I would be interested which they are.

Until that I'm out of here, already spammed this thread too much.. sorry for that. :wwink:

I updated post above.

Also yes i say it just like i pick out leaks or anything else with code.

Look at my tutorial things a guier should know for info on why it is slower. I do not have a definite example of it bugging everytime i try to save a map here the bug is fixed when i redownload the map. By it is to random to be worth using it.
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
IDK, but normally in programming/scripting languages, you do use your own variable when you make loops... so it's not really that kind of not normal thing to do...

In normal programming language you have local variables with a scope, which means you dont have to care about overwriting the variable from somewhere else.

But im done with this discussion, either the bug exists or it doesnt, there is no need to discuss this.
My original post was adressed to deathismyfriends post who came up with wild accusations about Int A/B being slow and buggy without providing any further information.

For the bug some of GUIs BJs use them in the BJ. It then messes them up without the person knowing.
Which BJ function uses "bj_forLoopAIndex" or "bj_forLoopBIndex" except for the respective getters/setters? Because this is the file that contains all BJ functions and it doesnt contain other functions which use IntA/B.

Also this never gets inlined.
It does. If i may quote JassHelperManual:

How to make a function inlineable? The current algorithm basically follows these rules (which are subject to change to allow more functions to be considered inlineable in the future):

The function is a one-liner
If the function is called by call the function's contents must begin with set or call or be a return of a single function.
If the inlined function is an assigment (set) it should not assign one of its arguments.
Every argument must be evaluated once and only once by the function, in the same order as they appear in the arguments list.
If the function contains function calls, they should all be evaluated after the arguments UNLESS the function is marked as non-state changing, at the moment some very few native functions and also return bug exploiters are considered as non-state changing.

I have experienced times were using it have bugged.
Like a nested Integer a then integer b loop.
Where when testing i found out counted like this. Both were set from 1 to 10.
int A = 1
int B = 1
int B = 2
int B up to B = 10
Then when the A = 2 was supposed to start it jumped to 6 and continued.
Note the only thing in the loop was the game display message. No waits and no other triggers of any type in the map.
Then i tried doing same thing with new map and it worked fine. But with all of the bugs about it it just isn't worth using.
Attach a testmap that shows the bug, otherwise im not interested.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
Well then muzzel you never do listen to anyone. I have heard of this bug many times. I don't code in GUI anymore nor will i ever use integer A / B.

Also you say they get inlined then run this map. And notice how it does not get inlined.

Wait till lag stops then press ESC to notice the numbers displayed.

Integer A displays 1808
tempInt displays 1841

Both triggers have same things. One uses integer A one uses tempInt and integer A loop breaks before the tempInt
 

Attachments

  • integer A vs tempInt.w3x
    12.7 KB · Views: 48
Level 14
Joined
Jun 27, 2008
Messages
1,325
I just checked the output jasshelper creates.
The Getter and Setter functions get inlined, however the bj_forLoopAIndexEnd variable doesnt:

JASS:
function Trig_Integer_A_Actions takes nothing returns nothing


    set bj_forLoopAIndex = 1

    set bj_forLoopAIndexEnd = 9999

    loop


        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd

        set udg_tempPoint1 = GetRectCenter(GetPlayableMapRect())

        call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), udg_tempPoint1, bj_UNIT_FACING )


        call RemoveLocation( udg_tempPoint1)

        call DisplayTextToForce( GetPlayersAll(), ( "Integer A = " + I2S(GetForLoopIndexA()) ) )

        set bj_forLoopAIndex = bj_forLoopAIndex + 1

    endloop

endfunction
 
Status
Not open for further replies.
Top