ID:262404
 
Code:
Color //This is my color object
var
r
g
b
hex
New(var/red,var/green,var/blue)
..()
if(!red&&!green&&!blue) del src //delete it so colorless Color objects don't take up space
if(!red) red=0
if(!blue) blue=0
if(!green) green=0
r=red;b=blue;g=green
hex=rgb(r,g,b)


Problem description:
Notice the last line under New(). That should assign the hex value to the hex variable. But it doesn't for turfs, it's only working for mobs and objs. I tested this using the following verb on one turf, obj, and mob.

verb/Check()
set src in oview(1) //Under mob, this line was removed
if(color.hex) world<<"color for [src] exists"
else world<<"color doesn't"


Prodigal Squirrel

You're deleting turfs, because they're not getting any red, green or blue arguments when New() is called.
I'm pretty sure your first if() wants to check and see if src.r, src.g, src.b are also null before deleting.
In response to DarkView
But they are gettting red, green, and blue. Besides, it would delete the color object, then simply not give the text var any colors or text. It wouldn't delete the turf.

turf
grass
bgcolor=new(11,66,11)
text="<font bgcolor=#116611> </font>"//Defined for mapping purposes


Here's a commented version of the Color object, explaining what I'm trying to accomplish.

Color
var
r
g
b
hex
New(var/red,var/green,var/blue)
..()
if(!red&&!green&&!blue) del src //if a color object is created without any colors, delete it.
else
if(!red) red=0 //If it has no red, but has the others give it red
if(!blue) blue=0
if(!green) green=0
r=red;b=blue;g=green //Assign the objects rgb values to the desired values
hex=rgb(r,g,b) //Create a hex variable for it


For reference, here's what atom is doing for all of this. This could also be the cause.

atom
var
Color/color
Color/bgcolor
char=" "

New()
.=..()
if(color&&bgcolor&&color.hex&&bgcolor.hex) text="<font bgcolor=[bgcolor.hex] color=[color.hex]>[char]"
else if(color&&color.hex) text="<font color=[color.hex]>[char]"
else if(bgcolor&&bgcolor.hex) text="<font bgcolor=[bgcolor.hex]>[char]"


DarkView wrote:
src.r, src.g, src.b are also null before deleting.

I tried this just because you suggested, but it didn't affect anything.

Here are some tests that I've tried:

turf
grass
...
verb/Check_turf()
set src in range(0)
if(src.bgcolor) world<<"bgcolor is alive"
if(src.bgcolor.r)world<<"[src]'s r is alive"
if(src.bgcolor.b)world<<"[src]'s b is alive"
if(src.bgcolor.g)world<<"[src]'s g is alive"
if(src.bgcolor.r)world<<"[src]'s hex is alive"

obj
weapon
Bow
...
verb/Check_object()
set src in range(0)
if(src.bgcolor) world<<"bgcolor is alive"
if(src.bgcolor.r)world<<"[src]'s r is alive"
if(src.bgcolor.b)world<<"[src]'s b is alive"
if(src.bgcolor.g)world<<"[src]'s g is alive"
if(src.bgcolor.r)world<<"[src]'s hex is alive"


Check_turf() only merits "bgcolor is alive". Whereas Check_obj() outputs every one of the messages. I'm baffled. Perhaps it's a bug?

Prodigal Squirrel
In response to Prodigal Squirrel
I don't think this will solve your problem, but let me give you some tips...

Color
var
name = "" // Since we use 'name' for the hex value,
r = 0 // you can plainly use [myColor] rather than [myColor.hex].
g = 0
b = 0
New(var/red = 0, var/green = 0, var/blue = 0)
if(!red && !green && !blue) del src
..()
r = red; g = green; b = blue
name = "\proper [rgb(r, g, b)]" // We want proper.

atom
var
Color/color = null // Defaults.
Color/bgcolor = null
char = " "
New()
.=..()
text="<font bgcolor='[bgcolor]' color='[color]'>[char]"


Sometimes it better to just set a value, then to run so many IF statements.

By the way, your check to see if the "hex" variable is true is checking the "r" var.
In response to Yota
Yota wrote:
By the way, your check to see if the "hex" variable is true is checking the "r" var.

oops! Oh well.

Thanks a lot for the tips!

Prodigal Squirrel
In response to Prodigal Squirrel
Hmm, I was thinking. I noticed how you have the /Color datum delete itself if it's solid black, to save up room for more datums. However, since you'll probably be using two non-black /Color datums per atom, it's still going to be a huge problem. Rather than using datums, just use a hex value returned by rgb(). Also, in text mode, there's a difference between black, and transparent when dealing with the background color. (Transparent, as in taking on the BG color of the underlying atom.)
In response to Yota
Yota wrote:
Hmm, I was thinking. I noticed how you have the /Color datum delete itself if it's solid black, to save up room for more datums. However, since you'll probably be using two non-black /Color datums per atom, it's still going to be a huge problem. Rather than using datums, just use a hex value returned by rgb().

I've been thinking of this. I just thought that having 4 variables so closely related that are used for two different attributes, was reason enough to use a datum, but I guess not. I'll just have to use 8 variables under atom: r, g, b, color, BGr, BGg, BGb, and bgcolor.

Also, in text mode, there's a difference between black, and transparent when dealing with the background color. (Transparent, as in taking on the BG color of the underlying atom.)

I'm not sure why you're telling me that. Is it because I'm deleting solid black datums? If so, then I should take away the default color values of 0, and change the if(!red&&!blue&&!green) to if(isnull(red)&&isnull(green)&&isnull(blue))? Or would it be best to get rid of that if() check entirely since the defaults for each Color datum variables in atom are null?

Prodigal Squirrel