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

#1 2009-10-05 21:21:19

Larry828
Scratcher
Registered: 2007-05-30
Posts: 100+

Need help: move from first to 12th sprite in order

In my project "Cleaning Medley" an ant eats 12 crumbs. In Part One he does it randomly, but in Part Two goes from #1 to #12 in order (smart ant).  But I had to write out "go from 1 to 12" manually, one at a time!! I tried variables in a test project and could get an arrow to *point* to each of four sprites, and then *go* to each of the four sprites.....but it would never go to the first to the second to the third.....  If you'd like to take a look, here's the link: http://scratch.mit.edu/projects/Larry828/705013 .  It's the *long* script that begins "When I receive Go Two".  Thanks!

Last edited by Larry828 (2009-10-05 21:22:53)

Offline

 

#2 2009-10-05 21:46:10

greenflash
Scratcher
Registered: 2009-05-27
Posts: 1000+

Re: Need help: move from first to 12th sprite in order

I think this will help... copy this script:

http://i38.tinypic.com/2lj56gx.jpg

I hope that's what you were looking for. I'm glad you named each sprite by it's number.

the counter essentially is the "crumb number" or the name of the crumb the ant is going to. I didn't test it, so I don' t know if it works.

Also, I noticed that you have two different broadcasts, annoucetwo and goto. I think they all need to be goto.  smile

Any questions?


http://i48.tinypic.com/2wrkirk.pnghttp://i46.tinypic.com/6r5zk7.pnghttp://i45.tinypic.com/2vtxr1t.png

Offline

 

#3 2009-10-05 21:59:18

The-Whiz
Scratcher
Registered: 2007-07-09
Posts: 1000+

Re: Need help: move from first to 12th sprite in order

How strange... I just made a project about the same thing! http://scratch.mit.edu/projects/The-Whiz-test/706532

Offline

 

#4 2009-10-05 22:06:13

Larry828
Scratcher
Registered: 2007-05-30
Posts: 100+

Re: Need help: move from first to 12th sprite in order

I substituted your 5 lines for my 51 (!) lines....but here's what happened.  The ant went to the first crumb and then waited there until it finally said, "If you don't mind...." which is the end of the scene.  (It acted like my test project: it went to the first sprite but then wouldn't go to the second.  My variable had been named "Sprite number" but adding 1 to it each time didn't produce the serial movement I need.)  I just can't figure why it won't go from the first to the second crumb!!

BTW, the "approach two" broadcast calls a title screen that introduces the ant's second approach to crumb-finding, and that title screen calls "go two."

What do we do now??  :-/

Offline

 

#5 2009-10-05 22:30:07

Larry828
Scratcher
Registered: 2007-05-30
Posts: 100+

Re: Need help: move from first to 12th sprite in order

I think I am confusing "sprite name" with "sprite number".  Naming the crumbs 1-12 makes it sound like numbers, but those are *names*.  --- Suppose the first crumb was named Adam, the second Bob, the third Charlie, etc.  How would we make the ant go from one of those to the next?  See?  I think that's what's confusing the scripts so far: names that look like numbers.  Does this make any sense?  After all....it works with my 51 line method that names each sprite in turn and sends the ant to it. 

But those nearly identical 4 lines per sprite (differing only in the name called) seem to beg for a "repeat" loop.  And a variable.  But incrementing a *name* by one makes no sense.  It would be like saying, "Go to Adam" then "Go to Adam plus 1" etc....

Maybe I should rename the crumbs and put them in a list.  Or leave them as they are, and put them in a list.  Then call the list items.....if I can figure out how.

?????

Thanks for your help!

Offline

 

#6 2009-10-05 22:48:04

greenflash
Scratcher
Registered: 2009-05-27
Posts: 1000+

Re: Need help: move from first to 12th sprite in order

Here we go, same concept, except using a list of sprite names:

http://i35.tinypic.com/280l111.jpg

Again, I haven't tried, as you can see, all this project has is the list and variables.

Here is the zoomed in script:
http://i38.tinypic.com/2eat635.jpg

I hope that helps!!  smile

Last edited by greenflash (2009-10-05 22:50:40)


http://i48.tinypic.com/2wrkirk.pnghttp://i46.tinypic.com/6r5zk7.pnghttp://i45.tinypic.com/2vtxr1t.png

Offline

 

#7 2009-10-05 22:57:40

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Need help: move from first to 12th sprite in order

Sorry to tell you this, but your crumb sprites will have to be number off like that (crumb1,crumb2, and so on) if you want to make this efficient.

Your script should then look something like this

i is usually used as the variable for loops of this sort in programming.

when green flag clicked
set i to 1
repeat (number of crumbs){
go to (join (crumb)(i))
change i by 1}
say "all done!"


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#8 2009-10-06 07:21:52

The-Whiz
Scratcher
Registered: 2007-07-09
Posts: 1000+

Re: Need help: move from first to 12th sprite in order

Not necessarily - You could use this script:

Code:

[When I receive [Go two]]
[set [iter] to [0]
[repeat (12)]
[][change [iter] by (1)]
[][go to (join (iter)())]
[end repeat]
[say [All done]]

Offline

 

#9 2009-10-06 10:17:25

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Need help: move from first to 12th sprite in order

That is basically the same script.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#10 2009-10-06 12:06:30

Larry828
Scratcher
Registered: 2007-05-30
Posts: 100+

Re: Need help: move from first to 12th sprite in order

Here's a stripped-down version of the "Cleaning" project: http://scratch.mit.edu/projects/Larry828/706807

In Scratch there's a command "Play note ( )" and one can make a list consisting only of numbers, like 65, 66, 65, and Scratch will play a tune. Because Scratch knows those numbers represent notes.  So shouldn't the "go to _____" command work the same way?

Based on suggestions given here, in the test project linked above, the crumbs are named c1 - c12 in the list "crumbs".  Using variable "index" to grab the item number in the list it goes like this:

Repeat [length of (crumbs)]
     wait 1 sec
     POINT TOWARDS [item (index) of (crumbs)]
     wait 1 sec
     GO TO [item (index) of (crumbs)

And in the test project you can see each item in the list 'hit' twice (pointed to and gone to?)...but the ant never moves.

A newer test project http://scratch.mit.edu/projects/Larry828/706891  uses the script above, and gives an option to run a literal sequence of "Go to c1" etc commands...and those work fine online.  I can't figure out the difference.

Thanks to all of you who are contributing ideas and scripts!!!  I think my test project reflects those suggestions.  If not, please let me know!!

ps  these things generally work at home on my computer (my script above works fine) but they fail online.  I'd really like a method that will work online for future projects. 
:-)

Last edited by Larry828 (2009-10-06 12:37:31)

Offline

 

#11 2009-10-06 17:27:22

Larry828
Scratcher
Registered: 2007-05-30
Posts: 100+

Re: Need help: move from first to 12th sprite in order

Update: I uploaded "4 targets" a super-simple example of the problem of moving to sequential targets and Paddle2See responded.  He says that the online engine currently has no way of using motion on a string object.  (Refer to that project if my paraphrase isn't accurate, please.)  So I've decided to stick with the original form of "Cleaning Medley" and delete the two "test" projects I uploaded.  "4 targets" will stay for awhile because of Paddle2See's helpful comments.

Thanks for all the help and the scripts!!  They work great on my computer.  Just not online.  Paddle2See said he'd write up the problem and maybe it'll get fixed sometime.

Offline

 

Board footer