• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Serious Trigger Failure {Some problem involving dialogs}

Status
Not open for further replies.
It seems lately I've been completely out of it (first with the models) and now this.

I've created a VERY basic triggering system that seems to fail miserably.

Trigger-7.png


Now before I started using if-then-else it destroyed the main dialog and then re-created the whole thing.

I thought that because the trigger was destroying a dialog that didnt exist (on the first fire) that it was causing problems..

After realizing that wasn't the issue with this implementation, I'm really out of ideas.

I set the trigger to writeout to see if it was a dialog < - > dialog item issue but it seems it's not, because every 2 seconds it is infact creating a new dialog item and destroying the old one.

So what's left? The basic arithmetical equation of 'Set Year = (Year + 10)'? Doubtful, but I changed it to 'Set Year = (+ (10)) just to see, and it worked. Every 2 seconds it changed the year to exactly 10, but no more.

The dialog shows a year of -1000, which tells me the first arithmetic value is indeed firing, taking it from -1010 to -1000, but it wont go any higher than that.

It seems 'Set Year = (Year + 10)' isn't updating (Year + ... ) to it's new current value of being +10 more than the previous fire and instead keeping the initial -1010.

So wtf am I doing wrong? It's probably something obvious but I'm getting frustrated at this trigger that was supposed to take me 60 seconds to whip together.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Do you really want Year to be a local variable? I am sure you want it as a global variable.

Locals persist only the length of the function call and are allocated in the current stack frame for the executing thread. This means that each time the function is called you are setting year to be -1010 and then adding 10 to it. This value is constant and matches the problem you describe.

Galaxy does not support static locals which are function specific globals so you will need to allocate a normal global to be year. Globals are stored on the heap and thus share the same data to any function called by any thread. Multi-threaded synchronization is of no concern in SC2 as only 1 thread will run at any time and there is no time splicing.

I advise checking if you mean the other variables to be locals as well. The dialog and dialog buttons for example might be better off in a global as you may need to access them between function calls and across many functions.
 
Well I just whiped out my trigger and started from scratch:

  • Events
    • Timer - Every 1.0 seconds of Real Time
  • Local Variables
    • Year = 0 <Integer>
  • Conditions
  • Actions
    • Variable - Modify Year: + 1
    • UI - Display ("Year: " + (Text(Year))) for (All players) to Debug area
And discovered what you just said the hard way.
/facepalm
Thank you, DSG. I was keeping them local to clean up clutter on my trigger list.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
There is a major structural difference between locals and globals. The big one is that locals are dynamically allocated while globals are statically allocated.

A good idea would be to group like globals and components into the same folder and name them in a way that namespace collisions are not likely. You can use structs (GUI they are Records) to bind related values into a single global. The problem with structs is that Galaxy does not support pointers or bulk copying of structs so you cannot pass a struct as a function parameter.
 
Status
Not open for further replies.
Top