How do I create x amount of objects (global variable)

Get help using Construct 2

Post » Thu Feb 19, 2015 6:36 pm

Hi Yall!

I have a question.

As seen in very much games lately i am trying to create a answer system.

I have done this before with a complete keyboard that works fine but this time i want to make it different.
I want to give the person some random letters mixed with letters you can use for the answer.

Now, i want to create a x amount of objects because i want to show the length of the answer.

Example:
Image

Now, the little empty spaces in the image should be the amount of the answer.

So if i have a answer "Construct" i need to create 9 of those objects.

And if that isn't enough they need to be perfectly centered.

Can any one help me with the best technique to do this?

Thanks in advance!
B
10
S
4
G
3
Posts: 165
Reputation: 2,511

Post » Thu Feb 19, 2015 7:26 pm

maths and stuff :P

Firstly you will want a variable for the spacing between the objects.

Then, you're going to want a for loop, which goes from 1 to the length of letters in the word. (len() system expression). Then on each loop spawn a new object with the X coordinate of "(LayoutWidth/2) + (spacing* Object.width*(loopindex-((len(word)+1)/2)))"

the spacing variable usually works best between 1 and 2
You do not have the required permissions to view the files attached to this post.
Last edited by briggybros on Thu Feb 19, 2015 7:27 pm, edited 1 time in total.
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Thu Feb 19, 2015 7:27 pm

Try this...

centering-slots-example.capx


You can write any answer and hit enter or click the button to update the slots.

Attention: In this example the registration point for the slots is top-left (0,0) not the default registration, which is centered. If you preffer a centered registration, remember to add half the width of a slot to the firstX variable.
You do not have the required permissions to view the files attached to this post.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
16
S
4
G
1
Posts: 416
Reputation: 2,313

Post » Thu Feb 19, 2015 7:54 pm

Wow guys thanks! Both work like a charm!

I got so many more things to learn!

Great thanks!
B
10
S
4
G
3
Posts: 165
Reputation: 2,511

Post » Thu Feb 19, 2015 10:48 pm

Hi Guys i found out i have one more question.

After this i still don't know how to create random letters.

Well, i know how to create random letters but i don't know how to make sure the letters are included that are needed to create the answer.

Can any one help me out with that one?

As seen in the image on my first post ( the A,W,A,A,A,A,A,A,A buttons ).
I will take the word "Construct" for example again.

I have 18 Letters/Buttons. These letters have to be random but the letters C,O,N,S,T,R,U,C,T have to be included in those letters.

So in this case i need the letters construct and 9 other random letters ( A to Z ).
The letters construct is actually a global variable.

Sorry for all these questions but i am pretty noob at that kind of things :(!

Thanks in advance!
B
10
S
4
G
3
Posts: 165
Reputation: 2,511

Post » Fri Feb 20, 2015 7:56 am

@Allardje:


I made you a simple demo of the principle...
You do not have the required permissions to view the files attached to this post.
B
8
S
3
Posts: 197
Reputation: 1,207

Post » Fri Feb 20, 2015 12:03 pm

Here...

centering-slots-example.capx
You do not have the required permissions to view the files attached to this post.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
16
S
4
G
1
Posts: 416
Reputation: 2,313

Post » Thu Mar 12, 2015 5:18 pm

Hey i actually integrated the script @brunopalermo ,

I pop up one question tho.

While working on the answer system ( so if you press a letter button that letter will appear in the answer slots ) i am not sure how to.

What i did is creating a text object on every "letter slot". These letters will be filled in with the right letter and will become visible if a right letter is pressed.

That part would be fine to create i think i can manage it but somehow i want to cut the answer in letters just like you do when creating the right letters and random letters.

Though my: find(uppercase(answer),mid(ALPHABET,loopindex,1)) won't work to get all letters.

This is what it looks like atm:
This is what i did. As you can see i tried using it the same way as it creates the letter slots:
Image
As you can see below creating the amount of "letters" is correct but my code isn't:

This works for the letter slots and the amount of letters but not for the text itself: find(uppercase(answer),mid(ALPHABET,loopindex,1))
Image

Somehow the letters appear as 0 and -1.

Can you please help me with that line of code? I think i'm heading the right direction but my line isn't completely correct.

Thanks!
B
10
S
4
G
3
Posts: 165
Reputation: 2,511


Return to How do I....?

Who is online

Users browsing this forum: DharmaOne and 24 guests