Game Development Community

Class Member Fields

by Justin Mette · in Torque Game Engine · 12/28/2001 (6:25 am) · 1 replies

I am working on user interface code at the moment and am having some trouble accessing "class member fields" in script that were set in C++ engine code.

I have a new gui class that creates a child button control, like this:

mNewButton = new GuiButtonCtrl();
AssertFatal(mNewButton, "Failed to create button!");
mNewButton->setField("text", "Hello");
mNewButton->registerObject();
addObject(mNewButton);

The button shows up fine when the application is run. The "Hello" text properly displays. However, when I access the "text" field of the button control from scripts - it is blank. In other words, the following line of script returns "":

echo(theButton.text);

If I use the getText() method of the control from script, everything works fine. The following line of script code properly returns "Hello":

echo(theButton.getText());

If I set the "text" field from script, I can access that field from script as I first described - no problems. It just seems to be a problem when you set the field value from C++ code.

I can use the getText() method to work around my problem - but I thought it strange that I couldn't just use the "text" field directly in this case. I am wondering ultimately if there is a problem deeper down in the field initialization code that prevents this case from happening or if I am doing something incorrectly when setting the field value from C++ code.

Has anyone had to deal with this problem or have a work-around that will allow me to use the "text" field directly from script?

Thanks,
Justin Mette
21-6 Productions

#1
12/28/2001 (9:10 am)
This problem sounds very familiar... I can't remember what the deal is though. This sounds like a problem for Mark.