Local variables

Sui-cookie

You can change this now in User CP.
Reaction score
49
If you have too many global, pre-defined, variables in a map, trigger's stop working. Are local variables counted into this?

if i have 15 max arrayed local variables, would my triggers cease to work? :confused:
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
I can imagine a situation, where the initialization trigger tries to initialize too many arrays, resulting in reaching operations limit.

Can you post your initialization triggers and a more precise problem description besides "it doesn't work"?
 

Bribe

vJass errors are legion
Reaction score
67
I'm curious what benefits would be had by maximizing an array of local variables :O

As a programmer's curiosity, I wonder if local arrays are deallocated after the endfunction line...
 

Sui-cookie

You can change this now in User CP.
Reaction score
49
i have no triggers =p i was just curious if by usuing as many local variables as i can, instead of globals, if i could get away with a few thousand more variables :p

Since globals have a limit before they get'cha in the ear when your not looking D: Was wondering if locals counted toward that :]
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
What kind of a limit are you talking about? There is no limit to the number of declared variables. At least, you'll never reach it...

If you're talking about array index limit, then the last safe index is 8190, starting from 0.
 

Sui-cookie

You can change this now in User CP.
Reaction score
49
Yes, look:
Its a map that has:
Trigger:
  • Untitled Trigger 001
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Unit - Explode Footman 0001 <gen>

As it's only trigger.
However, it has five global arrays of maximum size.
The trigger doesn't work unless you get rid of some of them.
 

Attachments

  • blub.w3x
    16 KB · Views: 155

Flare

Stops copies me!
Reaction score
662
I don't have World Editor at the moment, but did you toggle the Initial Value (or Set Default, something along those lines) checkbox when creating those variables? If so, the initialization of all those variables is likely to result in the operations limit being hit, which will prevent the initialization of anything that's being initialized after those variables.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Or, maybe if you set the Maximum Size of those arrays to something bigger than the actual limit, as the limit is 8191 (8192) so have you set it to something bigger than that ?
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
You are actually crashing the "main" thread.

JASS:
globals
    // User-defined
    integer array           udg_p
    boolean array           udg_a_B
    texttag array           udg_f
    damagetype array        udg_mmmhm
    integer array           udg_jfj

    // Generated
    trigger                 gg_trg_Untitled_Trigger_001 = null
    unit                    gg_unit_hfoo_0001          = null
    trigger                 gg_trg_Untitled_Trigger_002 = null
endglobals

function InitGlobals takes nothing returns nothing
    local integer i = 0
    set i = 0
    loop
        exitwhen (i > 8192)
        set udg_a_B<i> = false # this is not required at all booleans are false by deafult
        set i = i + 1
    endloop

    set i = 0
    loop
        exitwhen (i &gt; 8192)
        set udg_jfj<i> = 0 # this is not required at all integers == 0 by deafult
        set i = i + 1
    endloop

endfunction</i></i>


JASS:

function main takes nothing returns nothing
    .
    .
    .
    call InitGlobals(  )
    call InitCustomTriggers(  )
endfunction


InitCustomTriggers was never executed because the InitGlobals crashed the thread.

ExecuteFunc is your friend in such scenarios that require a lot of processing.
 

Ashlebede

New Member
Reaction score
43
There can be only one global block per map, no exceptions, unless you use vJASS... which will place your triggers' globals at the top of the map, so... yeah. Globals can't be declared after a function / in different blocks.
 

Sui-cookie

You can change this now in User CP.
Reaction score
49
That sucks.

But back to my main point, being as the global variable's problem is loading them all at once, local variables shouldn't have to abide by this at all, would they?

to a degree, of course. I doubt 50,000 local variables running in very close intervals is going to do Warcraft much good >.<
 

Ashlebede

New Member
Reaction score
43
Local variables are created upon function call and removed when the function ends... I think, for the removal. Anyhow, they are less trouble upon startup but will make your function with locals take a little more time to execute, especially when it is, say, a group variable and you want to create a new group everytime, whereas with a global you could just directly add units to your group, if you're going to re-use it. It depends on the number of times your triggers will fire, since globals increase loading time. u_u
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top