setindex()

0 favourites
  • 11 posts
  • Ashley

    You added chooseindex(1, "foo", "bar", "baz"), which is a great addition, would it also be possible to add

    setindex()

    Maybe setindex(index, new value)

    setindex(1,"yay")

    ("foo","yay","baz")

    Also changeindex()

    changeindex("foo", "yay")

    ("yay","bar","baz")

    It would complete the feature set.

    Thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't think this makes sense. What is it returning exactly? Construct does not have an array expression type at the moment. Further, the design of Construct is that expressions are usually read-only and don't actually themselves change things - that's what actions are for.

  • You're right. It would be much more helpful for these types to be applied to tokens instead.

    Tokenat() we already have but,

    settokenat(string, index,seperator, new token)

    and

    changetokenat(string, matching tokens, separator)

    would be very useful.

    Thanks.

  • But expressions aren't meant to change things - that's what actions are for. I think a one-dimensional array would be better in this case.

  • You would use it like this.

    Normally you could do;

    My_string=""

    My_tokens = "A,B,C,C"

    If condition met then set string My_string to tokenat(My_tokens,0,",").

    My_string = "A"

    settokenat() and changetokenat() would work the same, but on the token string itself.

    If condition met then set string My_tokens settokenat(My_token, 0,",","Z").

    My_tokens = "Z,B,C,C"

    If condition met then set string My_tokens changetokenat(My_token,"C",",","X").

    My_tokens = "Z,B,X,X"

  • Agree. "Set Index" action would be helpful

  • I still don't think this is the right approach - naturally next there'll need to be inserting at index, deleting at index, appending to end etc. - and that is basically reinventing everything the Array object does.

    For the next release cycle I've added a "split string" action for Array, which can take a string like "1,2,3" and set the array to hold those three elements, and a "join string" expression, which can return a string like "1,2,3" of the array contents again. Then you can use all the existing Array features to set, delete, insert etc. items before returning a string again.

  • This is a great idea Ashley !

    Do the "split string" and "join string" actions have a field to define what is the separator ?

    As the token expressions works : you can choose "/" or ";" or anything you want as a separator.

    It would be really useful as it would allow "," to be part of each "tokens" without being treated as a separator for example.

    (That separator field could still be set to "," by default or even ", ")

  • Do the "split string" and "join string" actions have a field to define what is the separator ?

    Yes, of course.

  • Amazing, this will be game-changer

  • I still don't think this is the right approach - naturally next there'll need to be inserting at index, deleting at index, appending to end etc. - and that is basically reinventing everything the Array object does.

    I usually hold text colors in string TXTCLR var. Is it right approach to use array for holding three numbers and change them on the go?

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