It's not possible to create a new icon file without specifying a DMI file as input, even if you're going to do all the drawing yourself.
Numbered Steps to Reproduce Problem:
1. Use the code snippet below without specifying an icon.
2. Try to create an icon in this manner. Won't work.
3. Create an empty "blank.dmi" file with no icon states and pass it as the first argument. You can now create an icon dynamically.
Code Snippet (if applicable) to Reproduce Problem:
/icon/proc/DrawRectangle(rgb, x1, y1, x2, y2)
src.DrawBox(rgb(0, 0, 0), x1, y1, x2, y1)
src.DrawBox(rgb(0, 0, 0), x1, y2, x2, y2)
src.DrawBox(rgb(0, 0, 0), x1, y1, x1, y2)
src.DrawBox(rgb(0, 0, 0), x2, y1, x2, y2)
mob
var
health = 5
mana = 10
const
max_health = 10
max_mana = 10
use_bars = FALSE
tmp
bar_health = null
bar_mana = null
image
bars
proc
UpdateBars()
if (use_bars)
var/cont = !src.bars || src.bar_health == null || src.bar_mana == null || src.bar_health != src.health || src.bar_mana != src.mana
if (cont)
if (!src.bars)
src.bars = new/image(loc = src)
if (src.client && (!src.client.images || !(src.bars in src.client.images)))
src.client.images.Add(src.bars)
var/icon/health_bar = GetBarIcon(health, max_health, rgb(255, 0, 0), 2)
var/icon/mana_bar = GetBarIcon(mana, max_mana, rgb(0, 0, 255), 2)
src.bars.overlays.Cut()
src.bars.overlays.Add(image(icon = health_bar, pixel_y = 2))
src.bars.overlays.Add(mana_bar)
src.bar_health = src.health
src.bar_mana = src.mana
GetBarIcon(value, max_value, rgb, height = 4)
var/icon/bar = new /icon('blank.dmi') // remove blank.dmi as needed
bar.Scale(world.icon_size, height)
bar.DrawBox(rgb(224, 224, 224), 0, 0, world.icon_size, height)
bar.DrawRectangle(rgb(0, 0, 0), 0, 0, world.icon_size, height)
var/width = ((world.icon_size - 1) / 100) * ((value * 100) / max_value)
bar.DrawBox(rgb, 1, 1, width, height - 1)
return bar
verb
vAddBars()
set name = "add bars"
src.use_bars = TRUE
src.UpdateBars()
vSetHealth(var/health as num)
set name = "set health"
src.health = health
src.UpdateBars()
vSetMana(var/mana as num)
set name = "set mana"
src.mana = mana
src.UpdateBars()
Expected Results:
Calling new/icon should create a blank icon file in memory.
Actual Results:
No icon file is created. But it does work when you specify an empty icon file, which is strange.
Does the problem occur:
Every time? Or how often?
Every time.
In other games?
Yes.
In other user accounts?
Yes.
On other computers?
Yes.
When does the problem NOT occur?
The problem does not occur when you specify an icon file as input, even if said file is an otherwise empty PNG.
Workarounds:
Create a file called "blank.dmi" that doesn't contain any icon states and use that as input.