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

#1 2010-07-13 02:29:09

BlueFlame
Scratcher
Registered: 2008-08-17
Posts: 100+

This Script Wont Work???

I'm making a classic laser & mirror game, and I'm having a bit of trouble with getting my laser to stop when it hits something (it's a small dot that moves and draws a line behind it). Anyway, this is the script that's not working:

Code:

When I recieve: Activate Laser
Forever
    Move -2 Steps
    If <Touching colour (black)>
           Broadcast: Reset Level (Failed Attempt)
           Stop Script
    End If
    If <Touching ((Goal))
           Broadcast: Next Level (Successful Attempt)
           Stop Script
    End If
End Forever

Help please? Thanks.


Scape - The mindbending puzzle by coolstuff  big_smile

Offline

 

#2 2010-07-13 07:11:58

GraemeK
Scratcher
Registered: 2010-06-14
Posts: 73

Re: This Script Wont Work???

Try this:

When I recieve: Activate Laser
Forever
    Move -2 Steps
    If <Touching colour (black)>
           Broadcast: Reset Level (Failed Attempt)
           Stop Script
    Else <Touching ((Goal))
           Broadcast: Next Level (Successful Attempt)
           Stop Script
    End If-Else
End Forever


http://internetometer.com/image/13865.png

Offline

 

#3 2010-07-13 07:17:35

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: This Script Wont Work???

Hm... If this object that it should be hitting is one pixel high or long, it could just be skipping over.

And though your script doesn't say it, I'm guessing you're using the pen to draw - so I think the issue is that it's drawing over the black before it can sense it. I remember an issue just like this a few weeks ago - but I can't seem to find it. Essentially, you need to have the pen up when you move, then have your "touching black" scripts, and if it isn't, go back, get the pen back down, and move forward again.

Offline

 

#4 2010-07-13 20:06:16

BlueFlame
Scratcher
Registered: 2008-08-17
Posts: 100+

Re: This Script Wont Work???

coolstuff wrote:

Hm... If this object that it should be hitting is one pixel high or long, it could just be skipping over.

That's definately not that case; I made sure that the black area was large enough for the laser not to able to skip over.

coolstuff wrote:

And though your script doesn't say it, I'm guessing you're using the pen to draw - so I think the issue is that it's drawing over the black before it can sense it. I remember an issue just like this a few weeks ago - but I can't seem to find it. Essentially, you need to have the pen up when you move, then have your "touching black" scripts, and if it isn't, go back, get the pen back down, and move forward again.

That wil take half of forever, and I'm pretty sure a gamer wouldn't want to wait that long. I'll try it anyway, and see if it works.

In the meantime, if anyone has any other ideas, they would be muchly appreciated  big_smile


Scape - The mindbending puzzle by coolstuff  big_smile

Offline

 

#5 2010-07-13 20:14:47

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: This Script Wont Work???

BlueFlame wrote:

coolstuff wrote:

And though your script doesn't say it, I'm guessing you're using the pen to draw - so I think the issue is that it's drawing over the black before it can sense it. I remember an issue just like this a few weeks ago - but I can't seem to find it. Essentially, you need to have the pen up when you move, then have your "touching black" scripts, and if it isn't, go back, get the pen back down, and move forward again.

That wil take half of forever, and I'm pretty sure a gamer wouldn't want to wait that long. I'll try it anyway, and see if it works.

In the meantime, if anyone has any other ideas, they would be muchly appreciated  big_smile

Actually, it doesn't take that long - it takes about (as a guess) 1.2x as long as before, because looping offsets the timing.

Offline

 

#6 2010-07-13 20:23:10

BlueFlame
Scratcher
Registered: 2008-08-17
Posts: 100+

Re: This Script Wont Work???

coolstuff wrote:

BlueFlame wrote:

coolstuff wrote:

And though your script doesn't say it, I'm guessing you're using the pen to draw - so I think the issue is that it's drawing over the black before it can sense it. I remember an issue just like this a few weeks ago - but I can't seem to find it. Essentially, you need to have the pen up when you move, then have your "touching black" scripts, and if it isn't, go back, get the pen back down, and move forward again.

That wil take half of forever, and I'm pretty sure a gamer wouldn't want to wait that long. I'll try it anyway, and see if it works.

In the meantime, if anyone has any other ideas, they would be muchly appreciated  big_smile

Actually, it doesn't take that long - it takes about (as a guess) 1.2x as long as before, because looping offsets the timing.

I'm not sure I'm with you. Wouldn't it take twice as long, because it has to take the same journey twice at the same speed?


Scape - The mindbending puzzle by coolstuff  big_smile

Offline

 

#7 2010-07-13 21:05:40

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: This Script Wont Work???

BlueFlame wrote:

coolstuff wrote:

BlueFlame wrote:


That wil take half of forever, and I'm pretty sure a gamer wouldn't want to wait that long. I'll try it anyway, and see if it works.

In the meantime, if anyone has any other ideas, they would be muchly appreciated  big_smile

Actually, it doesn't take that long - it takes about (as a guess) 1.2x as long as before, because looping offsets the timing.

I'm not sure I'm with you. Wouldn't it take twice as long, because it has to take the same journey twice at the same speed?

Not exactly. Allow me to explain.

When Scratch loops through stuff, it adds a considerable wait to what it does. Before looping through something again, it waits about 0.02 seconds or so - which may seem quite tiny, but is actually very significant.

Comparing the actual time it takes if you were to duplicate blocks "x" times vs. looping through them x times, it takes a lot longer to loop. For instance:

change x by 1
change x by 1

Doesn't take nearly as long as

repeat 2
  change x by 1
end repeat

This has been a key fact in many of my projects. In this case, since you're still looping through the same amount of times, little significant time has been added by putting more blocks within the loop because it takes about 1/10th as long to loop. While some time has been added, very little has.

Offline

 

#8 2010-07-13 21:27:45

BlueFlame
Scratcher
Registered: 2008-08-17
Posts: 100+

Re: This Script Wont Work???

coolstuff wrote:

I wrote:

I'm not sure I'm with you. Wouldn't it take twice as long, because it has to take the same journey twice at the same speed?

Not exactly. Allow me to explain.

When Scratch loops through stuff, it adds a considerable wait to what it does. Before looping through something again, it waits about 0.02 seconds or so - which may seem quite tiny, but is actually very significant.

Ok, sure.

coolstuff wrote:

Comparing the actual time it takes if you were to duplicate blocks "x" times vs. looping through them x times, it takes a lot longer to loop. For instance:

change x by 1
change x by 1

Doesn't take nearly as long as

repeat 2
  change x by 1
end repeat

Yup. That makes sense too.

coolstuff wrote:

This has been a key fact in many of my projects. In this case, since you're still looping through the same amount of times, little significant time has been added by putting more blocks within the loop because it takes about 1/10th as long to loop. While some time has been added, very little has.

What??? That may be the case, but I'd still be running through the Script twice. Like activating the laser twice, but only the second one would count...

:S


Scape - The mindbending puzzle by coolstuff  big_smile

Offline

 

#9 2010-07-13 21:53:28

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: This Script Wont Work???

BlueFlame wrote:

coolstuff wrote:

I wrote:

I'm not sure I'm with you. Wouldn't it take twice as long, because it has to take the same journey twice at the same speed?

Not exactly. Allow me to explain.

When Scratch loops through stuff, it adds a considerable wait to what it does. Before looping through something again, it waits about 0.02 seconds or so - which may seem quite tiny, but is actually very significant.

Ok, sure.

coolstuff wrote:

Comparing the actual time it takes if you were to duplicate blocks "x" times vs. looping through them x times, it takes a lot longer to loop. For instance:

change x by 1
change x by 1

Doesn't take nearly as long as

repeat 2
  change x by 1
end repeat

Yup. That makes sense too.

coolstuff wrote:

This has been a key fact in many of my projects. In this case, since you're still looping through the same amount of times, little significant time has been added by putting more blocks within the loop because it takes about 1/10th as long to loop. While some time has been added, very little has.

What??? That may be the case, but I'd still be running through the Script twice. Like activating the laser twice, but only the second one would count...

:S

You do it twice, but it's still faster because of the loop time delays.

BTW can I have your castle in scratchcraft?


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#10 2010-07-13 22:00:44

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: This Script Wont Work???

juststickman wrote:

BlueFlame wrote:

What??? That may be the case, but I'd still be running through the Script twice. Like activating the laser twice, but only the second one would count...

:S

You do it twice, but it's still faster because of the loop time delays.

BTW can I have your castle in scratchcraft?

Yep, spot on! Because there's no loop delay between doing it twice, it still goes pretty fast.

Offline

 

#11 2010-07-14 00:53:04

BlueFlame
Scratcher
Registered: 2008-08-17
Posts: 100+

Re: This Script Wont Work???

Uh huh...... I'll just trust your judgement on this one  smile


Scape - The mindbending puzzle by coolstuff  big_smile

Offline

 

#12 2010-07-14 00:54:04

BlueFlame
Scratcher
Registered: 2008-08-17
Posts: 100+

Re: This Script Wont Work???

juststickman wrote:

BTW can I have your castle in scratchcraft?

What? Are you talking to me or coolstuff?


Scape - The mindbending puzzle by coolstuff  big_smile

Offline

 

#13 2010-07-14 07:48:35

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: This Script Wont Work???

BlueFlame wrote:

juststickman wrote:

BTW can I have your castle in scratchcraft?

What? Are you talking to me or coolstuff?

I'd imagine he's talking to you - I've never heard of Scratchcraft  smile

Offline

 

#14 2010-07-14 11:33:59

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: This Script Wont Work???

BlueFlame wrote:

juststickman wrote:

BTW can I have your castle in scratchcraft?

What? Are you talking to me or coolstuff?

Blade said you made the giant castle in the scratchcraft server in minecraft. You!


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#15 2010-07-15 19:48:41

BlueFlame
Scratcher
Registered: 2008-08-17
Posts: 100+

Re: This Script Wont Work???

What is Scratchcraft?


Scape - The mindbending puzzle by coolstuff  big_smile

Offline

 

#16 2010-07-16 13:35:59

colorfusion
Scratcher
Registered: 2009-10-03
Posts: 500+

Re: This Script Wont Work???

Coolstuffs way put into script:

http://i29.tinypic.com/23uyjv5.jpg

Forgot to put the go back bit in, will make a dotted line like that.

Just put a move -2 then a move 2 after the pen down.

Last edited by colorfusion (2010-07-16 13:40:28)

Offline

 

#17 2010-07-16 13:37:58

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: This Script Wont Work???

colorfusion wrote:

Coolstuffs way put into script:

http://i29.tinypic.com/23uyjv5.jpg

Actually, that's a little different - your method won't draw a line.

I can make a graphical, tried-and-tested representation of my script when I get home.

Offline

 

#18 2010-07-16 20:29:15

BlueFlame
Scratcher
Registered: 2008-08-17
Posts: 100+

Re: This Script Wont Work???

coolstuff wrote:

colorfusion wrote:

Coolstuffs way put into script:

http://i29.tinypic.com/23uyjv5.jpg

Actually, that's a little different - your method won't draw a line.

I can make a graphical, tried-and-tested representation of my script when I get home.

I agree, it wont draw a line, but I kinda get what you guys are meaning now.

Thanks coolstuff  smile


Scape - The mindbending puzzle by coolstuff  big_smile

Offline

 

Board footer