making an rpg trying to get this script to work with the main player:
[blocks]
<when I receive[ start
<show>
<go to x 0 )y
0
<forever>
<if><key[ up ]pressed?>
<point in direction( 0
<move( 3 )steps>
<end>
<if><key[ down ]pressed?>
<point in direction( 180
<move( 3 )steps>
<end>
<if><key[ left ]pressed?>
<point in direction( -90
<move( 3 )steps>
<end>
<if><key[ right ]pressed?>
<point in direction( 90
<move( 3 )steps>
<end>
<if><touching color[ black
<go to x safe x )y
safe y
<else>
<set{ safe x }to( <x position>
<set{ safe y }to( <y position>
<end>
<end>
[/blocks]
basically I want to make the player move until it touches a wall (coloured black) but when I touch the wall instead of staying where it should be it goes to a random part of the screen, any ideas why this is happening and how do I fix it?
Offline
Hmm. It looks like it should work...unless it is starting off touching black right away, in which case Safe X and Safe Y would not be set properly before they were used. Can you give us a link to your project? That would make it easier to debug.
By the way, Troubleshooting is for problems with the Scratch software...not your scripts. Those go in All About Scratch - but no worries, I can move this there for you.
Offline
here's the link thanks
http://scratch.mit.edu/projects/cullmeister/1701675
Offline
The script works, but the mistake you made was where it should say:
[blocks]
<set{ safe x }to( <x position>
<set{ safe y }to( <y position>
[/blocks]
In the project, it says
[blocks]
<set{ safe x }to( <x position>
<set{ safe x }to( <y position>
[/blocks]
Which means the game is setting Safe X to the X position, and then replacing Safe X with the Y position before sending the sprite to the X position and Y=0 because safe Y stays as 0.
Last edited by 06dknibbs (2011-04-04 17:05:29)
Offline
wait a minute I see what I've done wrong I didn't change the last set to y and it was left on x silly me
edit: thanks anyway 06dknibbs
Last edited by cullmeister (2011-04-04 17:05:44)
Offline