Discuss Scratch

GoodChristianName
Scratcher
14 posts

How do I make a sprite appear at a random position at the top border?

Hi guys! So I'm trying to make a game based off of a story that I thought of about a virus that spreads through a dumb trend about licking toilet seats, and I've been trying to make the monster sprite appear randomly on the screen. I managed to do that but then I realised it would be impossible to hit them because since there's a border that I made teleport them to a random place on the screen at the bottom, it would just spawn there it would do that instantly go somewhere else, making it impossible to hit. So I've decided that I needed to make them spawn randomly at the top of the border so it can move downwards.

Please don't leave a text explanation, I understand better when you show the script, thanks!



~ A new scratcher.

Last edited by GoodChristianName (Oct. 25, 2017 21:20:43)

asivi
Scratcher
1000+ posts

How do I make a sprite appear at a random position at the top border?

AhSoddOff wrote:

Hi guys! So I'm trying to make a game based off of a story that I thought of about a virus that spreads through a dumb trend about licking toilet seats, and I've been trying to make the monster sprite appear randomly on the screen. I managed to do that but then I realised it would be impossible to hit them because since there's a border that I made teleport them to a random place on the screen at the bottom, it would just spawn there it would do that instantly go somewhere else, making it impossible to hit. So I've decided that I needed to make them spawn randomly at the top of the border so it can move downwards.

Please don't leave a text explanation, I understand better when you show the script, thanks!



~ A new scratcher.


I agree with you, we will understand you better if you share and post a link to your project.
Jay-TV
New Scratcher
30 posts

How do I make a sprite appear at a random position at the top border?

Wait, could you explain the question more please? Then I can help you.
gtoal
Scratcher
1000+ posts

How do I make a sprite appear at a random position at the top border?

when I start as a clone
go to x: (pick random (-240) to (240)) y: (180)

Last edited by gtoal (Oct. 26, 2017 07:41:27)

GoodChristianName
Scratcher
14 posts

How do I make a sprite appear at a random position at the top border?

Jay-TV wrote:

Wait, could you explain the question more please? Then I can help you.

Ok so, I'm trying to make the characters spawn at a random position at the top border of the screen you play on.

Like this,

https://imgur.com/a/nNH00
deck26
Scratcher
1000+ posts

How do I make a sprite appear at a random position at the top border?

AhSoddOff wrote:

Jay-TV wrote:

Wait, could you explain the question more please? Then I can help you.

Ok so, I'm trying to make the characters spawn at a random position at the top border of the screen you play on.

Like this,

https://imgur.com/a/nNH00
You're still not giving any real details of your problem though! It's hard to help if we don't understand the question.

@gtoal gave you a method to get a random position at the very top of the screen. If you want the y position to vary as well but within limited values just use a similar random block for the y.
GoodChristianName
Scratcher
14 posts

How do I make a sprite appear at a random position at the top border?

deck26 wrote:

AhSoddOff wrote:

Jay-TV wrote:

Wait, could you explain the question more please? Then I can help you.

Ok so, I'm trying to make the characters spawn at a random position at the top border of the screen you play on.

Like this,

https://imgur.com/a/nNH00
You're still not giving any real details of your problem though! It's hard to help if we don't understand the question.

@gtoal gave you a method to get a random position at the very top of the screen. If you want the y position to vary as well but within limited values just use a similar random block for the y.

