PDA

View Full Version : Question about class member colors


Scott Ayers
06-25-2010, 09:38 PM
Hey guys,

This is probably going to sound like a strange question. But I was practicing making classes and custom methods(functions). And I ran into something strange.
You know how the C4D script manager turns certain things a gray color?
I thought that happened whenever you created a class and some members for it. And then used them in the main section of the script. But I'm running into situations where it doesn't happen.

Here's an example: class MyClass
{
public:
var a,b,obj,value;
Add(a,b);
brightness(obj,value);
}

MyClass::Add(v1,v2) // A method to add two variables
{
return v1 + v2;
}

MyClass::brightness(obj,value)// A method to set the brightness value of a light
{
obj#LIGHT_BRIGHTNESS = value;// Sets the light's intensity slider to "value"
value = 0;
return value;
}

main(doc,op)
{
var cls = new(MyClass);
cls->obj = doc->FindObject("Light");//MyClass member obj
cls->value = .5;//MyClass member value-->Sets the light's brightness amount
cls->brightness(cls->obj,cls->value);// executes the brightness method with the member values

cls->a = 4;//MyClass member a
cls->b = 5;//MyClass member b
var result = cls->Add(cls->a, cls->b);//executes the Add method with the member values
println(result);
}

Everything works fine. And the members for the Add method turn gray as I expected.
But the members for my brightness method don't.
So I was just curious about that gray color behavior. And why it happens on some things, but not others?


-ScottA

Cairyn
06-26-2010, 09:11 AM
You know how the C4D script manager turns certain things a gray color?
I thought that happened whenever you created a class and some members for it. And then used them in the main section of the script. But I'm running into situations where it doesn't happen.

Everything works fine. And the members for the Add method turn gray as I expected.
But the members for my brightness method don't.
So I was just curious about that gray color behavior. And why it happens on some things, but not others?


Very simple. The idea that the gray color denotes a syntactical "member of a class" is a misconception.

The interpretation of the gray color is: There is an internal COFFEE class (not your own!) that has a member or method with this name. C4D has a list of all the members of all the classes internally, and when it finds a member access construct x->y, it looks up y in that table. If found, color gray.

It does not look at the class type of x! The colorization does not confirm that y is indeed a member of x; COFFEE never checks that. You may still get a runtime error.

Your own members are not included in that list; it only takes care of the internal COFFEE classes. So why are a and b, in your example, colored? Because a, b, c, and d are members of Polygon! Going through single letters: n and p are members of VolumeData; v and t are also colored but I'm too lazy to find them in the doc now ;-)

Scott Ayers
06-26-2010, 02:54 PM
Thanks Robert.

At first I did think that the gray color was only for built-in members like you said.
But then when some of them were popping up in my own members. I got kind of excited and thought perhaps they were responding to my own classes. Which would be kind of cool because that might be useful as a visual learning tool for people new to making classes.

I can see now that they're just for built in class members.:sad:

-ScottA

CGTalk Moderation
06-26-2010, 02:54 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.