Discuss Scratch

lunar_red-ribbon
New Scratcher
1 post

How to Set X and Y Limits w/ Random Position

For a game I'm making, I'm trying to code it so the target has a limit for how it can go but I don't know how to do it.
GAMS2
Scratcher
1000+ posts

How to Set X and Y Limits w/ Random Position

If you are looking to limit how far the x and y can go when randomized here's some code for that:

gotox:pickrandom...to...y:pickrandom...to...

For example if you only want it to go between -10 and 10 x and -10 and 10 y:
gotox:pickrandom-10to10y:pickrandom-10to10

Last edited by GAMS2 (March 25, 2025 16:37:03)

geramihasfood
Scratcher
100+ posts

How to Set X and Y Limits w/ Random Position

lunar_red-ribbon wrote:

For a game I'm making, I'm trying to code it so the target has a limit for how it can go but I don't know how to do it.
you could code a variable called limit
limit
then set it to the limit you want it to be at
setlimitto...
after that you can use the variable and use it in this
gotox:pickrandom...*-1to...y:pickrandom...*-1to...
and you'll get this script
gotox:pickrandomlimit*-1tolimity:pickrandomlimit*-1tolimit

an example of the script could be
setlimitto10gotox:pickrandomlimit*-1tolimity:pickrandomlimit*-1tolimit

I hope this helped.

Last edited by geramihasfood (March 25, 2025 18:29:06)

Powered by DjangoBB