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

#1 2011-05-26 02:52:34

Cameocool999
Scratcher
Registered: 2010-09-17
Posts: 38

Need help with fixing my random generator

I am working on a random terrain generator similar to minecraft but 2d. It starts by generating the terrain in number form, with stone being 1, dirt being 0, and grass being 2.

But i have run into a problem. For some reason, the terrain it generates is very weird. Heres pictures of the key scripts (Can't use IMG because i'm a new member):
http://i1230.photobucket.com/albums/ee487/epicpineapplepie/Screenshot2011-05-26at65026PM.png?t=1306392679
http://i1230.photobucket.com/albums/ee487/epicpineapplepie/Screenshot2011-05-26at65045PM.png?t=1306392704
And the terrain it generates:
http://i1230.photobucket.com/albums/ee487/epicpineapplepie/Screenshot2011-05-26at61720PM.png?t=1306392727

Can anybody help me isolate the problem?

Offline

 

#2 2011-05-26 04:37:22

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Need help with fixing my random generator

Are you using the pick random () to () block simply? Like:

Code:

repeat (however many squares you need)
  add (pick random (0) to (2) to [terrain]

Offline

 

#3 2011-05-26 07:25:21

deerel
Scratcher
Registered: 2008-08-23
Posts: 89

Re: Need help with fixing my random generator

Bad managing of flatness. You can easily get it to 0 (and then you divide by zero!) and often it gets to 1 or -1 (when "/(flatness/4)" means "*4" or "*(-4)").

Overall, your code is pretty bad. Delete it all, take a deep breath and write it anew, better.
For example use variables when convenient (instead of replace item by join that same item with something), don't use it when not needed (random stuff variable, unless it is used otherwise, should not be there, the random 1 to 3 should inside if), and separate different stages from each other (generate pure heights first, replace them by a 1...100002 in subsequent loop), and use less random blocks (it just shows that you programmed without thinking it over first, especially those random 0 to 4 things in flatness part).

Offline

 

#4 2011-05-27 17:17:46

Cameocool999
Scratcher
Registered: 2010-09-17
Posts: 38

Re: Need help with fixing my random generator

deerel wrote:

Bad managing of flatness. You can easily get it to 0 (and then you divide by zero!) and often it gets to 1 or -1 (when "/(flatness/4)" means "*4" or "*(-4)").

Overall, your code is pretty bad. Delete it all, take a deep breath and write it anew, better.
For example use variables when convenient (instead of replace item by join that same item with something), don't use it when not needed (random stuff variable, unless it is used otherwise, should not be there, the random 1 to 3 should inside if), and separate different stages from each other (generate pure heights first, replace them by a 1...100002 in subsequent loop), and use less random blocks (it just shows that you programmed without thinking it over first, especially those random 0 to 4 things in flatness part).

Well, this is only my second project, and the first one i have done in about 5 months. Thanks for your semi-constructive criticism. I have fully realized the problem that i had before and built up a lot of the code from scratch. The first version should be up within the hour.

Offline

 

Board footer