ID:1714191
 
Keywords: random, rougelike, tiles
(See the best response by Nadrew.)
Code:Randomization
Hey guys sorry for the onslaught of questions tonight, I am writing a code to make random turfs on the map as rougelikes tend to have randomization for replay value. this is my first shot at it and it doesnt give errors it just doesn't make the turfs as I want it to :P I put the random mob on the map and it doesn't change into a floor or water tile then delete the mob as I had hoped it just sits there lol. If you know why it doesn't work or have a easier way to go about this I would appreciate it :)

mob/random_tile
density = 0
text = ""
New()
randomize()
mob/proc/randomize()
while(src)
if(src.random == 0)
if(rand(1,2) == 1)
new/turf/water in src.loc
random += 1
sleep(1)
else
new/turf/floor in src.loc
random += 1
sleep(1)
else
del(src)



Thanks in advance,
Bloodocean7.

Best response
There's a few issues here, the first I see is you're failing to call the parent inside of New(), which in this case isn't going to really do much for you, but it'll save headaches in the future as you expand on the system. The next is that you're not spawn()ing off the randomize() call inside of New(), which is going to make the proc wait for the loop inside of randomize() to finish, which can lead to issues in initializing variables and whatnot properly.

Now we'll look at randomize itself, the way you have it setup now there's not even really a need for a loop, because it's just going to fire once and delete the mob (which will terminate the loop).
mob/random_tile
density = 0
text = "*"
New()
..()
spawn(1) randomize()
mob/proc/randomize()
var/list/random_types = list(/turf/water,/turf/floor)
// Now you just have to add types to this list to expand the possibilities.

var/picked_type = pick(random_types)
// This will pick a random item in the list, you can also do weighted items here, check the F1 reference on pick()

new picked_type(src.loc)
del(src)


Notice the syntax of usage of 'new' here, your usage was close to proper but not quite right, in the context you used it in your code you'd want:
new/turf/floor(src.loc)


You can pass custom arguments through the usage of new as well, which will be passed through the New() call of the turf.
Thanks so much man! It works! and I have learned alot from just this code, I learned mostly offline by trial and error so I am starting to see my code is a tad wonky lol now that I have random tiles now I just need the npcs to move right and I will have the ground work for my rougelike :)

Thanks for your patience with my many questions I assure you I am trying to work through my issues first before posting here :)

Hey one more thing:

How can I prioritize one turf over another? like I want floor to appear more often than the water for example.

otherwise it will be rather hard to navigate the z map lol

(I see something about probability in the help but Im pretty confused how to set it up with out errors.)
Look up prob() and pick() in the ref.