ID:139555
 
Code:
    changeicon(i as icon)
set name = "Change Icon"
set category = "Player"
var/d="[i]"
if(findtext(d,".dmi"))
switch(alert("Are you sure?","Confirm","Yes","No"))
if("Yes")
var/icon/I = ("[i]")
var/w = I.Width()
var/h = I.Height()
if(w>=33||h>=33)
I.Scale(32,32)
src.icon = I
alert("You have successfully set your new icon.")
else
src.icon = i
alert("You have successfully set your new icon.")
else
alert("You can only set a .dmi file as your icon.")


Code:
runtime error: Cannot execute null.Width().
proc name: Change Icon (/mob/verb/changeicon)
usr: Blade (/mob)
src: Blade (/mob)
call stack:
Blade (/mob): Change Icon('blade_magus.dmi')

Problem description:
Top code is the actual code for my icon change verb, I'm trying to make it so it automatically resizes oversized icons to 32x32 (and also checks if the users on the other end are trying to use JPG images and such instead of dmi's.)
Bottom is the display in Dream Daemon.

It refuses to give me my icon, oversized or legal-sized, no matter what I change on it. Please help me understand and fix this. It's not doing what it claims it does in the examples in BYOND's reference.

edit: This problem has been fixed, read my response to Lummox JR for my current problem.
You might have to do:
var/icon/I = new("[I]")


Not sure if that will fix it or not. :P
In response to Hi1
No, that just causes an infinite cross-reference loop.

Code:
main.dm:78:error: I:  compile failed (possible infinite cross-reference loop)
main.dm:79:error: I.Width: compile failed (possible infinite cross-reference loop)
main.dm:80:error: I.Height: compile failed (possible infinite cross-reference loop)
main.dm:81:error: w: compile failed (possible infinite cross-reference loop)
main.dm:81:error: h: compile failed (possible infinite cross-reference loop)
main.dm:82:error: I.Scale: compile failed (possible infinite cross-reference loop)
main.dm:83:error: I: compile failed (possible infinite cross-reference loop)

:(
BladePwnsYou wrote:
var/icon/I = ("[i]")


("[i]") is a string, not an /icon datum. This is why the code is failing.

Since i is an actual icon (a cache reference), that should be new(i) or icon(i). Either of those will return an /icon datum in this context.

Lummox JR
In response to Lummox JR
Thank you so much for the help, Lummox.

I have another sort-of related question, while I'm here.

I have a huge archive of icons that I've used before multiple times on other games on BYOND before, so I know there's nothing wrong with them. In my game, with that same code in the OP (except with icon(i) where it belongs now), certain icons (and the criteria for this seems to be random as hell) just do not load. I do not even get the "Are you sure?" message I put in, and it's not just me; other users in my gametester crew have reported the same problem with completely random icons. I have even put on icons from those other people who can't and vise versa.

Any ideas?

edit: No error messages in Dream Daemon either.
In response to BladePwnsYou
Simple solution! Don't use the "I" varible. Because that matches the same varible, in "var/icon/I". Use the varible on the top of the line of the code. Example: Change Icon(s as icon). Then plug that into new("[s]"). Then it shall work. Also. Random icons you say??? You must put in. icon_state="". Example: >>if(findtext(d,".dmi"))>>switch(alert("Are you sure?","Confirm","Yes","No"))>>if("Yes")>>var/ icon/I=new("[s]")>>var/w=I.Width()>>var/ I.Height()>>if(w>=33 || h>>33)>>I.Scale(32,32)>>src.icon=I>> src.icon_state=""

I'm sure you know how to finish the rest. :3 This shall work. I don't know didn't test it. I just seen, that you might wanna do that. XD
In response to Fun-n-games
Also!!!

do this!

var/icon/I =new("[s]",null)

That will work!! You're welcome. =3