turf
Turfs
Environment

Earth
icon='Earth.dmi'

Grass
icon_state="A 1"
New()
icon_state="A [rand(1,13)]"


I find my way of doing it more simplistic xD.
In response to Zasif
Lol
XD
idk, this is how i'd go about it.
turf
var
states = FALSE//FALSE
New()
..()
if(states)
var
list/list = icon_states(icon,2)
length = length(icon_state)+1
for(var/string in list)
if(copytext(string,1,length)!=icon_state)list -= string
if(list&&list.len)icon_state = "[pick(list)]"
/*
Example
icon_state = "sword" //default
if you have the states
sword a
sword b
sword c
sword d
sword eg45g4
it will choose from those as long as the beginning matches the default icon_state

*/
In response to Kozuma3
Okay everyone, look at this skill. This is A+ code right there.
Kozuma, you should really be using findtext, not copytext there. Copytext is a lot slower because it has to generate a new string, and THEN you compare it. Also, you should be checking list and list.len.

An alternative, since icon_states() can be very slow depending on how many states the icon contains - you can simply add your randomized turfs as direction frames, but that only allows a maximum of 8 forms.

simply:
turf.dir = pick(NORTH, SOUTH, EAST, WEST, NORTHEAST,\
NORTHWEST, SOUTHEAST, SOUTHWEST)
In response to Super Saiyan X
Super Saiyan X wrote:
Also, you should be checking list and list.len.
I do with if(list)

An alternative, since icon_states() can be very slow depending on how many states the icon contains - you can simply add your randomized turfs as direction frames, but that only allows a maximum of 8 forms.

That works too ^^

In response to Kozuma3
Kozuma3 wrote:
Super Saiyan X wrote:
Also, you should be checking list and list.len.
I do with if(list)

An alternative, since icon_states() can be very slow depending on how many states the icon contains - you can simply add your randomized turfs as direction frames, but that only allows a maximum of 8 forms.

That works too ^^


if(list) only checks if the list object exists. Not if it has contents. If it has no contents after your loop removes all the strings, it'll set the icon_state to blank, which might not be desired behavior.
In response to Super Saiyan X
Super Saiyan X wrote:
if(list) only checks if the list object exists. Not if it has contents. If it has no contents after your loop removes all the strings, it'll set the icon_state to blank, which might not be desired behavior.

Ah, fixed ^^

Page: 1 2