# How do I Make A "Box"

Get help using Construct 2

### » Wed Apr 19, 2017 1:00 pm

Hey guys,

I'm trying to make a word game for my Son to help him with his spelling.

I have 4-5 letters to choose from and I have the length of the word as a (visually) empty box for the letters.
Think of it like Scrabble a little bit; One letter per square.

Logically (in pseudo code) I can:

Code: Select all
`If box1 == empty {  put letter in this box} else if box2 == empty { put letter in this box} else if box3 == empty { but letter in this box}if box1 box2 box3 == full && correct == false {  reset the letters}`

But I don't know the best way to do this using Construct 2.

Am I best off using containers, or arrays, or maybe variables?

Thanks!
B
7
S
2
Posts: 41
Reputation: 613

### » Wed Apr 19, 2017 9:11 pm

I have managed to do the following logic:

Global Variables:
Empty_Box_1
Empty_Box_2
Empty_Box_3

Letters:
Letter_E_Small
Letter_D_Small
Letter_R_Small
Letter_A_Small
Letter_M_Small

[Letter_R_Small Group]
To move the letter R to Empty_Box_1:
If Empty_Box_1 = 0 > Set Position to XXX, YYY > Set Empty_Box_1 to 1

To remove the letter R from Empty_Box_1:
If Empty_Box_1 = 1 and Letter_R_Small.X = XXX and Letter_R_Small.Y = Empty_Box_1.X and Empty_Box_1.Y >
Letter_R_Small set Position back to original XXX, YYY and set Empty_Box_1 to 0.

This is just one letter, one box. Is there a better way I can do this for all 26 letters across variable sized Empty_Box_x's depending on the word length?

It'll take forever to do it this way I think, surely there's a more dynamic and less 'code' way of doing it?

Edit: Image

B
7
S
2
Posts: 41
Reputation: 613

### » Wed Apr 19, 2017 9:22 pm

Im going to assume drag and drop letters onto boxes.
Letter on collision with box
->box compare instance variable "filled"=0
-->letter set drag and drop to disabled
-->letter set position to box
-->box set variable "filled" to 1

This assumes letters and boxes are instances from two separate objects.
Letter frame 0 = A, 1 = B, etc
B
175
S
50
G
200
Posts: 8,626
Reputation: 124,528

### » Wed Apr 19, 2017 9:30 pm

newt wrote:Im going to assume drag and drop letters onto boxes.
Letter on collision with box
->box compare instance variable "filled"=0
-->letter set drag and drop to disabled
-->letter set position to box
-->box set variable "filled" to 1

This assumes letters and boxes are instances from two separate objects.
Letter frame 0 = A, 1 = B, etc

Hi Newt, thank you for replying to me.

I'm not sure what the frame is that you're referring to but I'll assume that's right? I created a new sprite object for each letter and gave them the name Letter_R_Small etc.

As for the selection, it's click based at the moment but I'll ultimately want it touch based since i'm gonna put it on my phone for my Son to use.

On Object Click > Letter_R_Small, move to Pos xxx, yyy, and so on.
B
7
S
2
Posts: 41
Reputation: 613

### » Wed Apr 19, 2017 10:19 pm

Im not saying you can't make 24 objects to make the alphabet, but I will say you should do a forum search on how instances work.
That with instance variables and how a Sprites animation frames can be used with them.
B
175
S
50
G
200
Posts: 8,626
Reputation: 124,528

### » Wed Apr 19, 2017 10:32 pm

newt wrote:Im not saying you can't make 24 objects to make the alphabet, but I will say you should do a forum search on how instances work.
That with instance variables and how a Sprites animation frames can be used with them.

Ahh Right, I see what you mean now (I think).

1 Object - 26 frames to make up the alphabet.

Could that be called dynamically, for instance:

On Load: Letters.0 (R) Letters.1 (E) Letters.2 (D) Letters.Random (Z) Letters.Random (F) and so on?
B
7
S
2
Posts: 41
Reputation: 613