How do i link a button to a object?
by Zergcow · in Torque Game Engine · 03/06/2008 (8:59 am) · 2 replies
I wasent sure where to post this, but i have this game where buildings that i place get automaticly hooked into a database and pull numbers to put in a dynamic field. Now i want to make a button that gets placed when the building is placed to update those fields. in my code the "newGuiTextCtrl" does work and shows up correctly. just not the button. sometimes i can get the button to show up but i cant get it where it does what it is supposed to.
An idea i had this morning but cant figure out is when i make a "new RTSbuilding ()" i somehow put the name in the () part. the name pulled from the database i mean. then i could have the button referance that named building?
here is my code (\server\scripts\items\building.cs)
so when i do the "%b.setName( $pi );" where $pi = "ell_a" then that means i would have a "RTSbuilding(ell_a)" right?
the function that the button would use would look like this (\server\scripts\core\db\utils.cs)
An idea i had this morning but cant figure out is when i make a "new RTSbuilding ()" i somehow put the name in the () part. the name pulled from the database i mean. then i could have the button referance that named building?
here is my code (\server\scripts\items\building.cs)
function serverCmdPlaceBuilding(%conn, %transform, %data)
{
//TODO: do some checks to verify that we can place a building here
%b = new RTSBuilding()
{
datablock = %data;
scale = "1 1 1";
//info for datbase stuff below...
pi = "Set in DB";
ell = "Set in DB";
ection = "Set in DB";
mroduction = "Set in DB";
dppm = "Set in DB";
};
%b.setTransform( %transform );
%b.setName( $pi );
%b.client = %conn;
%b.setTeam(%conn.getTeam());
%b.setControllingConnection(%conn);
%conn.buildings.add(%b);
%b.playRootAnimation();
//Attempting to hook the building to database info.
%result = DB::Select( "*", "roduction", "PI ='" @ $pi @ "'", "" );
%result.FirstRow();
%b.pi = %result.Value("PI");
%b.ell = %result.Value("ell");
%b.ection = %result.Value("ection");
%b.mroduction = %result.Value("Mroduction");
%b.dppm = %result.Value("DPPM");
%result.Clear();
// 3D UI setup:
new Gui3DProjectionCtrl(theBuildingProjector);
// add Gui elements like buttons and text.
// this is a button.
new GuiButtonCtrl( refButton );
theBuildingProjector.add( refButton );
// TODO:make it able to update the fields of the object it is attached to?
// this is static text.
new GuiTextCtrl(wellname);
theBuildingProjector.add(wellname);
//add the new GUI to the world.
playGui.add(theBuildingProjector);
// move the control to be at the location where the obj is now:
theBuildingProjector.pointWorld = %b.getPosition();
// attach the control to the obj:
theBuildingProjector.setAttachedTo(%b);
//set textctrl text to name of the obj
wellname.text = (%b.ell);
// giving the refButton a command to hook into the data and refresh the object it is attached to somehow.
refButton.Command = "DB::ZergRefreshInfo(%b.pi);";so when i do the "%b.setName( $pi );" where $pi = "ell_a" then that means i would have a "RTSbuilding(ell_a)" right?
the function that the button would use would look like this (\server\scripts\core\db\utils.cs)
function DB::ZergRefreshInfo(%pi)
{
%string1 = RTSbuilding (%pi)
{
pi = "Set in DB";
ell = "Set in DB";
ection = "Set in DB";
mroduction = "Set in DB";
dppm = "Set in DB";
};
%result = DB::Select( "*", "roduction", "PI ='" @ %pi @ "'", "" );
%result.FirstRow();
%string1.pi = %result.Value("PI");
%string1.ell = %result.Value("ell");
%string1.ection = %result.Value("ection");
%string1.mroduction = %result.Value("Mroduction");
%string1.dppm = %result.Value("DPPM");
%result.Clear();
}About the author
#2
so its obviously
I was thinking o figuring out a way to fetch the ID of the object and then using that to call the database. But i am kinda lost on which way to do this and why my method doesnot work. any help would be awsome.
03/06/2008 (9:06 am)
Here is the error i keep getting...>>> Advanced script error report. Line 51.
>>> Some error context, with ## on sides of error halt:
//-----------------------------------------------------------------------------
// Plugging things into the naming dlg window.
//
//-----------------------------------------------------------------------------
function DB::ZergRefreshInfo(%pi)
{
%string1 = RTSBuilding(%pi)
{
## ## pi = "Set in DB";
ell = "Set in DB";
ection = "Set in DB";
mroduction = "Set in DB";
dppm = "Set in DB";
};
%result = DB::Select( "*", "roduction", "PI ='" @ %pi @ "'", "" );
>>> Error report complete.
***** End of database initialization.
*******************************************************************************so its obviously
%string1 = RTSBuilding(%pi)So i started digging and found stuff like
function GuiRTSTSCtrl::getTypeID(%this, %objID){
switch$(%this.getSelectedObject(%objID).getRTSUnitTypeName())
{
case "bonecracker":
return 0;
case "shocker":
return 1;
case "rifleman":
return 2; }}I was thinking o figuring out a way to fetch the ID of the object and then using that to call the database. But i am kinda lost on which way to do this and why my method doesnot work. any help would be awsome.
Torque Owner Zergcow
Basically i am trying really hard to make all the UI elements like the refresh button create automatically and be linked to that particular building's database info. so that i can do it all in the game without having to switch to GUI Editor to do things.
So, any help would be much apreciated!