Apply a table of truth in a program

Get help using Construct 2

Post » Tue Sep 04, 2012 3:26 am

Hi, everybody!

Look, now I'm at the final stage of a program.

project

I have applied a truth table.

We can have some sprites present or not. These are the possible combinations:

OOO
XOO
OXO
OOX
XXO
XOX
OXX
XXX

Where a 'X'means the sprite is visible, and the 'O' means it is not.

The opacity of the laser beam changes depending on a formula that includes angles values for each sprite's instance.

I have thought to act like in the 'case' operation in C or Java.

But in this case...It seems that it does not work.

Do you have any idea about the reason?

Thanks a lot in advance. I left to you this project if it is usefull for somebody someday.
B
16
S
4
G
1
Posts: 105
Reputation: 1,829

Post » Tue Sep 04, 2012 6:43 pm

You could do it like this:
[code]global text pattern=""

Every Tick:
--- set pattern to ""

For each sprite:
--- sprite is visible:
------ add "x" to pattern
--- else:
------ add "o" to pattern

//// cases
pattern = "ooo":
--- do this

pattern = "xoo":
--- do that

...[/code]R0J0hound2012-09-04 18:44:32
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Tue Sep 04, 2012 8:20 pm

Interesting.

Such thing could be done as well with two arrays?

One of them for the sprites values selected by the buttons, and the other as a Registry. Comparing them we can solve the matter and modulate the opacity of the lasers.

How do you like that?
B
16
S
4
G
1
Posts: 105
Reputation: 1,829

Post » Tue Sep 04, 2012 10:15 pm

I suppose you could do it with arrays but it's not necessary.

Here's how I would do it:
http://dl.dropbox.com/u/5426011/examples14/laserFilter.capx
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Tue Sep 04, 2012 11:44 pm

You can represent the 3 postions using binary with 1 variable.

Like with a 8 bit number the least significant bit is 1 and the next is 2 and the next is 4.

variable == 4 the result is oox
variable == 2 the result is oxo
variable == 1 the result is xoo

So the variable can be anything between 0-7 which represents a condition you can act on.
B
17
S
9
G
7
Posts: 249
Reputation: 6,922

Post » Wed Sep 05, 2012 2:31 am

Thanks to all for your wise advices and dedication. I've properly finished the project, using an unidimensional array with three elements.

Afterwards, to emulate the switch command of C, a chain of If-else has been made to allow control over the different sprites that make part of the light beam.

Buttons are active and not only change the visibility of the sprites, they change also the values of that array.

As it seems that Construct2 does not allow to pick up more than one instance in a condition, this is the way that solved the issue...(Among a handful of other ways, of course.)

And thanks of the help from the people of the forum!
B
16
S
4
G
1
Posts: 105
Reputation: 1,829


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests