Is there any way to detect the global variables have been updated?

 

Excuse me, everyone.

I met a problem when dealing with the global variables. I wish you could give me a hand.

I defined a global variable using

GlobalVariableSet("userinput_01", 0);

I wish EA could detect whether the global variable has been updated or not.

I mean, even if the user has entered the same number, for example, 0, the EA could still detect the global variable has been updated, although its value is not changed.

Thank you so much!

 

Use an auxiliary variable to signal the update_event:

GlobalVariableSet("userinput_01", 0);

GlobalVariableSet("userinput_1_updated", 1); // signal the event


The EA could then inspect this variable and react to the event:

if( GlobalVariableGet("userinput_1_updated")!=0)

{

----- // develop/call your routine(s) here.

----- GlobalVariableSet("userinput_1_updated", 0); // make it ready for another change

}


By the way, this is a technique called Synchronization in Software Engineering. Semaphores are the adequate approach for handling these aspects.


Regards

AM.

 
abstract_mind:



Use an auxiliary variable to signal the update_event:

GlobalVariableSet("userinput_01", 0);

GlobalVariableSet("userinput_1_updated", 1); // signal the event


The EA could then inspect this variable and react to the event:

if( GlobalVariableGet("userinput_1_updated")!=0)

{

----- // develop/call your routine(s) here.

----- GlobalVariableSet("userinput_1_updated", 0); // make it ready for another change

}


By the way, this is a technique called Synchronization in Software Engineering. Semaphores are the adequate approach for handling these aspects.


Regards

AM.


abstract_mind

Thank you very much for your reply.

I am sorry, but I could not understand your example.

The problem here is how to record the event that the user has updated the global variable, no matter what values he/she has entered.

 
blackkettle:


The problem here is how to record the event that the user has updated the global variable, no matter what values he/she has entered.


Do you mean if the User changes the value using F3 ?
 
RaptorUK:

Do you mean if the User changes the value using F3 ?

RaptorUK,

Yes, you are so right.

Is there any way that could help me out?

Thank you!

 
blackkettle:

RaptorUK,

Yes, you are so right.

Is there any way that could help me out?


If I could I would, but I don't think there is an easy way, you would need to find where the Global Variables are stored and monitor that file for changes.
 

Changing the variable by hand, F3 and so on, still works. Instead of one, you just need change two variables:

GlobalVariableSet("userinput_01", 0); // your variable, it was 0 before, so it is a "change" to the same value.

GlobalVariableSet("userinput_1_updated", 1); // the secnd variable is to tell the EA that the other variable has new value.

These two lines can be replaced by hitting F3 and setting the values by hand.

-----------------

The code below must be inside your EA, e.g, in the start() function, in order to detect the variable change:

-----------------

The code in your EA just needs to detect "userinput_1_updated" changed to value 1

if(GlobalVariableGet("userinput_1_updated")==1)

{

----- put your code here

----- GlobalVariableSet("userinput_1_updated", 0); // prevent from repeating this code on each subsequent tick. Also, the EA is again prepared for another change

}


Regards.

AM.

 
abstract_mind:


Changing the variable by hand, F3 and so on, still works. Instead of one, you just need change two variables:

GlobalVariableSet("userinput_01", 0); // your variable, it was 0 before, so it is a "change" to the same value.

GlobalVariableSet("userinput_1_updated", 1); // the secnd variable is to tell the EA that the other variable has new value.

These two lines can be replaced by hitting F3 and setting the values by hand.

-----------------

The code below must be inside your EA, e.g, in the start() function, in order to detect the variable change:

-----------------

The code in your EA just needs to detect "userinput_1_updated" changed to value 1

if(GlobalVariableGet("userinput_1_updated")==1)

{

----- put your code here

----- GlobalVariableSet("userinput_1_updated", 0); // prevent from repeating this code on each subsequent tick. Also, the EA is again prepared for another change

}


Regards.

AM.



abstract_mind,

Thank you so much for your example.

I am so appreciative.