Pages: 1
Topic closed
How can I color (or another way) the backgrounds, so I can keep my sprite from going in those areas. I already have the backgrounds made, but I could put lines on it to block that area. I am using scrolling with X and Y. When I have it stop "scroll X" and "scroll Y", my sprite just stops and gets stuck. How can I keep it from moving, like have it bounce back (slightly). Remember I am using scrolling, and I already have background, but I could put lines down. If you know of any sample projects that would be nice. If you know a way and can just type it out, that is fine too. All help appreciated, thanks.
Offline
OK, first make 2 variables oldScrollX and oldScrollY
First make sure all the places you don't want to go into is one colour.
Put this script in
when flag clicked
forever
if touching colour (specify colour)
set scrollX to oldScrollX
set scrollY to oldScrollY
end
set oldScrollX to scrollX
set oldScrollY to scrollY
end
This will make it so that the sprite will never end up inside the specified colour.
Offline
What do you mean by end? Do you mean stop script or what? Also will this work if I just draw lines? I want the player to be able to see into the distance of where they can't go.
Offline
Purplewalrus wrote:
What do you mean by end? Do you mean stop script or what? Also will this work if I just draw lines? I want the player to be able to see into the distance of where they can't go.
By end I mean this part of the block
<end>
This will work if you draw lines.
Last edited by archmage (2009-01-07 21:01:30)
Offline
This is what I'm doing, and it isn't working, the sprite just gets stuck on the line.
http://scratch.mit.edu/forums/post.php?tid=13311#req_message
http://scratch.mit.edu/forums/post.php?tid=13311#req_message
http://scratch.mit.edu/forums/post.php?tid=13311#req_message http://scratch.mit.edu/forums/post.php?tid=13311#req_message
http://scratch.mit.edu/forums/post.php?tid=13311#req_message Scroll X => old scroll X
http://scratch.mit.edu/forums/post.php?tid=13311#req_message Scroll Y => old scroll Y
http://scratch.mit.edu/forums/post.php?tid=13311#req_message
http://scratch.mit.edu/forums/post.php?tid=13311#req_message old scroll X => Scroll X
http://scratch.mit.edu/forums/post.php?tid=13311#req_message old scroll Y => Scroll Y
http://scratch.mit.edu/forums/post.php?tid=13311#req_message
Or you can look at the picture of it here:
http://i303.photobucket.com/albums/nn160/purplewalruscontact/Script.jpg
Offline
I just tried to make the pictures with those blocks that the forums lets you use, and it didn't work as you can see with my previous post. it just made links, i guess you'll have to use the picture.
Offline
I got it to work this time, this is what it should look like.
<when green flag clicked>
<forever>
<if><touching color[
<set{ Scroll X }to( old scroll X
<set{ Scroll Y }to( old scroll Y
<end>
<set{ old scroll X }to( Scroll X
<set{ old scroll Y }to( Scroll Y
<end>
Offline
When I said, "I got it to work this time." I meant I got the forum script to work, not the actual script
Offline
I will post a demo. The code in the picture is correct.
The code I game you should work, another one of your codes must be the problem.
http://scratch.mit.edu/projects/archtest/374293 <-- I made a project of it
Or if the case is that you just don't want the scroll away from all of the terrain sprites there is an easier solution. But I am assuming that there will be certain parts in your terrain sprites that you don't want the player to go into.
Last edited by archmage (2009-01-07 21:38:37)
Offline
Now I am really confused. When I looked at your project online it looked fine, it worked. When I downloaded it, it didn't work. Then when I uploaded mine to this website, thinking it would work like yours, it didn't work. Do you have any idea whats going on?
Offline
I think I know the problem. I tried having scroll X and Scroll Y change by 1 and -1, and it worked. I think it was because I am going to fast, and move into the black, not next to it. Do you know how to fix this problem?
Offline
Oh yeah, I downloaded it and got the same error.
Let me check it out, I know it has something to do with the lag on the terrain sprites.
Offline
Alright, thanks a lot!
Offline
I wish they would allow direct scripting
function newBlock(b,pos)
{
var pudding = pos
}
return pudding
end
>.>
To tell the truth I dont actually script Much Java, just a lil, but I know alot of lua, lua would be easier than java.
function SaySomething(Something)
print(Something," has been said because I wanted It to say that")
end
SaySomething("Lol")
Last edited by Hellbender (2009-01-07 22:07:02)
Offline
Hellbender wrote:
I wish they would allow direct scripting
function newBlock(b,pos)
{
var pudding = pos
}
return pudding
end
Kinda off topic. Try making your own thread instead of using an unrelated one.
Offline
This script is giving me a rough time :S
Let me explain why this should work and why this is the scratch program's fault.
lets assume that the user has the down arrow key down, and one more movement down will push the sprite into green space.
This is my script (ignore the get out broadcast, I was testing stuff)
So the code should run through as follows.
1.the variable scrollY is 95 now, one more increase and the sprites moves into green zone. The oldScrollY variable is set to 95.
2. The down arrow key is down so we change the scrollY variable by 5
3. Since we are now in the green zone we have a script to move out of the green zone. The script will set the scrollY variable which is set to 100 to the oldScrollY variable which is set to 95.
4. We are out of the green area and life is good
However THIS DOES NOT HAPPEN
Seriously, this defys all logic.
Last edited by archmage (2009-01-07 22:30:55)
Offline
Wait...so your saying it can't be done?
Offline
Purplewalrus wrote:
Wait...so your saying it can't be done?
No, there is a way, but it involves using sensor sprites. I am just saying that my logic is perfect and that in any other language this would have worked but scratch is stupid sometimes.
Wait a bit and I'll upload another solution.
Offline
Alright, thanks.
Offline
Here, it uses sprites to detect its surroundings
http://scratch.mit.edu/projects/archtest/374326
Download it, look at the code.
Offline
Ok, I figured out the problem in the first script too. You see, because scratch is slower to moves sprites offline the If Touching Green part was skipped because the terrain sprites hadn't moved yet. By the time they moved it is too late because the oldScroll variables were saved to a position inside the green part making the whole script to get out useless.
This new project uses the same script as the first one I gave you, but only records variables if you are not in a green spot.
Use this one instead.
http://scratch.mit.edu/projects/archtest/374330
Offline
OMG!!! Thank you sooo much! It finally works now!!! :-)
Offline
Amazing how I was able to figure all those things out eh?
I guess making all those program flowcharts and tests in computer science paid off
The key to solving problems to to first see where the script is going wrong then to isolate the faulty code and fix it. Remember that
Last edited by archmage (2009-01-07 23:16:25)
Offline
if only i saw this earlier. This is a very helpfull detection coding method as the sprite doesint apear to bounce, i use it all the time and its the perfect soltion, even to slow old scratch. (also arch, simply moving the colour hitTest before the variable reset should solve it aswell, although ive never tried it like that.
Offline
yambanshee wrote:
(also arch, simply moving the colour hitTest before the variable reset should solve it aswell, although ive never tried it like that.
Tried it, didn't work.
Offline
Topic closed
Pages: 1