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

#1 2012-11-06 11:26:44

joshamunga
New Scratcher
Registered: 2012-10-29
Posts: 5

Random generating obstacles

I am just wondering how to make obstacles randomly generate like Toasty's Adventure.

How??

Thx if you help,

Josh

smile

Offline

 

#2 2012-11-06 12:14:12

awesomeness321
Scratcher
Registered: 2012-08-10
Posts: 100+

Re: Random generating obstacles

when gf clicked//this goes in the obstacle
set x to(pick random (whatever the smallest number the x position can be is) to (whatever the largest number x position can be is))
then do the same for the y position.
I think that should work.


My newest project:http://blocks.scratchr.org/API.php?user=awesomeness321&action=projects&type=newest&return=image&num=1Color:#30F9A5 I am currently http://blocks.scratchr.org/API.php?user=awesomeness321&action=onlineStatus&type=text

Offline

 

#3 2012-11-08 13:17:39

joshamunga
New Scratcher
Registered: 2012-10-29
Posts: 5

Re: Random generating obstacles

How do you get the variable?

Jsohamunga

Offline

 

#4 2012-11-08 16:44:54

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Random generating obstacles

joshamunga wrote:

How do you get the variable?

Jsohamunga

They aren't supposed to be variables. Just read the "variables" and insert numbers for them. For example, you might use this:

when gf clicked//this goes in the obstacle
set x to(pick random (-180) to (180))


http://i46.tinypic.com/35ismmc.png

Offline

 

#5 2012-11-08 19:04:43

Unforgivableblack
New Scratcher
Registered: 2012-10-05
Posts: 5

Re: Random generating obstacles

ErnieParke wrote:

joshamunga wrote:

How do you get the variable?

Jsohamunga

They aren't supposed to be variables. Just read the "variables" and insert numbers for them. For example, you might use this:

when gf clicked//this goes in the obstacle
set x to(pick random (-180) to (180))

I'm also working on creating random obstacles How do you automate it to have the objects generated randomly throughout the game instead of when the the gf is clicked?

Offline

 

#6 2012-11-08 19:37:53

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Random generating obstacles

Unforgivableblack wrote:

ErnieParke wrote:

joshamunga wrote:

How do you get the variable?

Jsohamunga

They aren't supposed to be variables. Just read the "variables" and insert numbers for them. For example, you might use this:

when gf clicked//this goes in the obstacle
set x to(pick random (-180) to (180))

I'm also working on creating random obstacles How do you automate it to have the objects generated randomly throughout the game instead of when the the gf is clicked?

To automate it, just run the set x part of the script whenever you need to. For example, you might use:

when gf clicked
forever
 if (touching [edge v]?)
  set x to (pick random (-180) to (180))
 end
I hope that this answers your question!


http://i46.tinypic.com/35ismmc.png

Offline

 

#7 2012-11-10 13:40:50

Unforgivableblack
New Scratcher
Registered: 2012-10-05
Posts: 5

Re: Random generating obstacles

ErnieParke wrote:

Unforgivableblack wrote:

ErnieParke wrote:


They aren't supposed to be variables. Just read the "variables" and insert numbers for them. For example, you might use this:

when gf clicked//this goes in the obstacle
set x to(pick random (-180) to (180))

I'm also working on creating random obstacles How do you automate it to have the objects generated randomly throughout the game instead of when the the gf is clicked?

To automate it, just run the set x part of the script whenever you need to. For example, you might use:

when gf clicked
forever
 if (touching [edge v]?)
  set x to (pick random (-180) to (180))
 end
I hope that this answers your question!

thanks that definitely answered my question. the only problem i'm running into is that the sprite randomly appears incredibly fast. is there how would i slow it down?

Offline

 

#8 2012-11-10 13:52:57

Llamalover
Scratcher
Registered: 2007-05-18
Posts: 100+

Re: Random generating obstacles

Do you have any other code that controls the movement or speed of the obstacles? The code ErniePark changes the obstacle's position when it touches the edge, or when the project starts.


Be nice, I'm an old lady  wink

Offline

 

Board footer