Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Random Spawning Help
- CaptainSpinner
-
Scratcher
13 posts
Random Spawning Help
For a game I am making, I have several rooms in a “hotel” that the main character has to explore. The object of the game is to find an object to be able to escape. To make the game more interesting/fun, I want the object to spawn in different rooms and at different locations within the rooms each new game. If I can't accomplish this, then my game isn't really a game. Anyway, I figured the “pick random _ to _” block and “go to _” block needed to be utilized but I am having trouble finding a solution that works. Below is what I have so far, I think the main issue is with the “go to” and random selector portions. Any help is greatly appreciated.
http://imageshack.com/a/img921/62/9CgGOm.png
http://imageshack.com/a/img921/62/9CgGOm.png
- drmcw
-
Scratcher
1000+ posts
Random Spawning Help
Your script makes no sense at all perhaps if I explain that
<[] = []>is a Boolean reporter block and so returns a true or false. Put into a number slot will convert that to either 0 or 1, so you have a pick random between 0 and 1 or 1 and 0 or 0 and 0 dependent upon backdrop. See how nonsensical things get and that's just the start.
- deck26
-
Scratcher
1000+ posts
Random Spawning Help
Why bump? As @drmcw says your script makes no sense. You need to understand that.
What's the first ‘go to’ supposed to do? Go to with a single parameter should contain either ‘mouse pointer’ or the name of a sprite which is chosen from a drop down list. You're telling it to go to 0 unless the backdrop is one of the two shown in which case you're telling it to go to either 0 or 1 - none of these make sense.
The remaining blocks will only ever tell the sprite to go to a position definded by x=0 or x=1 and y=0 or y=1. Since these are so close together it's not going to make much difference.
What's the first ‘go to’ supposed to do? Go to with a single parameter should contain either ‘mouse pointer’ or the name of a sprite which is chosen from a drop down list. You're telling it to go to 0 unless the backdrop is one of the two shown in which case you're telling it to go to either 0 or 1 - none of these make sense.
The remaining blocks will only ever tell the sprite to go to a position definded by x=0 or x=1 and y=0 or y=1. Since these are so close together it's not going to make much difference.
- awesome5185
-
Scratcher
1000+ posts
Random Spawning Help
Try doing this:
Presuming you have a square computer!
For preset locations, you'll need two variables for each room, one for the X axis and one for the Y. Then go
when I start as a clone
hide
go to x: (pick random (-360) to (360)) y: (pick random (-360) to (360))
show
Presuming you have a square computer!
For preset locations, you'll need two variables for each room, one for the X axis and one for the Y. Then go
go to x: (location1x) y: (location1y)
Last edited by awesome5185 (Dec. 2, 2016 04:16:11)
- deck26
-
Scratcher
1000+ posts
Random Spawning Help
Please stop bumping. You asked for help and we've pointed out why what you're doing won't work. Do you understand what you're being told - if yes try to do it another way - if no seek clarification.
A boolean block will only ever return 0 or 1. All the blocks in your scripts which would normally take numbers have boolean blocks in them so every one will only ever be 0 or 1 which it seems very unlikely is what you want.
Please either clarify what you understand of what help you've received so far or describe in some detail what you're trying to do!
A boolean block will only ever return 0 or 1. All the blocks in your scripts which would normally take numbers have boolean blocks in them so every one will only ever be 0 or 1 which it seems very unlikely is what you want.
Please either clarify what you understand of what help you've received so far or describe in some detail what you're trying to do!
- amylaser
-
Scratcher
500+ posts
Random Spawning Help
bump^^ No need to bump someone else's post; they can do that themselves.
Anyway, as others have pointed out, the main problem with your code is that you are using the Scratch blocks incorrectly. Here's an explanation:
<[] = []> //this block checks whether a CONDITION is true or false. It does NOT set values to anything.
(x position) //this block tells you the CURRENT x position of the sprite. It does NOT change it.
(y position) //same as above, but for the y position
So, if you want your sprite to go to the coordinates (10,10), then you would do this:
go to x: (10) y: (10)
You don't need any of the extra green blocks or what you have in your scripts right now.
And if you want the sprite to go to one of two random positions associated with a specific backdrop, then you'll need another randomizer script.
Also, it's not really clear what you're trying to achieve with this script below:
go to (pick random <(backdrop #) = [6]> to <(backdrop #) = [6]>)
Doesn't really make sense to move the sprite to a backdrop number… That's not how you're supposed to use the “go to” block. Remember, there are two types of “go to” blocks:
go to x: (0) y: (0) //this one specifies coordinates to move to
go to [ v] //this one gives certain options: you can go to the mouse-pointer, another sprite, or a random position
The one you were using in the above script was the second type of “go to” block, but it's not meant to take in numerical values. I assume you were trying to change the backdrop rather than move the sprite. In which case, you're using the wrong block. Use these scripts instead:
switch backdrop to (pick random (6) to (11))
So overall, here's what your scripts should look like after you have edited them accordingly:
define hide gur
hide
switch backdrop to (pick random (6) to (11)) //switch to random room
set [random location inside room v] to (pick random (1) to (2)) //this is called a variable
if <(backdrop #) = [6]> then
if <(random location inside room) = [1]> then
go to x: (-119) y: (123)
else
go to x: (-169) y: (-69)
end
else
if <(backdrop #) = [7]> then
if <(random location inside room) = [1]> then
go to x: (-217) y: (-155)
else
go to x: (-133) y: (-18)
end
else
if <(backdrop #) = [8]> then
if <(random location inside room) = [1]> then
go to x: (-52) y: (94)
else
go to x: (-160) y: (107)
end
else
if <(backdrop #) = [9]> then
if <(random location inside room) = [1]> then
go to x: (159) y: (-34)
else
go to x: (-18) y: (80)
end
else
if <(backdrop #) = [10]> then
if <(random location inside room) = [1]> then
go to x: (-58) y: (104)
else
go to x: (107) y: (102)
end
else
if <(backdrop #) = [11]> then
if <(random location inside room) = [1]> then
go to x: (125) y: (100)
else
go to x: (220) y: (89)
end
end
end
end
end
end
end
show //you want the sprite to be visible, right?
And if you're still confused… Well, try sharing your project and post the link here so we can take a look at the scripts.
FYI, you can right-click a block to make an info box appear. Or you can look up the blocks on the scratch wiki ( https://wiki.scratch.mit.edu/wiki/Scratch_Wiki ) if you want more in-depth explanations of what the blocks do.
And one more note… You should only bump your post if it is not longer on the front page of the forum. Bumping your post after only a couple of hours is generally discouraged.
Last edited by amylaser (Dec. 2, 2016 20:42:41)
- asivi
-
Scratcher
1000+ posts
Random Spawning Help
bumpWhy you bump?
What you have done?
Even, There is a project?
- EmperorTang
-
Scratcher
21 posts
Random Spawning Help
bump i have the exact same problem but nobody is clear enuff
- slaterock38
-
Scratcher
13 posts
Random Spawning Help
Hi there im new to scratch, can someone bump, this is not clear enough for me
- slaterock38
-
Scratcher
13 posts
Random Spawning Help
I see what you did there emperor tang, I made some more modifications to the script, check it out
- TMebust
-
New Scratcher
7 posts
Random Spawning Help
hi! i am new to scratch?! what is with this bump business? Help from a pro-scratcher? thanks!
- slaterock38
-
Scratcher
13 posts
Random Spawning Help
I see what you did there emperor tang, I made some more modifications to the script, check it out
- Discussion Forums
- » Help with Scripts
-
» Random Spawning Help