• 0

    posted a message on Looping through a Preset?

    I haven't used DataTables before so I was just ignoring it. I had a look at it and it does seem more promising.

     

    But I still have a slight readability issue, but might roll with it anyway.

     

    If I take the original Preset and turn it into a DataTable of:
    Name | Value

    A          | valueA

    B          | valueB

    C          | valueC

     

    Using a portion of actual values in my editor:

    Name | Value

    help     | (str)This is the help command. Syntax: help [command]

    tp         | Teleports selected units: tp

    copy    | Duplicates selected units: copy [(opt) intPlayer: Owner of the new units]

     

    With such table I can have the "help" function print in chat something like (as String, and assuming the + means join Strings):

    (Name of Value 2 in Global data table) + ": " + ("tp" from the Global data table)

     

    In the case a player enters "help tp" I could change the "help" function to:

    (Word 2 of entered chat message) + ": " + ((Word 2 of entered chat message) from the Global data table)

     

    This could work quite well using a instanced data table.

     

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

    Next problem doing this though, is my command handler function that looks a bit like:

     

    Switch(Word 1 of _cmdString)

      case("help")

        //code

      case("tp")

        //code

     

    I want to change the case checks to use the Name of the table so if I change the syntax, I would only need to change the DataTable entry and not this function as well. If I do this for a known entry order for a instanced data table of CMD:

     

    Switch(Word 1 of _cmdString)

      case(Name 1 of CMD data table)

        //code

      case(Name 2 of CMD data table)

        //code

     

    This has the readability thing earlier, where I look at this and go "what is Name 1". But given I have a comment block above each Case saying what that command is, this may not be a huge problem. So I may roll with this, Unless you or someone has any idea about this one.

     

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

     Thanks MaskedImposter for the suggestion. It seems to be working XD

    Posted in: Triggers
  • 0

    posted a message on Looping through a Preset?

    I was experimenting with presets like the example to store chat commands and their description as the preset identifier's value. Switching the Preset type to "Custom Code (String)" and ticking allow conversions seem to make it not integers anymore...

    If I use integer instead of Custom Code (String) it cant be checked against command strings.

     

    So in a switch I can have something like switch (someString) case (str(identifierOf(A))) which returns "A" from the example. The goal being to be able to dynamically generate a list of all commands with something like forEach Identifier in ExamplePreset: add "X, " to a display string.

     

    I have a switch that checks chat messages for commands, and I want to be able to generate a list of all the commands, and have a way intuitively attach descriptions (like usage/syntax) to each one.

     

    I thought of using a 2d array, so commands[1][0] would be the actual command string, and [1][1] would be that command's description, but then the command handler switch goes from something like "case("test")" to "case(commands[1][0])" which I'm finding not ideal for readability. And it seems whenever I change an array's size, all code using that array defaults to index 0 breaking a lot of things.

    Posted in: Triggers
  • 0

    posted a message on Looping through a Preset?

    Say I have a Preset:

     

    ExamplePreset

    Value Type: Custom Script (String)

    Values:

      A: (Script Value) "valueA"

      B: "valueB"

      C: "valueC"

     

    I'm treating this like its a enum, but the editor probably treats it somewhat differently.

    I want to be able to loop through each Key (Identifier) of this Preset. I want to do this dynamically without having to manually state the length of the Preset.

     

    Something like (simplified, assuming the string has been converted to text for the Display already):

    For each Key in ExamplePreset as _X do

      Display (Convert Preset  to String (_X)) for (AllPlayers)...

     

    I guess if that is not possible the next closest thing would be a 2D array. How would I do the above code or some way to loop through each key or value in a Preset?

    Posted in: Triggers
  • To post a comment, please or register a new account.