Pages: 1
Topic closed
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
I think this will help... copy this script:
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.
Any questions?
Offline
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
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
Here we go, same concept, except using a list of sprite names:
Again, I haven't tried, as you can see, all this project has is the list and variables.
Here is the zoomed in script:
I hope that helps!!
Last edited by greenflash (2009-10-05 22:50:40)
Offline
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!"
Offline
Not necessarily - You could use this script:
[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
That is basically the same script.
Offline
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
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
Topic closed
Pages: 1