Condition with order

Get help using Construct 2

Post » Mon Feb 02, 2015 1:40 pm

Thank you @EncryptedCow, i will use your code, i found it useful for one of the game puzzles ;)

@thatserafimkid & @alextro you are right the tokenat is the best way to do things like the piano puzzle, thank you very much for your help, all of you :D

thatserafimkid says :
I suppose it depends on how Hunter wants to use it

actualy i have two type of puzzle in the game, the piano puzzle (with tokenat method) and another with numbres like this :
Image

the numbres puzzle capx :
Code: Select all
 https://dl.dropboxusercontent.com/u/138507172/Piano%20Forum/puzzle_numbers.capx

this one i don't know yet what method i will use, i don't think Tokenat will be useful here, and i am sure my method isn't the right one, and i have some problems with it.
B
4
S
1
Posts: 40
Reputation: 532

Post » Mon Feb 02, 2015 4:59 pm

@thatserafimkid nice solution its really awesome, but could you please explain what tokenat does?
On the C2 manual i just found 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.

But i dont understand what that mean and how does it work (what means Nth and token)
Read this:
yeah, i really like to say that you should "Read this:"
B
13
S
6
Posts: 138
Reputation: 1,615

Post » Mon Feb 02, 2015 5:23 pm

Basically array separated by the given character.
B
19
S
6
G
7
Posts: 1,101
Reputation: 6,146

Post » Mon Feb 02, 2015 6:01 pm

@Hunter
For your code game you could have all your numbers as one object, and just have the different groups be an instance variable that separates them. So you could have one sprite with 3 animation frames. and copy it 3 times and give one instance variable 'GroupName' A, then B for you second copy, and so on. Then in your code you can just change the animation frame instead of deleting and creating a new object each time. Then with tokenat you can evaluate if Sprite Group A Current Frame = tokenat at index 0. Then check group B frame at index 1, and so on. Let me know if you still don't understand

@EyeForcz
as Somebody mentioned a tokenat is basically a one dimensional array. You can store a list of items and have them separated by a character. Let's say you made a list of your friends name
"Jon,Michael,Ben"
You could find out who the 3rd person on the list is by using tokenat.
You could do tokenat("Jon,Michael,Ben",2,",")
This would return "Ben"
You just have to remember that just like arrays tokenat has index 0. So the first name is at index 0 and the second name is at index 1, and so on.
The seperator is just what it says. You tell tokenat what you used to separate your list. So in the example "Jon,Michael,Ben" we used a comma to separate our names. So we let tokenat know that every time it sees a comma that its beginning the new index, in our case new name.
B
33
S
8
G
2
Posts: 100
Reputation: 2,635

Post » Mon Feb 02, 2015 6:54 pm

now i understand your code, thanks :)
Read this:
yeah, i really like to say that you should "Read this:"
B
13
S
6
Posts: 138
Reputation: 1,615

Post » Sat Feb 07, 2015 1:54 pm

@thatserafimkid i did it with your method, but the Tokenat Action, it is a little confusing :!:

i read your explination to EyeForcz, but i think i can understand better in the capx ^^

capx :
Code: Select all
https://dl.dropboxusercontent.com/u/138507172/Piano%20Forum/numbers_tokenat.capx
B
4
S
1
Posts: 40
Reputation: 532

Post » Sat Feb 07, 2015 2:21 pm

Try playing CDCECD and you notice congratulation will appear
B
255
S
39
G
15
Posts: 1,975
Reputation: 40,984

Post » Sat Feb 07, 2015 2:26 pm

@Hunter
Here try this. Instead of using different animations you can just use different frames of one animation. That way your animation will match your code number and you can compare it that way. You'll see I added the code groups into a family that way you can control the animation for any of the groups in one event. All it does is add one to the frame one you click on it, and it will revert back to 0 if you click on it and it already equals 2.
You do not have the required permissions to view the files attached to this post.
B
33
S
8
G
2
Posts: 100
Reputation: 2,635

Post » Sat Feb 07, 2015 6:08 pm

@thatserafimkid thank you for your quick anwsers, it is really effective with family and frames, but what i can't understand is the number after the global variable, it is not the code order, because tokenat do the order system and int convert it to integer right? but what is after the variable (CodeCombination) i can't understand it

Image
B
4
S
1
Posts: 40
Reputation: 532

Post » Sat Feb 07, 2015 8:46 pm

That is the index of you text you are comparing. codecombination is your text. The number after that tells tokenat where to look inside the text to compare that character.
So codeCimbination is a variable that equals "201"
The first character in that text is at index 0. So index 0 of the text "201" is eaul to "2", Index 1 would equal "0"
So what the code is doing is checking to make sure the frame of group A is the same as index 0 in this case "2", the frame in group B is the same as index 1 which is "0", and frame of group C is the same as index 2 which is "1"

You can read back on a post I wrote before in this thread that explains how tokenat works.
B
33
S
8
G
2
Posts: 100
Reputation: 2,635

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests