Game Development Community

This should be so simple...

by Dreamer · in Torque Game Engine · 05/08/2005 (1:53 am) · 18 replies

Hello all I am trying to add a console method to the GuiSliderCtrl, that will allow me to dynamically update either it's maxValue or it's range, I can't seem to get either to compile... Can some please help me?

Here are the changes I made...

GuiSliderCtril.h
void setMaxRange(const char *range);

GuiSliderCtrl.cc
ConsoleMethod( GuiSliderCtrl, setMaxRange, void, 3, 3, "Sets the max value of the slider.")//Dreamer
{
   object->setMaxRange(argv[2]);
}


//----------------------------------------------------------------------------

void GuiSliderCtrl::setMaxRange(const char *range){
	F32 thisRange = dAtof(range);
	mRange.setMax(thisRange);
}


And as always thanks in advance.

#1
05/08/2005 (1:54 am)
Whats errors does it spit back ?
#2
05/08/2005 (1:55 am)
Oh yeah sorry...
Quote:
bash-2.05b$ make
--> Compiling gui/guiSliderCtrl.cc
gui/guiSliderCtrl.cc: In member function 'void GuiSliderCtrl::setMaxRange(const
char*)':
gui/guiSliderCtrl.cc:61: error: invalid type argument of 'unary *'
make[1]: *** [out.GCC3.DEBUG/gui/guiSliderCtrl.obj] Error 1
make: *** [default] Error 2
#3
05/08/2005 (2:10 am)
Well.. I see one thing that looks wrong: mRange is a Point2F. I can't find any setMax function for a Point2F that takes a single float as an argument. Point2F::setMax takes a Point2F for an argument.
#4
05/08/2005 (2:11 am)
Ok thats fine, but how would I pass it a Point2F in from the console?

Better yet, maybe a simpler question would be how do I convert from const char* to Point2F?
#5
05/08/2005 (2:15 am)
Um... Wait. Are you sure you even need to create this function? Because mRange is already exposed to script here:

void GuiSliderCtrl::initPersistFields()
{
   Parent::initPersistFields();

   addGroup( "Slider" );
   [b]addField("range", TypePoint2F,   Offset(mRange, GuiSliderCtrl));[/b]
   addField("ticks", TypeS32,       Offset(mTicks, GuiSliderCtrl));
   addField("value", TypeF32,       Offset(mValue, GuiSliderCtrl));
   endGroup( "Slider" );
}

That's not a datablock, so you should be able to update the range simply by saying:

MySlider.range = "x y";

Yes no?
#6
05/08/2005 (2:16 am)
Oh crap I never noticed that lemme give it a shot really quick and see what if it works.
#7
05/08/2005 (2:20 am)
Quote:Ok thats fine, but how would I pass it a Point2F in from the console?

I think this should work:

ConsoleMethod( GuiSliderCtrl, setMaxRange, void, 4, 4, "Sets the max value of the sli
der.")//Dreamer
{
   object->setMaxRange( Point2F( dAtof(argv[2]), dAtof(argv[3] ) );
}


//----------------------------------------------------------------------------

void GuiSliderCtrl::setMaxRange(Point2F newRange){
   mRange.setMax(newRange);
}

And don't forget to change the header file to match.
#8
05/08/2005 (2:32 am)
void GuiSliderCtrl::setMaxRange(const char *range)
{   
	F32 thisRange = dAtof(range);   
	mRange.set(mRange.x, thisRange);
}
#9
05/08/2005 (2:34 am)
@Scott Nope that didn't work :(

Ok I see lotsa folks posted in the time it took me to test and type, in this case I was speaking ofr changing MySlider.range = "1.0 100.0";
#10
05/08/2005 (2:35 am)
object->setMaxRange( Point2F( dAtof(argv[2]), dAtof(argv[3] ) );

should be

object->setMaxRange( Point2F( dAtof(argv[2]), dAtof(argv[3] ) ) );

but this will just require you pass two parameters and it will set the whole range... (the code I posted above works)
#11
05/08/2005 (2:36 am)
Heres the entire thing
ConsoleMethod( GuiSliderCtrl, setMaxRange, void, 3, 3, "Sets the max value of the slider.")//Dreamer
{
		object->setMaxRange(argv[2]);

}
//----------------------------------------------------------------------------void 
void GuiSliderCtrl::setMaxRange(const char *range)
{   
	F32 thisRange = dAtof(range);   
	mRange.set(mRange.x, thisRange);
}
#12
05/08/2005 (2:43 am)
Note this works but doesn't update it so the next time you move the slider it will update...t o force it to update after you set it add

updateThumb(mValue);

like this

void GuiSliderCtrl::setMaxRange(const char *range)
{   
	F32 thisRange = dAtof(range);   
	mRange.set(mRange.x, thisRange);
	updateThumb(mValue);
}
#13
05/08/2005 (2:50 am)
Or how about simply:

void GuiSliderCtrl::setMaxRange(const char *range)
{
   mRange.x = dAtof(range);
   updateThumb(mValue);
}

edit: added updateThumb line

Quote:Nope that didn't work :(

I just tested it myself.. Seemed to work alright for me. Where is it failing in your test?
#14
05/08/2005 (2:59 am)
Of course, using the range field doesn't call the updateThumb function that Matthew mentioned. So the changes won't become apparent until you drag the slider. Might be worth adding a console function after all.
#15
05/08/2005 (3:06 am)
Bad:

void GuiSliderCtrl::setMaxRange(Point2F newRange){
   mRange.setMax(newRange);
}

This would not be a good idea actually, if you want to be able to set the range to any new value. Since Point2F::setMax doesn't set the x component, which is what guiSlider uses x for, but rather sets x and y to the incoming values only if they're greater than the current values. So you could only increase the slider's range with this function. :-o

Just thought that worth mentioning. I wasn't thinking about the logic of the function when I suggested that originally.
#16
05/08/2005 (9:58 pm)
@Scott, sorry for the confusion... When I said "Nope that didn't work", I was speaking only of setting the range values in script by MySlider.range="0 10"; or whatever.
#17
05/08/2005 (10:48 pm)
@Scott, umm hey yeah your solution seems to work good, with one minor drawback... It's not setting the max value... It's setting the min value :)
#18
05/08/2005 (11:22 pm)
MySlider.range = "min max" does work. The only drawback to that method is that the slider position doesn't reflect the change until the next time it's dragged. If that is an issue, see Matthew Langley's posts.