ID:156448
 
Hi, I am trying to figure out how to pick a random icon_state for a turf.

Ex. I am trying to make a sandy beach area, I made a couple of different icons of sand and want it to randomly pick a different state for each square of sand I lay down on the map. I tried this

turf
sand
icon = 'turf.dmi'
icon_state = pick("sand1","sand2","sand3")

and it give me
turf.dm:11:error: : expected a constant expression


am I going about this wrong? what do I need to do to get a random plot of sand?
Put it in the New() proc.
In response to Garthor
hmm all the ways I try dont work.

turf
sand
icon = 'turf.dmi'
new()
icon_state = pick("sand1","sand2","sand3")


and that gives me
turf.dm:11:error: : empty type name (indentation error?)
turf.dm:11:error: new: instruction not allowed here
turf.dm:12:error: : empty type name (indentation error?)
In response to BrewmasterP
BrewmasterP wrote:
hmm all the ways I try dont work.

> turf
> sand
> icon = 'turf.dmi'
> new()
> icon_state = pick("sand1","sand2","sand3")
>
>

and that gives me
> 
> turf.dm:11:error: : empty type name (indentation error?)
> turf.dm:11:error: new: instruction not allowed here
> turf.dm:12:error: : empty type name (indentation error?)
>



New()
icon_state=pick(blah,blah)
In response to Teh Governator
Teh Governator wrote:
BrewmasterP wrote:
hmm all the ways I try dont work.

> > turf
> > sand
> > icon = 'turf.dmi'
> > new()
> > icon_state = pick("sand1","sand2","sand3")
> >
> >

and that gives me
> > 
> > turf.dm:11:error: : empty type name (indentation error?)
> > turf.dm:11:error: new: instruction not allowed here
> > turf.dm:12:error: : empty type name (indentation error?)
> >


Look, you can't just go making up procedures like "new()" and expecting them to work. The procedure required is called "New()", and the capitalization is absolutely key there.
In response to Yurokei
thank you
it was because i didn't capitalize New()
In response to BrewmasterP
Not exactly. You see, everything in Byond has working 'cognates'. With variables, there are certain times when you should be changing them. You can't "define" them as being a procedure, if you see what I'm saying here.

In example, this wouldn't work:


obj/Pin
icon_state = pick("Red","Blue","Green")


because you can't change a variable's status as you're defining it in a situation like this.

What you should be doing is using the New() procedure, because New() is called when you create an object under new.

In example, this is the proper way you should go about doing something such as this:

world/New() //Called when the world is started
var/obj/Pin/P = new //create a new instance of it
P.loc = locate(1,1,1)
..() //Continue with regular procedures

obj/Pin
icon = 'Pins.dmi'
icon_state = ""
New() //called when new instance is created
P.icon_state = pick("Red","Blue","Green")