Game Development Community

Question regarding console functions...

by Daniel Hopkins · in Torque 3D Professional · 09/15/2009 (12:54 pm) · 5 replies

Hey,

I was recently delving into the T3D source in the attempt to modify the behavior of a GuiFrameSetCtrl. What I wanted to do was add an "onReSize" callback called when the user resizes one of the frames. So, I added an "onReSize" function to the control's class which looks like this:

void GuiFrameSetCtrl::onReSize()
{	
   if(isMethod("onReSize"))
	Con::executef(this, "onReSize");
   else
	Con::errorf(ConsoleLogEntry::General, "No method onReSize!!");
}

I then edited "guiEditor.ed.gui" by naming the GuiFrameSetCtrl "TestFrameSetCtrl" and added this function to "guiEditor.ed.cs":

function TestFrameSetCtrl::onReSize(%this)
{
   echo("Resizing TestFrameSetCtrl...");
}

However, upon starting the GUI editor, resizing the panel, and checking the console, I receive a bunch of "No method onReSize!!" messages. So basically this means the source function is being called, but it can't find the "onReSize" callback function declared in script. Any ideas as to why this isn't working?

Thanks!

Daniel

#1
09/15/2009 (1:22 pm)
possibly there are other GuiFrameSetCtrls which don't have onresize() implemented in script ?

for debugging purposes, i would suggest putting a bit more info in the error print, such as the object's simID and name, if it has one.

for practical purposes however, i would suggest getting rid of the isMethod() check and just calling executef() in every case. if the method doesn't exist, the execeutef() will just silently fail, which is probably what you want. (otherwise you're requiring every GuiFrameSetCtrl to implement onresize(), which seems odd).

also, if it were me, i'd consider moving the callback further up the class heirarchy, for example into GuiControl itself.
#2
09/15/2009 (1:42 pm)
@Orion: Thanks for the response!

In what way would other GuiFrameSetCtrls not implementing the onReSize() function affect it?

Ok, I'll have to try that.

As far as the isMethod() check goes, I originally left it out. However, when I wasn't getting the console message called from the script callback, I added it in for debugging purposes.

It was my impression the isMethod() function only checks to see if the current instance implements the function. For example, it is used in the GuiButtonBaseCtrl to check to see if the "onRightClick" callback is available. Is that correct?

I'll try that, too.

Thanks again for your feedback!
#3
09/15/2009 (2:38 pm)
> In what way would other GuiFrameSetCtrls not implementing the onReSize() function affect it?

the method simply wouldn't be called.

eg, the following two snippets are functionally identical:
if(isMethod("foo"))
   {
      Con::executef(this, "foo");
   }
Con::executef(this, "foo");

> It was my impression the isMethod() function only checks to see if the current instance implements the function.

yep.


> For example, it is used in the GuiButtonBaseCtrl to check to see if the "onRightClick" callback is available. Is that correct?

.. so it is. personally, i would rewrite that code to eliminate the call to isMethod().

basically, executef() itself checks to see if the method exists,
so the only reason to check for it yourself would be if it's in fact an error for the callback not to be implemented,
or if you want to take some other special behaviour based on the existence or not of the callback.
#4
09/15/2009 (2:40 pm)
@Orion: Thanks for the info.

Okay...I feel really dumb. It was working only I was naming the wrong control. The thing is, I'm re-working the GUI editor and as you can't edit the editor with the editor, I'm having to look through it's .gui script to adjust the controls. It has two GUiFrameSetCtrls, and I was naming the wrong one. So, I named the right one and everything is working.

Thanks.
#5
09/15/2009 (2:44 pm)
sweet, glad you got it sorted!