How do I convert a local variable to a global one?

Endercraft

Moderator (& bug finder :D)
If you need to write a local variable value to a global variable you can select the global variable in th I set variable action the use [lv=localvar] for example.
If you want to make a local variable global you can create a global variable with the same name as the local one which you will delete when the global is created.
 

dreamily9724

New member
If you need to write a local variable value to a global variable you can select the global variable in th I set variable action the use [lv=localvar] for example.
If you want to make a local variable global you can create a global variable with the same name as the local one which you will delete when the global is created.
Thank you!
 

dhj49er

Well-known member
So no conversion, which would be good if the feature ever gets implemented.
The new global variable must either be created in a different macro to the macro with the same named local variable or via the Variables list.
Deleting the local variable will also apply to all actions which use the local variable.
When I need to convert a local variable to global, I create a new global variable with similar name. I then edit the macro and change all instances of the local variable to use the newly created global version.
Once this is complete, run the macro to confirm it works with the new global variable. Then I delete the local variable and finally rename the global variable to the deleted local variable name.
It sounds more long winded than it is, but I do try to avoid it!
 
Last edited:

Endercraft

Moderator (& bug finder :D)
It won't work with magic text of course but to all other actions it will work.
There is no indication in macro data that a variable is local of global. It will set the variable that it finds, whether it's local or global.
You can also create a global variable with the same name as a local variable in a macro and it shouldn't cause many issues.
 

Endercraft

Moderator (& bug finder :D)
Nevermind, there is a JSON entry for defining a local variable ("isLocalVar").
Here's an example of variable data :
JSON:
{
  "dictionary": {
    "entries": [],
    "isArray": false,
    "variableType": 4,
    "type": "Dictionary"
  },
  "isActionBlockWorkingVar": false,
  "isLocalVar": true,
  "m_booleanValue": false,
  "m_decimalValue": 0,
  "m_intValue": 2,
  "m_name": "var",
  "m_stringValue": "",
  "m_type": 1,
  "supportsInput": false,
  "supportsOutput": true
}

Note that the dictionary data (which also works as array) is still there even if it's not a dictionary/array variable. It's also the same for all other data such as m_booleanValue, m_decimalValue, m_stringValue.
Oh well..

But this entry actually never comes into play unless no local/global variable with that name exists. If it is marked as local var it will still check for a global variable if local doesn't exist and set the global variable if it exists.
 
Top