The Daily Click ::. Forums ::. Klik Coding Help ::. OR-statement
 

Post Reply  Post Oekaki 
 

Posted By Message

popshop



Registered
  08/08/2005
Points
  5
8th August, 2005 at 09:02:34 -

I will try to explain this problem as easy as i can.

I have, let's say, a Counter 1, Counter 2 and an Activ object. In the start of the frame Counter 1 and Counter 2 is set to a random value from 1 to 5. If the value of Counter 1 hits 2 or 5 and Counter 2 hits 2 or 4 the activ object should be destroyed.

Now, I could make a long list of conditions: "Counter 1=2 and Counter 2=2", "Counter 1=5 and Counter 2=2" etc. etc... But I don't want that long list, I want a short and easy way to make this work. So, this would be my question:
Is there a condition that may look like this: "Counter 1=2 or 5 and Counter 2=2 or 4">Destroy Activ object 1? The OR-statement doesn't work like this I've noticed, but there have to be an other way. Please help!

 
n/a

DeadmanDines

Best Article Writer

Registered
  27/04/2006
Points
  4758
8th August, 2005 at 09:55:41 -

Right, there are two main possibilities I can think of to help you
The second is best for what you want.

THE FIRST METHOD

'The Flag Object' by z33z (http://www.clickteam.info/extensions/extview.php?id=253)

Here we use a flag value for each possible 'or' (so if we want '1 or 6', we would have 2 flags. One for if it's 1, and one for if it's 6). We then have an event for each of those flags. They go this way:

counter1 = 1
..Turn flag 0 ON

counter1 = 2
..Turn flag 1 ON


Then we do another event to do the OR command:

Flag Object: OR flags 0 to 1
..[insert actions here]


This basically checks if flag 0 is ON, *or* if flag 1 is ON (or both).

Since this uses several events, you may wonder why you don't just do an event for each choice. Well the reason is that this keeps all your actions in one place.

To illustrate, imagine if we have events to check if the counter = 1 or 3, and set a string object to 'yes'.

counter = 1
...Print: "yes"

counter = 3
...Print: "yes"

But now, suppose I wanna change that to say "flopsy bunnies"
I have to change BOTH events.

But if we did this:

counter = 1
...Flag 0 ON

counter = 3
...Flag 1 ON

Flag Object: OR flags 0 to 1
...Print: "yes"


We have three events instead of two, but if we wanna make changes, we only need to change the last event. Hopefully you'll see how this is much simpler to alter and update.

THE SECOND METHOD

...is far simpler in most respects. This requires the ambiguously named 'Cunning Object', by Tigerworks.
(http://www.clickteam.info/extensions/extview.php?id=18 )

This is the closest to what you want. This is all within one event. The downside is that - as far as I know - it only compares numbers. So the following would need the first method:

Player's name = 'Fred' OR 'Nancy'

Object1 is visible OR Object2 is visible

Those kinda things would need to be done with the first method.

Hope it helps

Image Edited by the Author.

 
191 / 9999 * 7 + 191 * 7

popshop



Registered
  08/08/2005
Points
  5
8th August, 2005 at 15:04:38 -

Thank you for your reply...
There is only one thing - I can't figure out how to use the Cunning object. Perhaps I'm an idiot, perhaps it's a strange tool, I don't know

Image Edited by the Author.

 
n/a

RapidFlash

Savior of the Universe

Registered
  14/05/2002
Points
  2712
9th August, 2005 at 00:41:01 -

The Cunning Object may be confusing at first, but it's really simple. Just make sure that End OR is the last condition in the event.

 
http://www.klik-me.com

DeadmanDines

Best Article Writer

Registered
  27/04/2006
Points
  4758
9th August, 2005 at 05:19:15 -

I hope this clarifies things for you:

Cunning Object will only compare numbers. So you can use it with a counter value, an object's coordinates, etc. Anything that's a number.

When you go to insert a condition using Cunning Object, the menu of conditions pops up with the following options:

OR comparisons
(A sub-menu with the following conditions)
--OR comparison ( = )
--OR comparison ( < )
--OR comparison ( > )
--OR comparison ( <= )
--OR comparison ( >= )
--OR comparison ( <> )
End OR


Any of those 'OR comparison...' conditions require two values. Think of it like this:

'if A = B...'

Here we have two obvious values: A and B. It's the same with Cunning, except it calls them 'first number' and 'second number'.

The little symbol in brackets ( = ), ( < ), ( <> ), etc, just represents the kind of thing you want to check for. Here is a basic list of what they do:

( = ) If A is equal to B
( < ) If A is less than B
( > ) If A is more than B
( <= ) If A is less than or equal to B
( >= ) If A is more than or equal to B
( <> ) If A is different to B

The way you do an OR comparison is by putting more than one of these conditions in the same event. You then finish it with an END OR condition.

Here's an example. At the start of the level, it generates a random number between 0 and 10. If the counter = 2 or 4, or it's greater than 5, then we play a little sound.


Start Of Frame
-- Counter: Set value to random(10)

Start Of Frame
+Cunning Object: Value("counter") = 2
+Cunning Object: Value("counter") = 4
+Cunning Object: Value("counter") > 5
+Cunning Object: END OR
-- Sound: Play sound 'YAY.wav'


D'you see how that works? It helps if you think of it in a certain way.
Don't think of it as 'if counter = 2, 4, or is more than 5'

Think of it like this:
'if counter = 2' OR
'if counter = 4' OR
'if counter > 5'

Then you'll understand how we lay one comparison on top of another. Then all you need to remember is to have an END OR at the bottom.

I hope that helps, just ask again if there's anything you still don't understand

Image Edited by the Author.

 
191 / 9999 * 7 + 191 * 7

popshop



Registered
  08/08/2005
Points
  5
10th August, 2005 at 17:19:34 -

I get it!...that wasn't so strange after all (which have to make me the idiot ). Thanks a million. =D

 
n/a
   

Post Reply



 



Advertisement

Worth A Click