Condition with order

Get help using Construct 2

Post » Sat Jan 31, 2015 8:24 pm

Thank you thatserafimkid for such details =)

it seems so easy but i have no idea how you create family ID and if you add instant variable to the array or not

here is my capx, i know it's missing a lot of things, but that's all i understand ^^':

Code: Select all
https://dl.dropboxusercontent.com/u/138507172/puzzle_array.capx
B
4
S
1
Posts: 40
Reputation: 532

Post » Sat Jan 31, 2015 8:48 pm

@Hunter
You are close. Perhaps using a variable with name "ID" was a little confusing because it seems you've mistaken it for Object ID or UID.
So in the Keys family you want to create a Text instance variable you can call it KeyName to make it easier for you. You don't have to create a separate variable for each key.
Image
Then click each key sprite seprately and you will see that they each share the new KeyName variable. You can change the variable value for each key sprite separately so then you can refer to them specifically in your code. So lets say for your C key object sprite you would set the value of KeyName to C. Do that for each of your other letters.
Image
Then in your code when Families 'Keys' is pressed you compare the KeyName variable. If it equals "C" then you play sound for the C key and so on.

The array is just an easy way to hold multiple values. In your case because you want to hold multiple key combinations to solve your puzzle an array is the best option.

An array has indexes which refers to the location you want something stored. It begins with 0 and goes on for however many things you need to store.
So what you would do is in the start of layout is set each index beginning with 0 to the key combination you want. So if you wanted you puzzle to be DEC.
You would
set index(0) to "D"
set index(1) to "E"
set index(2) to "C"

Image

As you can see we have three items in our array so you would change the array width to 3 so it knows its holding 3 things. If you add more then you need to change the width to however many keys you have.

Let me know if your still confused on any of this.
B
33
S
8
G
2
Posts: 100
Reputation: 2,635

Post » Sat Jan 31, 2015 9:28 pm

@thatserafimkid
If I am not mistaken, you can use tokenat to store key order as an alternative to array especially for 1D array.
ImageImage
B
101
S
45
G
22
Posts: 772
Reputation: 21,468

Post » Sat Jan 31, 2015 9:35 pm

Either way thatserafimkid deserves some kinda of a little medal for that explanation post.
B
19
S
6
G
6
Posts: 1,101
Reputation: 5,646

Post » Sat Jan 31, 2015 9:59 pm

Yeah you are right somebody, thatserafimkid thank you for your explanation very detailed :D

i understand now the logic of arrays, i have just a litle problem for my puzzle, it is that i want the player to continue clicking on other keys even if he change the order, so i add this to the event sheet :

Image

but the problem now is that even if i do this : C+E+C+C+C+D+D+E or C+E+C+D+D+D+E i can succeed

and what i want to do is leave the player the choice to play what he want but he succeed only if he play the right keys

here is my capx :
Code: Select all
https://dl.dropboxusercontent.com/u/138507172/puzzle_array2.capx
B
4
S
1
Posts: 40
Reputation: 532

Post » Sat Jan 31, 2015 10:03 pm

Simplified it a whole bunch and put each key into one object. You could change the array.AsJSON to a loop within the array to tell the user exactly which keys they got wrong on each attempt.

EDIT: Didn't see the second and third page of replies, woops. If this helps at all go ahead and use it, if not just ignore :P
You do not have the required permissions to view the files attached to this post.
B
46
S
14
G
7
Posts: 603
Reputation: 8,096

Post » Sat Jan 31, 2015 10:19 pm

You just have to repopulate the array once you get order wrong. Check out the capx. I did this by putting the array populate inside a group. The group gets activated on start so the array is already populated once you start the layout. But I also reactivated it if the key you pressed is not the next one on the list. You dont need the extra code to play the sound on every click. I removed that since it was already in there. I just took it out of the nested Key.ID condition.

@Somebody
Aha thanks. I just like helping people out. He happened to get me on a day I'm not busy.
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 Jan 31, 2015 10:45 pm

@alextro
That would be a really clean solution for this case. You would be right. I suppose it depends on how Hunter wants to use it.

But in any case I went a head and created an example with tokenat instead of using an array. Check it out @Hunter. All you have to do to change the puzzle is change the variable 'puzzle' to have the letters in the order you want. And then change where it says keycount = 6 to however many letters you have in your puzzle. Might be easier for you.

Edit: I found a bug in the last capx I uploaded. If you hit the first key in the pattern twice to start off with it wouldn't continue the pattern. You would have to click one of the other keys first then start the pattern again.
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 » Sun Feb 01, 2015 6:16 pm

Excellent @thatserafimkid your sample give me an idea how to build dialogue system such as rpg or vn game.
ImageImage
B
101
S
45
G
22
Posts: 772
Reputation: 21,468

Post » Sun Feb 01, 2015 7:17 pm

@alextro
You are very welcome. Glad I could provide some inspiration
B
33
S
8
G
2
Posts: 100
Reputation: 2,635

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: plinkie, R0J0hound, SERG 04 and 3 guests