ID:140966
 
Code:
obj
F_damage_num
layer = 10000
var
F_damageValue
proc/F_damage(atom/Target, value, color)
color=colour2html(color)
//var/icon/I = new('F_damageFade.dmi')
//I.Blend(color, ICON_MULTIPLY)
var/list/Numbers = new()
var/string = num2text(value)
var/counter = 0
var/strLength = length(string)
while(string)
var/obj/F_damage_num/O = new(null)
O.pixel_x = counter*(-7) + Target.pixel_x + round(strLength*7/2)+7
O.pixel_y = Target.pixel_y + 25
O.F_damageValue = copytext(string, length(string))
//O.icon = I
Numbers += O
string = copytext(string, 1, length(string))
counter++
for(var/obj/F_damage_num/O in Numbers)
O.loc = Target:loc
flick(O.F_damageValue, O)
spawn(10)
del O


Problem description:
This makes the game lag like hell, the three lines commented out above fix the lag though, so I was wondering if there way to cache the icon for next time, so the first time it calls the proc, it creates the icon for that color, and then after, it just uses it, but it seems it makes it each time every time which is why it lags.

If I make it choose icon based on color then it works fine if I make an icon file for that of each color, but I don't want to do that.
Why the hell are you using :? Irrelevant, but still, why?
In response to Vic Rattlehead
That was part of F_damage...Anyways, it was removed a while ago, but I copied that from a different code file by accident, however, the one used in the game im working on looks about the same.
I anticipate the easiest way to do it would to use an associative list to store the cache the colour and modified icon. Simply check if your colour has already been generated: if it has, then use that icon. Otherwise, generate and store it using the code you commented out.
In response to Superbike32
Actually, this is the one used by mine at the moment.

proc/F_damage(atom/Target, value, color)
color=colour2html(color)
var/icon/I = new('F_damageFade.dmi')
I.Blend(color, ICON_MULTIPLY)
var/list/Numbers = new()
var/string = num2text(value)
var/counter = 0
var/strLength = length(string)
while(string)
var/obj/F_damage_num/O = new(null)
O.pixel_x = counter*(-7) + round(strLength*7/2)+7
O.pixel_y = 25
O.F_damageValue = copytext(string, length(string))
O.icon = I
Numbers += O
string = copytext(string, 1, length(string))
counter++
for(var/obj/F_damage_num/O in Numbers)
O.loc = Target.loc
flick(O.F_damageValue, O)
spawn(10)
del O