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

Get help using Construct 2

Post » Wed Aug 13, 2014 10:56 am

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 :)
Last edited by damjancd on Thu Aug 14, 2014 3:55 am, edited 1 time in total.
B
37
S
6
G
1
Posts: 301
Reputation: 2,860

Post » Wed Aug 13, 2014 11:09 am

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 told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Aug 13, 2014 11:22 am

I guess that's the only choice. I was hoping for a non token at and adding variable option :)
Thanks @LittleStain
B
37
S
6
G
1
Posts: 301
Reputation: 2,860

Post » Wed Aug 13, 2014 11:41 am

Would you use an array?
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Aug 13, 2014 11:50 am

It's literally only for 3 choices. But sure, if Array is simpler than token at... are you suggesting using "for" ?
B
37
S
6
G
1
Posts: 301
Reputation: 2,860

Post » Wed Aug 13, 2014 12:00 pm

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.

fruit.png

Edit: made slightly more concise
You do not have the required permissions to view the files attached to this post.
Last edited by codah on Thu Aug 14, 2014 3:14 am, edited 2 times in total.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Aug 13, 2014 6:28 pm

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")
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756

Post » Wed Aug 13, 2014 10:54 pm

@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?
B
37
S
6
G
1
Posts: 301
Reputation: 2,860

Post » Wed Aug 13, 2014 11:45 pm

damjancd wrote:@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.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Aug 14, 2014 3:08 am

@Codah I see, cool. @R0J0hound thanks!
B
37
S
6
G
1
Posts: 301
Reputation: 2,860

Next

Return to How do I....?

Who is online

Users browsing this forum: NN81, plinkie, TsubaRu and 9 guests