ID:150155
 
I've been working on the weather system for my newest project and I've run into a bit of a snag, I'm trying to make the wind effect the direction the rain moves. So I tried to make the icon_state of the rain equal the global var winddirection:

var/winddirection

obj
weather
rain
icon='weather.dmi'
icon_state=winddirection

proc
windcheck()
var/Direction = rand(1,4)
switch(Direction)
if(1)
winddirection="North"
//I do this for all of the directions


Now, no matter what I try (I've been trying to an hour) I keep getting this error:

"Expected constant expression" on the line of the icon_state
And when I try to make a var like

obj
weather
rain
var/DIR = winddirection
icon='weather.dmi'
icon_state=DIR


I get an "Invalid variable" error on the icon_state line.

Any suggestions?

Nadrew wrote:
> var/winddirection
>
> obj
> weather
> rain
> icon='weather.dmi'
> icon_state=winddirection


You can't initialize a variable to the value of another variable. If you want to do that, you have to do it in New(). That's because the compiler doesn't necessarily know what value winddirection will have at the time the rain object is created in the game.

In response to Air Mapster
Thanks no errors, next small question does using it as an overlay even call New()? Because now no icon appears and I think it's because no icon_state gets set because New() isn't called.

[Edit]
Yep, I was right creating it as an overlay New() isn't called.
In response to Air Mapster
also remember to space these

icon_state = winddirection
In response to Migzor
That really doesn't matter.
In response to Nadrew
Nadrew wrote:
Thanks no errors, next small question does using it as an overlay even call New()? Because now no icon appears and I think it's because no icon_state gets set because New() isn't called.

Another reason an icon may not appear for you is that you should set icon_state="[winddirection]", since icon_state is supposed to be a string.

Lummox JR
In response to Nadrew
Nadrew wrote:
Thanks no errors, next small question does using it as an overlay even call New()? Because now no icon appears and I think it's because no icon_state gets set because New() isn't called.

Another reason an icon may not appear for you is that you should set icon_state="[winddirection]", since icon_state is supposed to be a string.

One thing you may want to consider, if you haven't thought of this already, is that it might be preferable to use 4-direction icons for what you're doing. Since NORTH, SOUTH, EAST, and WEST are defined as 1, 2, 4, and 8 (not necessarily in that order, though!), just set dir=1<<rand(0,3). Might be worth trying, perhaps for later modifications once you get the basic code running.

Lummox JR
In response to Lummox JR
I know, that's what I did.
Try adding the ("")


i don't know if it will help or not, but give it a try



obj
weather
rain
icon='weather.dmi'
icon_state = "winddirection"