Omg, I'm so sorry, I don't really understand all of what you're saying, I'm super new to programming ;(. So what I'm seeing from this post is that i need to use a random block for y?
Because from what I've just done to check what y and x means, I'm pretty sure y means upwards?? And seeing as you still don't seem to understand the issue, the image that I just showed you is meant to represent the line that the sprite starts off in. The sprite spawning any farther than that is my problem. Because since I put something at the bottom that teleports the sprite to a random position on the screen, it just spawns on the line and disappears making it impossible to hit.

Last edited by GoodChristianName (Oct. 26, 2017 16:27:18)

deck26
Scratcher
1000+ posts

How do I make a sprite appear at a random position at the top border?

y goes from -180 (bottom ) to 180 (top). x goes from -240 at left to 240 on the right. Try moving your mouse and watch the coordinates change under the Scratch screen.

If you want something to go to the very top of the screen setting y to 180 will do that (assuming the costume is properly centred) but if you want it to be randomly between y=160 and 180 you need to tell Scratch that.
GoodChristianName
Scratcher
14 posts

How do I make a sprite appear at a random position at the top border?

deck26 wrote:

y goes from -180 (bottom ) to 180 (top). x goes from -240 at left to 240 on the right. Try moving your mouse and watch the coordinates change under the Scratch screen.

If you want something to go to the very top of the screen setting y to 180 will do that (assuming the costume is properly centred) but if you want it to be randomly between y=160 and 180 you need to tell Scratch that.


OMLL. I DID IT. I'M SO HAPPY THANK YOU SO SO SO SO SO SO SO MUCH!

DEFINITELY PUTTING YOU GUYS IN THE CREDITS!





-oh wait, but now i have another problem- This one might be a bit more simple, but how do I make a wall that a sprite can't get through?
deck26
Scratcher
1000+ posts

How do I make a sprite appear at a random position at the top border?

AhSoddOff wrote:

deck26 wrote:

y goes from -180 (bottom ) to 180 (top). x goes from -240 at left to 240 on the right. Try moving your mouse and watch the coordinates change under the Scratch screen.

If you want something to go to the very top of the screen setting y to 180 will do that (assuming the costume is properly centred) but if you want it to be randomly between y=160 and 180 you need to tell Scratch that.


OMLL. I DID IT. I'M SO HAPPY THANK YOU SO SO SO SO SO SO SO MUCH!

DEFINITELY PUTTING YOU GUYS IN THE CREDITS!





-oh wait, but now i have another problem- This one might be a bit more simple, but how do I make a wall that a sprite can't get through?
Standard method which generally works is move the sprite, check if it is touching the wall (touching sprite is better than touching colour) and undo the move if so. That happens quick enough that you don't see the move.

move (5) steps
if <touching [wall v] ?> then
move (-5) steps
end
GoodChristianName
Scratcher
14 posts

How do I make a sprite appear at a random position at the top border?

deck26 wrote:

AhSoddOff wrote:

deck26 wrote:

y goes from -180 (bottom ) to 180 (top). x goes from -240 at left to 240 on the right. Try moving your mouse and watch the coordinates change under the Scratch screen.

If you want something to go to the very top of the screen setting y to 180 will do that (assuming the costume is properly centred) but if you want it to be randomly between y=160 and 180 you need to tell Scratch that.


OMLL. I DID IT. I'M SO HAPPY THANK YOU SO SO SO SO SO SO SO MUCH!

DEFINITELY PUTTING YOU GUYS IN THE CREDITS!





-oh wait, but now i have another problem- This one might be a bit more simple, but how do I make a wall that a sprite can't get through?
Standard method which generally works is move the sprite, check if it is touching the wall (touching sprite is better than touching colour) and undo the move if so. That happens quick enough that you don't see the move.

move (5) steps
if <touching [wall v] ?> then
move (-5) steps
end
It worked! Thanks alot!
GoodChristianName
Scratcher
14 posts

How do I make a sprite appear at a random position at the top border?

oh no bois.

i need a bit more help ;(.

So, I want a certain costume of a sprite to do something when it touches another sprite, how do I do it?
asivi
Scratcher
1000+ posts

How do I make a sprite appear at a random position at the top border?

Let me suggest you to start in https://scratch.mit.edu/starter_projects

Last edited by asivi (Oct. 27, 2017 13:10:32)

GoodChristianName
Scratcher
14 posts

How do I make a sprite appear at a random position at the top border?

asivi wrote:

Let me suggest you to start in https://scratch.mit.edu/starter_projects
Can I learn what to do in there?
deck26
Scratcher
1000+ posts

How do I make a sprite appear at a random position at the top border?

All you need is a loop around an if block that detects touching and checks the costume number. I suspect @asivi is right though, spend soem time learning more of the basics.
GoodChristianName
Scratcher
14 posts

How do I make a sprite appear at a random position at the top border?

deck26 wrote:

All you need is a loop around an if block that detects touching and checks the costume number. I suspect @asivi is right though, spend soem time learning more of the basics.
I'll probably try doing the practice stuff, but can you show that in block form please?
deck26
Scratcher
1000+ posts

How do I make a sprite appear at a random position at the top border?

GoodChristianName wrote:

deck26 wrote:

All you need is a loop around an if block that detects touching and checks the costume number. I suspect @asivi is right though, spend soem time learning more of the basics.
I'll probably try doing the practice stuff, but can you show that in block form please?
if <<(costume #) = []> and <touching [ v] ?>> then

end
But this is fairly basic given I'd already told you what to check for - try not to need things being presented in blocks, be prepared to think it through and work things out. Above is an ‘if block that detects touching and checks the costume number’ as previously suggested.
GoodChristianName
Scratcher
14 posts

How do I make a sprite appear at a random position at the top border?

deck26 wrote:

GoodChristianName wrote:

deck26 wrote:

All you need is a loop around an if block that detects touching and checks the costume number. I suspect @asivi is right though, spend soem time learning more of the basics.
I'll probably try doing the practice stuff, but can you show that in block form please?
if <<(costume #) = []> and <touching [ v] ?>> then

end
But this is fairly basic given I'd already told you what to check for - try not to need things being presented in blocks, be prepared to think it through and work things out. Above is an ‘if block that detects touching and checks the costume number’ as previously suggested.

Thanks so much for the advice, I really appreciate you guys alot. But I've seem to done exactly what you've done (while trying to understand the code) and it seems to not be working.

https://imgur.com/a/uZLTY

Last edited by GoodChristianName (Oct. 27, 2017 15:34:35)

deck26
Scratcher
1000+ posts

How do I make a sprite appear at a random position at the top border?

A single block out of context tells us nothing really. We'd have to see the project, see what kind of loop this was in, check the loop was running etc etc.
GoodChristianName
Scratcher
14 posts

How do I make a sprite appear at a random position at the top border?

deck26 wrote:

A single block out of context tells us nothing really. We'd have to see the project, see what kind of loop this was in, check the loop was running etc etc.
True lol.

Here's the project.

https://scratch.mit.edu/projects/182128794/

Powered by DjangoBB