ID:2049945
 
(See the best response by FKI.)
Hello guys, I'm having trouble trying to use this proc to display the icon of datum with it's overlays on the browser, I was hoping one of you could help me out:

Code:
datum/object
var/icon/onscreen_image

proc/generate_icon()
onscreen_image = icon('icons/effects/effects.dmi', "nothing")


var/image/background = new('icons/obj/background.dmi', "background_[pick(0,1,2,3)]")
var/image/texture = new('icons/obj/textures.dmi', "texture_0")
var/image/elevation = new('icons/obj/elevation.dmi', "elevation_0")
elevation.alpha = 126

var/icon/I

I += background
I += texture
I += elevation

var/icon/stamp = getFlatIcon(I)
onscreen_image.Blend(stamp, ICON_OVERLAY)


And to display it on the browser:
user << browse_rsc(Q:onscreen_image, "onscreenimage.png")

dat += "<div class='statusDisplay'><center><img src=onscreenimage.png width=64 height=64></center></div>"


And when I test it out, the icon inside the browser is blank (icon('icons/effects/effects.dmi', "nothing")) (The first line in generate_icon proc)

Does anyone know what I did wrong?
Thanks :)

Best response
I think you missed some DM tag wrappings.

But one thing I see that I believe is incorrect is your use of browse_rsc(). For the file parameter (the first argument), you are sending a given datum's onscreen_image, which is an icon object, not a file (not sure if the former would work in that case though).

Another thing I noticed is you are creating those images incorrectly; the second argument used in creating an image is the atom it should be attached to (if any). You are passing icon_states instead, so your images don't actually have icon_states.
Fixed the DM tags.

I used the exact code that SS13 preferences datum uses to display the mob with it's job specific clothes in the browser. It also uses browse_rsc(preview_icon,previewicon.png)
, where preview_icon is nothing more than var/icon/preview_icon

As for images, you are right about the loc var, however I never had any problems with making images with the code above.

In case it doesn't work that way with datums, how should I fix it? Like this: ?
var/image/background = new('icons/obj/background.dmi', icon_state = "background_[pick(0,1,2,3)]")
In response to Infernus44
Yeah, like that.

I'm not familiar with SS13. If you could show me the original code, that might help.
https://github.com/tgstation/-tg-station/blob/master/code/ __HELPERS/icons.dm#L648

Here is the tgstation implementation

most are fairly similar in being modified versions of a proc by DarkCampainger.
In response to Optimumtact
My fault; I meant to show the original version of the generate_icon() proc and where it's being used via the browse() proc.

@Infernus44: Have you tried a bit of procedural debugging to figure out where exactly the code goes wrong? If so, where does the problem begin?

Not much to go on, so I'm pulling at loose strings here. There have been occurrences where I've tried using getFlatIcon() for similar purposes and it would produce nothing at all, with no reason as to why. Other times, it works beautifully. I don't want to think that's the case here though.
I'm not at my computer right now, so I will post the code and debug results tomorrow.