Is it possible to use $index in value names?

There’s a good chance I am overcomplicating this.

I want to generate x number of values where x=the expression of a repeat.

I want the name to be card+$index+_id. It works for the value but the name field won’t allow special characters.

Just to explain what I am trying to do - I generate a random 4-digit long number and look up in the database what item fits the number. In the database I have two fields, range_bot and range_top. This lets me set odds for the items. For example, I could have item 1=0-999 item2=1000-4999 and item3=5000-9999. Then if the number given back is 3894 it would be item2 and it would save the id for that item in a value.

I want to repeat that action a certain number of times and set a value each time. How can I/is it possible to make the name of the variable created be different each time? Preferably named after the $index value.

Here is the code for my action if needed

{

  "meta": {

    "$_GET": [

      {

        "type": "text",

        "name": "game_id"

      }

    ]

  },

  "exec": {

    "steps": [

      {

        "name": "numbers_string",

        "module": "core",

        "action": "setvalue",

        "options": {

          "value": "0,1,2,3,4,5,6,7,8,9"

        },

        "meta": [],

        "outputType": "text",

        "output": true

      },

      {

        "name": "numbers_array",

        "module": "core",

        "action": "setvalue",

        "options": {

          "value": "{{numbers_string.split(',')}}"

        },

        "meta": [],

        "outputType": "text",

        "output": true

      },

      {

        "name": "generate_card_number",

        "module": "core",

        "action": "setvalue",

        "options": {

          "key": "generate_card_number"

        },

        "meta": [],

        "outputType": "number"

      },

      {

        "name": "repeat",

        "module": "core",

        "action": "repeat",

        "options": {

          "repeat": 10,

          "outputFields": [],

          "exec": {

            "steps": [

              {

                "name": "r_generate_card_number",

                "module": "core",

                "action": "repeat",

                "options": {

                  "repeat": 4,

                  "outputFields": [],

                  "exec": {

                    "steps": [

                      {

                        "name": "random_number",

                        "module": "core",

                        "action": "setvalue",

                        "options": {

                          "value": "{{numbers_array.randomize().top(1)}}"

                        },

                        "meta": [],

                        "outputType": "number",

                        "output": true

                      },

                      {

                        "name": "generate_card_number",

                        "module": "core",

                        "action": "setvalue",

                        "options": {

                          "value": "{{generate_card_number+random_number}}",

                          "key": "generate_card_number"

                        },

                        "meta": [],

                        "outputType": "number",

                        "output": true

                      }

                    ]

                  }

                },

                "output": true,

                "meta": [

                  {

                    "name": "$index",

                    "type": "number"

                  },

                  {

                    "name": "$number",

                    "type": "number"

                  },

                  {

                    "name": "$name",

                    "type": "text"

                  },

                  {

                    "name": "$value",

                    "type": "object"

                  },

                  {

                    "name": "random_number",

                    "type": "number",

                    "sub": []

                  },

                  {

                    "name": "generate_card_number",

                    "type": "number",

                    "sub": []

                  }

                ],

                "outputType": "array"

              },

              {

                "name": "query",

                "module": "dbconnector",

                "action": "single",

                "options": {

                  "connection": "db",

                  "sql": {

                    "type": "SELECT",

                    "columns": [

                      {

                        "table": "card",

                        "column": "card_id"

                      },

                      {

                        "table": "card",

                        "column": "range_bot"

                      },

                      {

                        "table": "card",

                        "column": "range_top"

                      }

                    ],

                    "params": [

                      {

                        "operator": "less_or_equal",

                        "type": "expression",

                        "name": ":P1",

                        "value": "{{generate_card_number}}",

                        "test": ""

                      },

                      {

                        "operator": "greater_or_equal",

                        "type": "expression",

                        "name": ":P2",

                        "value": "{{generate_card_number}}",

                        "test": ""

                      }

                    ],

                    "table": {

                      "name": "card"

                    },

                    "primary": "card_id",

                    "joins": [],

                    "wheres": {

                      "condition": "AND",

                      "rules": [

                        {

                          "id": "card.range_bot",

                          "field": "card.range_bot",

                          "type": "double",

                          "operator": "less_or_equal",

                          "value": "{{generate_card_number}}",

                          "data": {

                            "table": "card",

                            "column": "range_bot",

                            "type": "number",

                            "columnObj": {

                              "type": "integer",

                              "primary": false,

                              "unique": false,

                              "nullable": true,

                              "name": "range_bot"

                            }

                          },

                          "operation": "<=",

                          "table": "card"

                        },

                        {

                          "id": "card.range_top",

                          "field": "card.range_top",

                          "type": "double",

                          "operator": "greater_or_equal",

                          "value": "{{generate_card_number}}",

                          "data": {

                            "table": "card",

                            "column": "range_top",

                            "type": "number",

                            "columnObj": {

                              "type": "integer",

                              "primary": false,

                              "unique": false,

                              "nullable": true,

                              "name": "range_top"

                            }

                          },

                          "operation": ">=",

                          "table": "card"

                        }

                      ],

                      "conditional": null,

                      "valid": true

                    },

                    "query": "SELECT card_id, range_bot, range_top\nFROM card\nWHERE range_bot <= :P1 /* {{generate_card_number}} */ AND range_top >= :P2 /* {{generate_card_number}} */"

                  }

                },

                "output": true,

                "meta": [

                  {

                    "type": "number",

                    "name": "card_id"

                  },

                  {

                    "type": "number",

                    "name": "range_bot"

                  },

                  {

                    "type": "number",

                    "name": "range_top"

                  }

                ],

                "outputType": "object"

              },

              {

                "name": "TEST",

                "module": "core",

                "action": "setvalue",

                "options": {

                  "value": "{{'card'+$index+'_id'}}"

                },

                "meta": [],

                "outputType": "text",

                "output": true

              },

              {

                "name": "generate_card_number",

                "module": "core",

                "action": "setvalue",

                "options": {

                  "key": "generate_card_number"

                },

                "meta": [],

                "outputType": "text"

              }

            ]

          }

        },

        "output": true,

        "meta": [

          {

            "name": "$index",

            "type": "number"

          },

          {

            "name": "$number",

            "type": "number"

          },

          {

            "name": "$name",

            "type": "text"

          },

          {

            "name": "$value",

            "type": "object"

          },

          {

            "name": "r_generate_card_number",

            "type": "array",

            "sub": [

              {

                "name": "random_number",

                "type": "number",

                "sub": []

              },

              {

                "name": "generate_card_number",

                "type": "number",

                "sub": []

              }

            ]

          },

          {

            "name": "query",

            "type": "object",

            "sub": [

              {

                "type": "number",

                "name": "card_id"

              },

              {

                "type": "text",

                "name": "name"

              },

              {

                "type": "text",

                "name": "image"

              },

              {

                "type": "number",

                "name": "atk"

              },

              {

                "type": "number",

                "name": "def"

              },

              {

                "type": "number",

                "name": "magic"

              },

              {

                "type": "number",

                "name": "heal"

              },

              {

                "type": "number",

                "name": "range_bot"

              },

              {

                "type": "number",

                "name": "range_top"

              }

            ]

          }

        ],

        "outputType": "array"

      }

    ]

  }

}
Community Page
Last updated: