Macro help with setting a global variable

I have this macro that works:

/script global.targetName = UnitName("target") /script print(targetName)

It sets the global variable, targetName, to whomever I’m targeting, and then displays their name in my chat frame. Works perfectly.

However, when I run this code:

/script global.tankName = UnitName("target") /script print(tankName)

It does not seem to want to set the variable, and is showing “nil” in the chat frame.

Any ideas on why “targetName” works, but “tankName” does not? I mean, it’s literally the only thing that changes between the two macros…

UPDATE:

Well, despite Capella’s unhelpful remarks, I found out how to set a global variable (for those who may be new to macros like myself.

It seems that “global” in:

/script global.tankName = UnitName("target")

has been causing some problems, but if I run it without “global”:

/script tankName = UnitName("target")

it seems to work fine. I have one macro setting the tankName variable, and another macro using the tankName variable, so I’m assuming it’s automatically a global variable.

what makes you think global interface has tankName as an acceptable method option? :expressionless:

ChatGPT :stuck_out_tongue:

Is there a way to create a custom global variable then with a name of my choosing?

/run VariableNamedInSuchAWayThatNothingElseWillAccidentallyUseIt = UnitName("target")
/run print(VariableNamedInSuchAWayThatNothingElseWillAccidentallyUseIt)

That said, depending on what you’re trying to do there’s probably a much better way. I also recommend posting in UI and Macro next time, you’ll get more helpful responses.

1 Like