Best practice to enter an array of values to an action

0 favourites
  • 9 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • I need to get an array of values, like ["First","second","more,"etc"], into an action. The way I tried was to add several AddAnyTypeParam() calls but that will limit the number of values and give a lot of maybe unused input fields.

    If I use a single free form entry I need to parse the input and handle all strange inputs. I also need to explain the format to the user.

    Any thoughts how handle this?

  • JSON string.

  • I am on my pad now so i can't check but will the parameter input really accept {xxxx}?

  • Json string like "[1,2,3]" , it is a string.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I tested to use a JSON string as the input but could not get pass the input syntax checker.

    First test for reference, this was an expected fail:

    Next, use single quotes as string input, not allowed:

    Ok, let's escape the double quotes, that might work, but no:

    Single quotes are not allowed as string in JSON and will also break the runtime right away.

    More ideas needed.

  • In C2 you escape double quotes by doubling them

    "[""Arne"",""was"",""here""]"

  • I wouldn't use a string: you have to parse it, which adds unnecessary string handling overhead, and JSON is especially awkward to use in expressions since all double-quotes have to be doubled up.

    I'd just use an action to add one item, and the user can use multiple actions to add multiple items.

  • I wouldn't use a string: you have to parse it, which adds unnecessary string handling overhead, and JSON is especially awkward to use in expressions since all double-quotes have to be doubled up.

    I'd just use an action to add one item, and the user can use multiple actions to add multiple items.

    It is a good idea. And it might need to indicate the end of aray assigning, maybe another action.

    Action Push an element

    Action push an element

    ....

    Action do something using this array, then clean it

  • I tested with the JSON style input and it's very easy from the plugin side, more or less just a single line to get the array. However the 14 double quotes to get 11 characters in is a bit hard to put that syntax on the user. So I would probably just keep this as a last resort.

    Having several actions and push the items one by one gets more complicated as I am already in a transaction flow and the array is also connected to a property.

    All my actions in the flow is already standalone so I need to setup a sub flow just for this. From a user point of view this method seems fairly natural, just need to understand if the action is an AND or an OR for values(filters in my case).

    My current test implementation is a simplified "CSV" method to get all values in one action. There is some special parsing involved, but not that much.

    But what I really want of course is a AddAnyTypeArrayParam()

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)