I'm trying to write some code that reports false if any of the named sprites are being touched, but true of none of them are being touched.
Here's my code, but it's reporting the value of t6 no matter if it's true or false... Help!
|t2 t3 t4 t5 t6| t6_false. t1 = 'up' ifTrue: [ t2_self touching: 'nogo'. t3_self touching: 'right only'. t4_self touching: 'down only'. t5_self touching: 'left only'. ^t2=t3=t4=t5=t6]. t1='down' ifTrue: [ t2_self touching: 'nogo'. t3_self touching: 'right only'. t4_self touching: 'up only'. t5_self touching: 'left only'. ^t2=t3=t4=t5=t6]. t1='left' ifTrue: [ t2_self touching: 'nogo'. t3_self touching: 'right only'. t4_self touching: 'up only'. t5_self touching: 'down only'. ^t2=t3=t4=t5=t6]. t1='right' ifTrue: [ t2_self touching: 'nogo'. t3_self touching: 'left only'. t4_self touching: 'up only'. t5_self touching: 'down only'. ^t2=t3=t4=t5=t6].
Offline
I think t2=t3=t4=t5=t6 is comparing t5 and t6 and reporting true or false then compares true or false to t4. t4 is a string so it is NEVER equal to true or false and continues done the line. Hmm... Replace that code with (t2 | t3 | t4 | t5) not. "|" means "OR."
Offline
|t2 t3 t4 t5|
t1 = 'up' ifTrue: [
t2_self touching: 'nogo' asUTF8.
t3_self touching: 'right only' asUTF8.
t4_self touching: 'down only' asUTF8.
t5_self touching: 'left only' asUTF8].
t1='down' ifTrue: [
t2_self touching: 'nogo' asUTF8.
t3_self touching: 'right only' asUTF8.
t4_self touching: 'up only' asUTF8.
t5_self touching: 'left only' asUTF8].
t1='left' ifTrue: [
t2_self touching: 'nogo' asUTF8.
t3_self touching: 'right only' asUTF8.
t4_self touching: 'up only' asUTF8.
t5_self touching: 'down only' asUTF8].
t1='right' ifTrue: [
t2_self touching: 'nogo' asUTF8.
t3_self touching: 'left only' asUTF8.
t4_self touching: 'up only' asUTF8.
t5_self touching: 'down only' asUTF8].
^({t2. t3. t4. t5.} asOrderedCollection includes: true) not
"note the BRACKETS {} instead of PARENTHESIS ()"Last edited by rubiks_cube_guy238 (2011-01-02 10:31:05)
Offline
Also, "^self touching: 'nogo'" by itself reports false, even if the sprites are touching each other. Have I done something wrong? Do I need to turn the string to something else for the touching part to work?
Offline
Fixed it!
Offline
sparks wrote:
I see! Thanks! Is there any way to toggle a true to a false? I need it to report false if any of them are true.
I did that.
|t2 t3 t4 t5 t6| t2_false. t3_false. t4_false. t5_false. t6_false. t1 = 'up' ifTrue: [ t2_self touching: 'nogo'. t3_self touching: 'right only'. t4_self touching: 'down only'. t5_self touching: 'left only']. t1='down' ifTrue: [ t2_self touching: 'nogo'. t3_self touching: 'right only'. t4_self touching: 'up only'. t5_self touching: 'left only']. t1='left' ifTrue: [ t2_self touching: 'nogo'. t3_self touching: 'right only'. t4_self touching: 'up only'. t5_self touching: 'down only']. t1='right' ifTrue: [ t2_self touching: 'nogo'. t3_self touching: 'left only'. t4_self touching: 'up only'. t5_self touching: 'down only']. ^ (t2 | t3 | t4 | t5) not
Offline
sparks wrote:
Thanks! So I learn something here, what's UTF8?
Text encoding, I think.
Offline
sparks wrote:
Is there any way to do a "$Color$ is touching sprite $Sprite$ block?
EDIT: I mean, $Color$ of this sprite is touching $Sprite$
Yes, look at how the <touching $Color$?> block works then change it. I can't do it now because I'm busy.
Offline