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:
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.
Offline
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
Offline
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
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
Offline
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![]()
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
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![]()
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?
Offline
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![]()
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
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
Offline
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 repeatYup. 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?
Offline
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...
:SYou 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
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!
Offline
Coolstuffs way put into script:
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
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
coolstuff wrote:
colorfusion wrote:
Coolstuffs way put into script:
http://i29.tinypic.com/23uyjv5.jpgActually, 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
Offline