Determine variable/attribute based on string value

Is the following possible:

  • set value of a string variable myString = “myUnitAttribute”
  • change unit attribute myUnitAttribute using the string to determine which attribute to write to
  • then set value of a string variable myString = “myOtherUnitAttribute”
  • change unit attribute myOtherUnitAttribute using the string to determine which attribute to write to

2 and 4 should be same line of script except it writes to a different attribute because the value of string changed.

2 Likes

Not exactly sure what you’re trying to do but, try using Number type instead of String type

1 Like

It should be possible, but Variable isn’t an option when choosing attribute types in the script editor (there’s only Constant and Function).

So you can just put a variable value in the raw JSON instead. Here’s a script that I made that will do what you’re looking for, though it has to use the attribute ID which is always 10 random letters, not a readable name:


Raw JSON for the script
{
     "triggers": [],
     "conditions": [
          {
               "operator": "==",
               "operandType": "boolean"
          },
          true,
          true
     ],
     "actions": [
          {
               "type": "setVariable",
               "value": "N5upjRkzQU",
               "variableName": "tempString"
          },
          {
               "type": "sendChatMessageToPlayer",
               "message": {
                    "function": "concat",
                    "textA": "The value of your attribute ",
                    "textB": {
                         "function": "concat",
                         "textA": {
                              "function": "getVariable",
                              "variableName": "tempString"
                         },
                         "textB": {
                              "function": "concat",
                              "textA": " is: ",
                              "textB": {
                                   "function": "getPlayerAttribute",
                                   "attribute": {
                                        "function": "getVariable",
                                        "variableName": "tempString"
                                   },
                                   "entity": {
                                        "function": "getTriggeringPlayer"
                                   }
                              }
                         }
                    }
               },
               "player": {
                    "function": "getTriggeringPlayer"
               }
          }
     ],
     "name": "i6ObuMrpC9",
     "parent": null,
     "key": "i6ObuMrpC9",
     "order": 2
}
2 Likes