How do I make a sequential Choose(...) expression? |Answered

  • I'm looking for the simplest way to do this

    I want to just plug into the value SequentialChoose(Apples,Oranges,Cake)

    and the first time it runs, it selects Apples

    Second, it selects Oranges

    Third, it selects Cake

    then Apples again, ad infinitum.

    Thanks people of the Construct 2 community

  • I guess using TokenAt and TokenCount would work for this..

    tokenat(src, index, separator)

    Return the Nth token from src, splitting the string by separator. For example, tokenat("apples|oranges|bananas", 1, "|") returns oranges.

    tokencount(src, separator)

    Count how many tokens occur in src using separator. For example, tokencount("apples|oranges|bananas", "|") returns 3.

    just add 1 to a variable as long as it's less than tokencount-1 else set it to 0

    use that variable in the TokenAt expression..

  • I guess that's the only choice. I was hoping for a non token at and adding variable option

    Thanks LittleStain

  • Would you use an array?

  • It's literally only for 3 choices. But sure, if Array is simpler than token at... are you suggesting using "for" ?

  • No use array.at() and index it with a variable incremented by % so it wraps around. But for 3 choices it does seem overkill (but I'd probably still do it by personal preference).

    e.g.

    [attachment=0:3ktrwyji][/attachment:3ktrwyji]

    Edit: made slightly more concise

  • Another idea could be to use the function object.

    global number cur = -1

    On function "next"

    --- set cur to (cur+1)%Function.ParamCount

    --- set return value to Function.Param(cur)

    On any click

    --- Set text to Function.call("next", "apples","oranges","bananas")

  • R0J0hound Not sure I understand how this works, or how to recreate it in Construct 2, but looks simple and resource cheap.

    what is the global number CUR aspect? current ? or a global variable?

    I have only one function right?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • R0J0hound Not sure I understand how this works, or how to recreate it in Construct 2, but looks simple and resource cheap.

    what is the global number CUR aspect? current ? or a global variable?

    I have only one function right?

    Pretty much as he spelled out.. global var is for the same reason as my currFruit var ('current'). One function as shown. Should translate straight into C2.

  • codah I see, cool. R0J0hound thanks!

  • codah I see, cool. R0J0hound thanks!

    Don't be afraid to use arrays (I'm not saying you are). Remember the added benefit, that you would then have the fruit names available to you anywhere else in your code, e.g. Fruit.At(APPLE) where APPLE is a defined constant.

  • codah I am afraid And a really large set of them actually. So I'd have to start using them one way or another .

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