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

#1 2012-02-01 17:40:00

Legolas_Greenleaf
Scratcher
Registered: 2011-06-16
Posts: 86

Explanatory topic: "or" script removal

I think that some people might have already found about this, but I haven't seen anybody say anything about it, so here goes.

Have you ever made a game (for example, a scroller, since in that context this script is more useful) and used sensing that involved recognizing what sprites you were touching?  And since there were a lot of platforms, you had to identify each one in a really long "if (touching Sprite 1) or (touching Sprite2) or (touching Sprite3)", etc. script?

Here's a solution; make a list called IfTouching (if you want, add a number so you can make more lists with that name) and add the names of all the sprites your character will be touching.  Then, you can just say "if touching (item [any] of IfTouching)" and save yourself some work and space.

Hope this helped someone!

Legolas


http://25.media.tumblr.com/tumblr_m8s5zeoqje1qky8rdo1_250.gif  OPPAN GANGNAM STYLE~

Offline

 

#2 2012-02-01 18:37:02

puppetadventurer
Scratcher
Registered: 2011-02-20
Posts: 1000+

Re: Explanatory topic: "or" script removal

Good idea!


3

Offline

 

#3 2012-02-01 19:19:38

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Explanatory topic: "or" script removal

Sorry to say it doesn't quite work that well...when you say any, what it does is picks a random item, not test every single one.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#4 2012-02-02 03:26:57

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Explanatory topic: "or" script removal

AtomicBawm3 wrote:

Sorry to say it doesn't quite work that well...when you say any, what it does is picks a random item, not test every single one.

You could maybe get the terrain number then. I think the terrain number will be

(ScrollX)/[480]
, though I'm not sure. And then just put
<touching (item (Terrain #) of [Terrain list v]) ?>


Why

Offline

 

#5 2012-02-02 07:07:32

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Explanatory topic: "or" script removal

RedRocker227 wrote:

AtomicBawm3 wrote:

Sorry to say it doesn't quite work that well...when you say any, what it does is picks a random item, not test every single one.

You could maybe get the terrain number then. I think the terrain number will be

(ScrollX)/[480]
, though I'm not sure. And then just put
<touching (item (Terrain #) of [Terrain list v]) ?>

You might have to round it though.

Last edited by scimonster (2012-02-02 07:08:03)

Offline

 

#6 2012-02-02 07:22:23

catfan8
Scratcher
Registered: 2008-07-23
Posts: 500+

Re: Explanatory topic: "or" script removal

There is always the "and" block though. I had to make a script like this once:

when gf clicked
forever
if <<(sprite 1) = [1]> and> 
The full script went had nine different sprites in it.

Last edited by catfan8 (2012-02-02 07:23:05)


http://mag.racked.eu/cimage/i9002/Sword-In-Back+get%21/HEROBRINE+Y+U+NO+EXIST/mca.png

Offline

 

#7 2012-02-02 10:13:45

Smozzick
Scratcher
Registered: 2011-10-23
Posts: 100+

Re: Explanatory topic: "or" script removal

Huh, I didn't know you could reference sprites by a string...ideas ^^.


http://i50.tinypic.com/ded8m.png

Offline

 

#8 2012-02-02 12:32:53

Legolas_Greenleaf
Scratcher
Registered: 2011-06-16
Posts: 86

Re: Explanatory topic: "or" script removal

Yes, I had a lack of foresight.  However, strings can still be a useful way to remove "or" scripts.


http://25.media.tumblr.com/tumblr_m8s5zeoqje1qky8rdo1_250.gif  OPPAN GANGNAM STYLE~

Offline

 

#9 2012-02-02 12:51:13

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Explanatory topic: "or" script removal

scimonster wrote:

RedRocker227 wrote:

AtomicBawm3 wrote:

Sorry to say it doesn't quite work that well...when you say any, what it does is picks a random item, not test every single one.

You could maybe get the terrain number then. I think the terrain number will be

(ScrollX)/[480]
, though I'm not sure. And then just put
<touching (item (Terrain #) of [Terrain list v]) ?>

You might have to round it though.

Yeah. Like I said, I wasn't sure if my method was completely correct, but I knew it was something like that.


Why

Offline

 

#10 2012-02-04 16:56:12

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: Explanatory topic: "or" script removal

RedRocker227 wrote:

scimonster wrote:

RedRocker227 wrote:

You could maybe get the terrain number then. I think the terrain number will be

(ScrollX)/[480]
, though I'm not sure. And then just put
<touching (item (Terrain #) of [Terrain list v]) ?>

You might have to round it though.

Yeah. Like I said, I wasn't sure if my method was completely correct, but I knew it was something like that.

Your method works, but you need to round it down with the

(() mod ())
block.

set [terrain number v] to (((scrollx) / [480]) - (((scrollx) / [480]) mod (1)))
if <touching (item (terrain number) of [terrain list v]) ?>
do stuff
end

Last edited by rdococ (2012-02-04 16:58:18)

Offline

 

#11 2012-02-05 22:52:26

K-Jam
Scratcher
Registered: 2010-04-17
Posts: 100+

Re: Explanatory topic: "or" script removal

good idea, but since ou cant hide lists, you'll see the list and it will be ugly  sad


http://images.inmagine.com/img/imagezoo/iz162/Iz162012.jpg COMPASS!!!

Offline

 

#12 2012-02-06 00:37:08

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Explanatory topic: "or" script removal

K-Jam wrote:

good idea, but since ou cant hide lists, you'll see the list and it will be ugly  sad

Um. Click the checkbox next to the list's name. :?

Offline

 

#13 2012-02-06 00:55:19

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: Explanatory topic: "or" script removal

scimonster wrote:

K-Jam wrote:

good idea, but since ou cant hide lists, you'll see the list and it will be ugly  sad

Um. Click the checkbox next to the list's name. :?

tongue  +1

Offline

 

#14 2012-02-06 16:44:16

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Explanatory topic: "or" script removal

Kind of on topic:  You can broadcast strings too.  This is very nice for platformers.

broadcast [(join ["Level "][(Level #)])]

Last edited by MoreGamesNow (2012-02-06 16:44:27)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#15 2012-02-07 05:48:22

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Explanatory topic: "or" script removal

MoreGamesNow wrote:

Kind of on topic:  You can broadcast strings too.  This is very nice for platformers.

broadcast (join [Level ](Level #))

Fixed script.

Last edited by scimonster (2012-02-07 05:48:37)

Offline

 

Board footer