ID:148008
 
I have an object with an icon which I want to get the icon states for. I set a var/icon/I to equal the objects icon, then I set a var/list/L to equal I.IconStates. When that part of the program executes, I get a runtime-error reading "cannot execute null.IconStates()".

//my code
client/proc/pic(icon/icon)
view=1
var/obj/O=new
O.icon=icon;O.loc=mob.loc;O.icon_state="3,3"
var/icon/I=O.icon
if(I)
var/list/L=I.IconStates()
//end code

I added in the view=1 and the loc/icon_state for O just to make sure that it did have an icon. I even added the if(I) to make the line only run if I is not null. I don't see why I'm getting a "cannot execute null.IconStates()" error since I is definately not null.

As allways, all help appreciated.
IconStates() is not a proc that belongs to /icon, but rather takes an /icon as an argument. Hit F1 and check it out in the help.
In response to tenkuu (#1)
tenkuu wrote:
IconStates() is not a proc that belongs to /icon, but rather takes an /icon as an argument. Hit F1 and check it out in the help.

I thank you for the help, as it was meant to be helpful, but actually IconStates() does belong to /icon, and it shows that in the help. If that were not the case my error would show at compile time rather than at runtime. I even tried IconStates(I) once just to make sure, and that gave a compile time error.

Maybe I should be a bit clearer: The runtime error states that it cannot execute null.IconStates(), which would usually mean that 'I' (the variable that it is assuming is null) is equal to null, but it's not. So, what else could cause that runtime error other than the variable being null? I suppose this turns out to be more of a question about byond itself and should have gone into the "Byond Q&A" section of the forum. If it does not get answered here I will repost it there later on.

Thank you for your time and help.
In response to Loduwijk (#2)
Whoa, I was thinking of that other proc that does the same thing but is named differently.(icon_states(icon)) Anyway, back to the problem at hand.

You're not assigning an icon object with this line:

var/icon/I=O.icon

Try doing:

var/icon/I=new(O.icon)
In response to tenkuu (#3)
Thank you, I don't see why I didn't notice that. I even opened up some of my past projects in which I used IconStates() and compared them to see what I was doing wrong, and I must have glanced right over that without noticing.

Now I can use my Graphics() function without putting in the specifications in the code for every dmi that I pass into it. Thanks much for the help.