HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

What's the effect of overlapping a variable definition?

02-19-2004, 05:37 PM#1
RaeVanMorlock
I have basic variables setup for ease of use with the trigger GUI -- like _integer, _unit, _string, etc... type of stuff.

My problem is that, from time to time (even without wait statements in place), a trigger will be so long, and so much will be happening, that another trigger will start to fire and overwrite the value of those global variables -- hence totally screwing up the trigger that started first.


I had an idea that, at the beginning of each trigger (especially the longer ones), I'd do Custom Script: local integer udg__integer and stuff like that to redeclare each global variable as a local version of it, hence "fooling" the GUI to reference the global version and use the local version.

I haven't the time or thought to be able to test this -- so does anyone happen to know if you WC3 has a variable presidence like that? -- If it will use local variables before global variables of the same declaration name?
02-19-2004, 06:53 PM#2
Cubasis
YES!

This is exactly hwat many people are using at the moment and has been known for a while. doing a custom-script action to declare a local variable with the name of a global WILL allow you to reference "the local" by using the global in the GUI windows.

But just to add, the only way another trigger jumps in and messes up your global variables is...you having "waits"... Two threads (triggers) can not run at teh same time, so the only way to allow another trigger to run is either to wait, or finish the trigger.

Cubasis
02-19-2004, 07:50 PM#3
RaeVanMorlock
Good stuff -- I'm almost certain I had the porblem with using waits, but seeing as how it's fixed now, I can't refer to what it was ^_^ Since I'm all but recreating my map now, I'll let ya know if I come across it again. Good times, definitely good times...




Okay, I got a problem

Code:
Arced Fire
    Events
        Unit - A unit Begins channeling an ability
    Conditions
        (Ability being cast) Equal to Arced Fire 
    Actions
        Custom script:   local integer udg__integer
        Custom script:   local integer udg_IntegerA
        Custom script:   local unit udg__unit
        Custom script:   local player udg__player
        Set _integer = 20
        Set _unit = (Casting unit)
        Game - Display to (All players) the text: (Unit:  + (Name of _unit))
        Set _player = (Owner of _unit)
        For each (Integer IntegerA) from 1 to 90, do (Actions)
            Loop - Actions
                Game - Display to (All players) the text: (Player:  + (Name of _player))
                Game - Display to (All players) the text: (Unit:  + (Name of _unit))
                Game - Display to (All players) the text: (String(IntegerA))
                Unit - Create 1 Peasant for _player at (Position of _unit) facing Default building facing degrees
                Wait 1.00 seconds

If I remove the 4 custom script lines that redefine the variables, then this works -- but as it is now... once it enters the loop, it's like it forgets the values.

More oddly, if I change the the udg_IntegerA to udg__IntegerA, then _player works, but _unit still doesn't.
02-20-2004, 12:21 AM#4
RaeVanMorlock
*bump*
02-20-2004, 05:02 AM#5
Extrarius
The wierd local type Bug
02-20-2004, 11:58 AM#6
Cubasis
Yes, unfortunately, that completely wacky bug has been found comming up when doing this kind of stuff.

As you can read from that thread, we want to think that initiating these locals from start fixes this, but...we have yet to test it well enough.

So....erhm,

*runs*