This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-01-02 09:52:52

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

help with code... again. Sorry.

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!

Code:

|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].

http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#2 2011-01-02 10:10:49

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: help with code... again. Sorry.

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."


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#3 2011-01-02 10:14:06

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: help with code... again. Sorry.

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.

Last edited by sparks (2011-01-02 10:19:24)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#4 2011-01-02 10:18:23

rubiks_cube_guy238
Scratcher
Registered: 2009-07-02
Posts: 100+

Re: help with code... again. Sorry.

Code:

|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)


The glass is never half full nor half empty; it is twice as large as it needs to be.

Offline

 

#5 2011-01-02 10:19:28

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: help with code... again. Sorry.

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?


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#6 2011-01-02 10:31:57

rubiks_cube_guy238
Scratcher
Registered: 2009-07-02
Posts: 100+

Re: help with code... again. Sorry.

Fixed it!


The glass is never half full nor half empty; it is twice as large as it needs to be.

Offline

 

#7 2011-01-02 10:35:23

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: help with code... again. Sorry.

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.

Code:

|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

http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#8 2011-01-02 11:28:38

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: help with code... again. Sorry.

Thanks! So I learn something here, what's UTF8?


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#9 2011-01-02 11:29:40

ScratchReallyROCKS
Scratcher
Registered: 2009-04-22
Posts: 1000+

Re: help with code... again. Sorry.

sparks wrote:

Thanks! So I learn something here, what's UTF8?

Text encoding, I think.


http://imageshack.us/a/img694/3806/sigmad.png

Offline

 

#10 2011-01-02 14:50:40

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: help with code... again. Sorry.

Is there any way to do a "$Color$ is touching sprite $Sprite$ block?

EDIT: I mean, $Color$ of this sprite is touching $Sprite$

Last edited by sparks (2011-01-02 15:17:02)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#11 2011-01-02 15:21:49

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: help with code... again. Sorry.

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.


http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

Board footer