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

#1 2011-04-03 12:41:44

cullmeister
Scratcher
Registered: 2010-05-17
Posts: 6

problem with certain script

making an rpg trying to get this script to work with the main player:

[blocks]
<when I receive[ start
<show>
<go to x sad  0 )y sad  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 sad  safe x )y sad  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

 

#2 2011-04-04 10:34:57

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: problem with certain script

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.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#3 2011-04-04 16:19:08

cullmeister
Scratcher
Registered: 2010-05-17
Posts: 6

Re: problem with certain script

here's the link thanks

http://scratch.mit.edu/projects/cullmeister/1701675

Offline

 

#4 2011-04-04 17:03:13

06dknibbs
Scratcher
Registered: 2008-01-29
Posts: 1000+

Re: problem with certain script

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.  smile

Last edited by 06dknibbs (2011-04-04 17:05:29)


http://i404.photobucket.com/albums/pp129/06dknibbs/Untitled-3-6.jpg

Offline

 

#5 2011-04-04 17:04:25

cullmeister
Scratcher
Registered: 2010-05-17
Posts: 6

Re: problem with certain script

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

 

Board footer