can anyone help on How to change script objects from c++ code?
by David Stoesz · in Torque 3D Professional · 08/13/2009 (12:51 pm) · 5 replies
Hello, I have this code in my playgui.gui file
new GuiCrossHairHud(Reticle) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "center";
VertSizing = "center";
position = "496 368";
Extent = "32 32";
MinExtent = "8 8";
canSave = "1";
Visible = "1";
tooltipprofile = "GuiToolTipProfile";
hovertime = "1000";
bitmap = "art/gui/SelectionHud/blank.png";
wrap = "0";
damageFillColor = "0 1 0 1";
damageFrameColor = "1 0.6 0 1";
damageRect = "50 4";
damageOffset = "0 10";
};
I need to change the bitmap from c++ code in the game.
Or alternatively if someone can tell me how to create the gui bitmap all in the c++ code, that would work too.
Just to describe what i am doing: I have code that determines what I am pointing at in order to make some changes on the Hud. I also want to change this bitmap to a speach bubble for NPCs I can talk to and to a hand for objects I can interact with. The code works for determining what I am looking at, but I have not figured out how to change this gui bitmap.
Any help would be appreciated.
new GuiCrossHairHud(Reticle) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "center";
VertSizing = "center";
position = "496 368";
Extent = "32 32";
MinExtent = "8 8";
canSave = "1";
Visible = "1";
tooltipprofile = "GuiToolTipProfile";
hovertime = "1000";
bitmap = "art/gui/SelectionHud/blank.png";
wrap = "0";
damageFillColor = "0 1 0 1";
damageFrameColor = "1 0.6 0 1";
damageRect = "50 4";
damageOffset = "0 10";
};
I need to change the bitmap from c++ code in the game.
Or alternatively if someone can tell me how to create the gui bitmap all in the c++ code, that would work too.
Just to describe what i am doing: I have code that determines what I am pointing at in order to make some changes on the Hud. I also want to change this bitmap to a speach bubble for NPCs I can talk to and to a hand for objects I can interact with. The code works for determining what I am looking at, but I have not figured out how to change this gui bitmap.
Any help would be appreciated.
About the author
#2
08/13/2009 (2:11 pm)
Hey Ryan, Thanks! I knew there was an easy way to do this, but couldn't find a reference to it since most examples I found were entirely in script or c++.
#3
eval("Reticle.bitmap = $HudBmp::" @ %type @ ";");
But that just looks nasty!
08/13/2009 (2:15 pm)
No problem, David. Doesn't look like you can assign global variables like I showed earlier, so I changed it to a switch statement like above. You could replace the entire switch statement with:eval("Reticle.bitmap = $HudBmp::" @ %type @ ";");
But that just looks nasty!
#4
Or, you could set the bitmap like this as well:
There are many choices. The last one is probably the fastest though. I haven't verified the code, but I hope it works fine.
08/15/2009 (8:45 am)
Another possibility is to change the field through setField:GuiCrossHairHud * reticle = dynamic_cast<GuiCrossHairHud*>(Sim::findObject("Reticle"));
if (reticle)
reticle->setField("bitmap", "art/gui/SelectionHud/notblank.png");Or, you could set the bitmap like this as well:
GuiCrossHairHud * reticle = dynamic_cast<GuiCrossHairHud*>(Sim::findObject("Reticle"));
if (reticle) {
const char *bmpFileName = "art/gui/SelectionHud/notblank.png";
reticle->setBitmap(bmpFileName);
}There are many choices. The last one is probably the fastest though. I haven't verified the code, but I hope it works fine.
#5
I just wanted to confirm that your code worked great, exactly what I needed. Thank you very much.
08/20/2009 (12:40 am)
Konrad, I just wanted to confirm that your code worked great, exactly what I needed. Thank you very much.
Torque Owner Ryan Mounts
CornerstoneViz
In your C++ code, after you have determined what you are looking at, call a console function to change the bitmap for you.
// varType is a char* that describes what you are pointing at. // In this example, varType is "NCP", "Object", or "Blank" if(Con::isFunction("changeHudBmp") Con::executef("changeHudBmp", varType);Then somewhere in script define the "changeHudBmp" function.
$HudBmp::NCP = "art/gui/SelectionHud/NCP.png"; $HudBmp::Object = "art/gui/SelectionHud/Object.png"; $HudBmp::Blank = "art/gui/SelectionHud/blank.png"; function changeHudBmp(%type) { switch$(%type) { case "NCP": Reticle.bitmap = $HudBmp::NCP; case "Object": Reticle.bitmap = $HudBmp::Object; case "Blank": Reticle.bitmap = $HudBmp::Blank; default: Reticle.bitmap = $HudBmp::Blank; } }