Button interaction
by Craig Lallathin · in Torque Game Engine Advanced · 01/18/2010 (3:48 pm) · 14 replies
I want the player to be able to go up to an object and hit a button (lets use x as example) before an event is triggered. Is there any way to do this? If there is can someone give me an example of how this would be done?
If this is something easy I apologize, any help would be appreciated
Thanks,
Craig
If this is something easy I apologize, any help would be appreciated
Thanks,
Craig
#2
01/18/2010 (5:09 pm)
I would like it to appear when the player approaches it but it still only appears when the player is like 5 steps away from the object.
#3
01/18/2010 (5:15 pm)
Okay... Well, how are you doing it now, and how -exactly- do you want it to behave? If you post script, people here can help more :)
#4
This is an example of a trigger I have just not sure how to make it use the button to trigger it instead. If i can figure out how to use a button to trigger this instead i figure it should be about the same for an animation.
function Ambush_five::onEnterTrigger(%this, %trigger, %obj)
{
if (%obj.getclassname() $= "player" && !%trigger.doneOnce)
{
echo("Player in Trigger");
%trigger.doneOnce = true;
serverPlay3D(Ambush5HUD, %obj.getTransform());
//Do something else here
}
else
{
echo("NOT player in trigger");
}
Parent::onEnterTrigger(%this, %trigger, %obj);
}
01/18/2010 (5:27 pm)
I don't have any script as of yet because I'm not sure how to go about doing this. I know how to create a trigger so that when you run into a certain area a sound or animation automatically plays but I want to set an actual button on the keyboard to trigger an animation.This is an example of a trigger I have just not sure how to make it use the button to trigger it instead. If i can figure out how to use a button to trigger this instead i figure it should be about the same for an animation.
function Ambush_five::onEnterTrigger(%this, %trigger, %obj)
{
if (%obj.getclassname() $= "player" && !%trigger.doneOnce)
{
echo("Player in Trigger");
%trigger.doneOnce = true;
serverPlay3D(Ambush5HUD, %obj.getTransform());
//Do something else here
}
else
{
echo("NOT player in trigger");
}
Parent::onEnterTrigger(%this, %trigger, %obj);
}
#5
Oh, well this wouldn't even need a trigger if you want the player to do this with a button- just do something like this in scripts/client/default.bind.cs:
Now, that lets you execute that anywhere, but you could do this in the trigger (you'd have to remove the bindCmd in the default.bind.cs for this to work properly):
Or, if you want to display a button when the player hits the trigger (because I'm a bit fuzzy on what you mean by using a button to trigger something, and you could have meant using a button instead of a keybind):
And then create a doStuffGui.gui with:
That's a couple of ways to do it, hope it helps :)
01/18/2010 (5:42 pm)
Quote:This is an example of a trigger I have just not sure how to make it use the button to trigger it instead
Oh, well this wouldn't even need a trigger if you want the player to do this with a button- just do something like this in scripts/client/default.bind.cs:
function doStuff()
{
//The stuff you want done goes here...
}
moveMap.bindCmd(keyboard, "x", "", "doStuff();");Now, that lets you execute that anywhere, but you could do this in the trigger (you'd have to remove the bindCmd in the default.bind.cs for this to work properly):
function Ambush_five::onEnterTrigger(%this, %trigger, %obj)
{
moveMap.bindCmd(keyboard, "x", "", "doStuff();");
}
function Ambush_five::onLeaveTrigger(%this, %trigger, %obj)
{
moveMap.unbindCmd("x");
}Or, if you want to display a button when the player hits the trigger (because I'm a bit fuzzy on what you mean by using a button to trigger something, and you could have meant using a button instead of a keybind):
function Ambush_five::onEnterTrigger(%this, %trigger, %obj)
{
Canvas.pushDialog(doStuffGui);
}
function Ambush_five::onLeaveTrigger(%this, %trigger, %obj)
{
Canvas.pushDialog(doStuffGui);
}And then create a doStuffGui.gui with:
new GuiControl(doStuffGui)
{
//GuiControl stuff here...
new GuiButtonCtrl(doStuffBtn)
{
//GuiButtonCtrl stuff here...
command = "doStuffGuiFn();";
};
};
function doStuffGuiFn()
{
//Do your stuff here...
Canvas.popDialog(doStuffGui); //We're done, get rid of the GUI...
}That's a couple of ways to do it, hope it helps :)
#6
Then on the client side, add a function for RemapAction
Of course, the movemap portion could be easily replaced with whatever map you use, the "b" can be replaced with whatever key you want, and the function can also be changed.
The only thing to remember is to add code for the player leaving the trigger that would call the same function, but with a differnt %in value.
This will take the ability to do the command away when the player is not in the trigger.
01/18/2010 (5:48 pm)
If you want just a certain keyboard button to be active only when in the trigger, I would suggest the trigger action being a command to bind the desired button to do the animation.//...code for trigger... commandToClient(%player.client,'RemapAction',true); //...rest of code...
Then on the client side, add a function for RemapAction
function clientCmdRemapAction(%in)
{
if(%in)
moveMap.bind("keyboard","b",PlayMyAnimation);
else
moveMap.unbind("keyboard",PlayMyAnimation);
}Of course, the movemap portion could be easily replaced with whatever map you use, the "b" can be replaced with whatever key you want, and the function can also be changed.
The only thing to remember is to add code for the player leaving the trigger that would call the same function, but with a differnt %in value.
//...code for leaving trigger... commandToClient(%obj.client,'RemapAction',false); //...rest-o-code...
This will take the ability to do the command away when the player is not in the trigger.
#8
01/18/2010 (5:51 pm)
Hmm... the previous post appeared after mine... whoops! :) His method works too. The only thing to worry about would be client/server communications, since the trigger data is on the server side, I believe, and the actionmaps are on the client side. But for singlePlayer games, any way should work :)
#9
01/18/2010 (5:57 pm)
Michael is right about the client/server functions, and his toggle for the bind/unbind is a smoother implementation than I originally wrote.
#10
01/21/2010 (11:12 pm)
sorry ted I just read back over this and saw that you weren't sure if i wanted it to keybind. yes i do. so far i am unsuccessful in getting this to work.
#11
01/22/2010 (5:59 pm)
What are your problems? Any persistent error messages?
#12
moveMap.bind("keyboard","b",PlaySound);
in config.cs.
This......
function doStuff()
{
//The stuff you want done goes here...
%trigger.doneOnce = false;
serverPlay3D(Collins2HUD, %obj.getTransform());
}
datablock SFXProfile(Collins3HUD)
{
fileName = "~/data/sound/collins3HUD";
description = AudioClose3d;
preload = true;
};
moveMap.bindCmd(keyboard, "b", "", "doStuff();");
in default.bind.cs
trying to make it play anywhere i hit b on the keyboard
01/28/2010 (9:54 pm)
maybe I missed something, I put this...... moveMap.bind("keyboard","b",PlaySound);
in config.cs.
This......
function doStuff()
{
//The stuff you want done goes here...
%trigger.doneOnce = false;
serverPlay3D(Collins2HUD, %obj.getTransform());
}
datablock SFXProfile(Collins3HUD)
{
fileName = "~/data/sound/collins3HUD";
description = AudioClose3d;
preload = true;
};
moveMap.bindCmd(keyboard, "b", "", "doStuff();");
in default.bind.cs
trying to make it play anywhere i hit b on the keyboard
#13
01/28/2010 (11:23 pm)
it keeps telling me PlaySound: Unknown command.
#14
01/29/2010 (3:17 pm)
I do not see where you defined "PlaySound". Why did you map doStuff to b in default.bind.cs and PlaySound to b in config.cs? The error might be that, from the default demo, the actionmap is grabbed from config when loaded, and default.bind would not reflect any updated changes to the actionmap.
Torque 3D Owner Ted Southard