Correct name for mouse click?
by Orion the Hunter · in Torque Game Builder · 11/13/2012 (4:58 pm) · 20 replies
Hello again,
I'm trying to make it so that when I click the mouse button, it fires the weapon. currently, the keybind is:
How do I change it from "keyboard X" to the correct name for mouse click? Is there a such thing?
I'm trying to make it so that when I click the mouse button, it fires the weapon. currently, the keybind is:
%template.addBehaviorField( keyAttack, "Attack", KEYBIND, "keyboard X" );
How do I change it from "keyboard X" to the correct name for mouse click? Is there a such thing?
#2
11/14/2012 (5:34 am)
Oh I got it. You were right. Thanks!
#3
11/14/2012 (10:09 am)
Sorry, after trying it out it didn't work. Still not positively responding. It says, "Unknown device, button0." I tried mouse button0 with no success... any more help?
#4
A device is a peripheral like a mouse, keyboard or joystick. An action is like button0, "a", "up", etc (the stuff in the link Kand gave you).
You should check this place out. There are multiple awesome tutorials: torquescripter.com/
11/14/2012 (1:06 pm)
button0 is not a device.A device is a peripheral like a mouse, keyboard or joystick. An action is like button0, "a", "up", etc (the stuff in the link Kand gave you).
You should check this place out. There are multiple awesome tutorials: torquescripter.com/
#5
I'm just guessing that it might be keyboard, instead of mouse.
Otherwise you could implement off of the t2dSceneWindow, but not sure if you want to have that as your functionality or not.
11/14/2012 (3:10 pm)
You might need to check your behavior code to make sure the right "bind" is being applied. The correct syntax should be:moveMap.bind(mouse, button0, functionCall);
I'm just guessing that it might be keyboard, instead of mouse.
Otherwise you could implement off of the t2dSceneWindow, but not sure if you want to have that as your functionality or not.
t2dSceneWindow::onMouseDown(%this, %modifier, %worldPosition, %clicks)
#6
Is the syntax correct? If so, why isn't it working?
11/15/2012 (6:14 am)
Well I didn't make the behavior. It comes with PSK so everything should be valid... I have the current applied as a function:if ( !isObject( ControllerBehavior ) )
{
%template = new BehaviorTemplate( ControllerBehavior );
%template.friendlyName = "Player Controller";
%template.behaviorType = "Actor";
%template.description = "Player Controller";
%template.addBehaviorField( keyLeft, "Move Left", KEYBIND, "keyboard a" );
%template.addBehaviorField( keyRight, "Move Right", KEYBIND, "keyboard d" );
%template.addBehaviorField( keyUp, "Move Up", KEYBIND, "keyboard w" );
%template.addBehaviorField( keyDown, "Move Down", KEYBIND, "keyboard s" );
%template.addBehaviorField( keyJump, "Jump", KEYBIND, "keyboard space" );
//THE FUNCTION THAT WONT WORK vvv
%template.addBehaviorField( keyAttack, "Attack", KEYBIND, "mouse button0" );
//THE FUNCTION THAT WONT WORK ^^^
%template.addBehaviorField( keyReload, "Reload", KEYBIND, "keyboard R" );
}Is the syntax correct? If so, why isn't it working?
#7
Did some Google searching and documentation perusal and didn't find any examples of an addBehaviorField except for a keyboard key.
You should consider your options:
1. directly invoke bind() function instead of using behavior
2. do what Doc suggested
3. try to figure out how to get KEYBIND to work with a mouse button
Those are roughly in order from easiest to hardest. Scripting is all about giving an idea concreteness as fast as possible, utilizing workarounds, and being creative in a way different than programmers.
11/15/2012 (7:12 am)
For me it sticks out that every single other addBehaviorField that *works* binds a keyboard key.Did some Google searching and documentation perusal and didn't find any examples of an addBehaviorField except for a keyboard key.
You should consider your options:
1. directly invoke bind() function instead of using behavior
2. do what Doc suggested
3. try to figure out how to get KEYBIND to work with a mouse button
Those are roughly in order from easiest to hardest. Scripting is all about giving an idea concreteness as fast as possible, utilizing workarounds, and being creative in a way different than programmers.
#8
11/15/2012 (7:30 am)
Maybe try throwing this somewhere in main.cs or game.cs if it doesn't already exist:enableMouse();
#9
First off, I doubt this is what you want for your game if it is a platformer, but it "could" be useful if you want to interact with an environment object via a behavior.
In your Behaviors directory there should be an input.cs or something similar that actually has the bindObj commands.
To get mouse action allowed, include this line on your Behavior::onBehaviorAdd(%this) function:
From here you can add Mouse interaction for "THAT OBJECT!!"
So for instance if you were to do this:
Any time you clicked the object, the function would perform, and in this case echo that you clicked it.
If you want to have your mouse always shoot and nothing else, it would be easier to do what I suggested earlier with t2dSceneWindow::onMouseDown
At first I wondered why just a joystick was allowed, but the joystick has axis control and buttons so it allows flexibility. The mouse however has a different control aspect.
11/15/2012 (8:08 am)
I figured out the problem. It appears the Behavior Input only receives keyboard/joystick for movement purposes. In order to have the mouse reaction, there are a few things to do.First off, I doubt this is what you want for your game if it is a platformer, but it "could" be useful if you want to interact with an environment object via a behavior.
In your Behaviors directory there should be an input.cs or something similar that actually has the bindObj commands.
To get mouse action allowed, include this line on your Behavior::onBehaviorAdd(%this) function:
%this.owner.setUseMouseEvents(true);
From here you can add Mouse interaction for "THAT OBJECT!!"
So for instance if you were to do this:
function ControllerBehavior::onMouseDown(%this, %modifier, %worldPos)
{
echo("I clicked my object!!");
}Any time you clicked the object, the function would perform, and in this case echo that you clicked it.
If you want to have your mouse always shoot and nothing else, it would be easier to do what I suggested earlier with t2dSceneWindow::onMouseDown
At first I wondered why just a joystick was allowed, but the joystick has axis control and buttons so it allows flexibility. The mouse however has a different control aspect.
#10
~JR
11/15/2012 (8:27 am)
AHA! I fixed it. The problem turned out to be with main screen gui, not the behavior at all. The thing was the mouse event window was not accessible. So I replaced my main screen gui with a previous version which I knew worked. Now the mouse is not blocked from being used. Thanks, guys!~JR
#11
11/17/2012 (8:45 am)
It'd be super sweet if you'd post the line(s) in context which 1.) caused the problem, then 2.) that fixed it.
#12
11/21/2012 (6:54 am)
Well it turned out not to be a problem with your bind commands at all. It was just a matter of being able to click. Do you want me to post the gui file?
#13
11/21/2012 (8:47 am)
I would dig that. I would like to know exactly what to do if I run into similar problems.
#14
11/21/2012 (8:55 am)
Part 1://--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(mainScreenGui) {
canSaveDynamicFields = "0";
isContainer = "1";
Profile = "GuiBlackContentProfile";
HorizSizing = "width";
VertSizing = "height";
Position = "0 0";
Extent = "1024 768";
MinExtent = "8 8";
canSave = "1";
Visible = "1";
hovertime = "1000";
new t2dSceneWindow(sceneWindow2D) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiText24Profile";
HorizSizing = "width";
VertSizing = "height";
Position = "0 0";
Extent = "1024 768";
MinExtent = "8 8";
canSave = "1";
Visible = "1";
tooltipprofile = "GuiDefaultProfile";
hovertime = "1000";
lockMouse = "0";
useWindowMouseEvents = "0";
useObjectMouseEvents = "0";
};
new GuiBitmapCtrl() {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "relative";
VertSizing = "bottom";
Position = "0 0";
Extent = "1024 96";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
bitmap = "~/data/images/GUI/scorebox.png";
wrap = "0";
};
new GuiBitmapCtrl(pepperBox) {
canSaveDynamicFields = "0";
isContainer = "1";
Profile = "GuiDefaultProfile";
HorizSizing = "left";
VertSizing = "bottom";
Position = "663 22";
Extent = "343 51";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
tooltipprofile = "GuiDefaultProfile";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_chilibox.png";
wrap = "0";
#15
11/21/2012 (8:56 am)
(Part 2)new GuiBitmapCtrl(ghostPepper0) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "17 9";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
tooltipprofile = "GuiDefaultProfile";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_pepperGhost.png";
wrap = "0";
};
new GuiBitmapCtrl(ghostPepper1) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "48 9";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_pepperGhost.png";
wrap = "0";
};
new GuiBitmapCtrl(ghostPepper2) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "79 9";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_pepperGhost.png";
wrap = "0";
};
new GuiBitmapCtrl(ghostPepper3) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "110 9";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_pepperGhost.png";
wrap = "0";
};
#16
11/21/2012 (8:57 am)
(part 3)new GuiBitmapCtrl(ghostPepper4) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "141 9";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_pepperGhost.png";
wrap = "0";
};
new GuiBitmapCtrl(ghostPepper5) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "172 9";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_pepperGhost.png";
wrap = "0";
};
new GuiBitmapCtrl(ghostPepper6) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "203 9";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_pepperGhost.png";
wrap = "0";
};
new GuiBitmapCtrl(ghostPepper7) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "234 9";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_pepperGhost.png";
wrap = "0";
};
#17
11/21/2012 (8:59 am)
(part 4)new GuiBitmapCtrl(ghostPepper8) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "265 9";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_pepperGhost.png";
wrap = "0";
};
new GuiBitmapCtrl(ghostPepper9) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "296 9";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_pepperGhost.png";
wrap = "0";
};
new GuiBitmapCtrl(pepper0) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "17 12";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "0";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_peppers.png";
wrap = "0";
};
new GuiBitmapCtrl(pepper1) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "48 12";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "0";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_peppers.png";
wrap = "0";
};
new GuiBitmapCtrl(pepper2) {
#18
11/21/2012 (9:02 am)
(Part 7) <--- ignore until part 6. I posted this too early.};
new GuiTextCtrl(SecondaryAmmoGui) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "left";
VertSizing = "top";
Position = "864 728";
Extent = "150 30";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
maxLength = "1024";
};
new GuiMouseEventCtrl(MouseInputCtrl) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiTransparentProfile";
HorizSizing = "width";
VertSizing = "height";
Position = "0 0";
Extent = "1024 768";
MinExtent = "8 8";
canSave = "1";
Visible = "1";
hovertime = "1000";
lockMouse = "1";
};
new GuiBitmapButtonCtrl() {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "-149 160";
Extent = "140 30";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
Command = "pauseModeActive();";
Accelerator = "escape";
hovertime = "1000";
groupNum = "-1";
buttonType = "PushButton";
UseMouseEvents = "0";
};
};
//--- OBJECT WRITE END ---
#19
11/21/2012 (9:05 am)
(Part 5)canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "79 12";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "0";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_peppers.png";
wrap = "0";
};
new GuiBitmapCtrl(pepper3) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "110 12";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "0";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_peppers.png";
wrap = "0";
};
new GuiBitmapCtrl(pepper4) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "141 12";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "0";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_peppers.png";
wrap = "0";
};
new GuiBitmapCtrl(pepper5) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "172 12";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "0";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_peppers.png";
wrap = "0";
};
new GuiBitmapCtrl(pepper6) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "203 12";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "0";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_peppers.png";
wrap = "0";
};
new GuiBitmapCtrl(pepper7) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "234 12";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "0";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_peppers.png";
wrap = "0";
};
new GuiBitmapCtrl(pepper8) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "265 12";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "0";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_peppers.png";
wrap = "0";
};
new GuiBitmapCtrl(pepper9) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "296 12";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "0";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_peppers.png";
wrap = "0";
};
};
maxLength = "1024";
#20
Whoo! That was a lot of code. I hope it helps. Sorry if it's a little more than you asked for. So basically, make sure that the mouse input gui is over everything. Even if you make a new gui that pops over the mainScreen, if it's involved with the t2dscene, it must have a mouseInput.
~JackRabbit
11/21/2012 (9:09 am)
(Part 6)new GuiBitmapCtrl() {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "32 32";
Extent = "64 64";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
tooltipprofile = "GuiDefaultProfile";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_extralives.png";
wrap = "0";
};
new GuiBitmapCtrl() {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "96 48";
Extent = "32 32";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
tooltipprofile = "GuiDefaultProfile";
hovertime = "1000";
bitmap = "~/data/images/GUI/HUD_x.png";
wrap = "0";
};
new GuiTextCtrl(ExtraLivesCounter) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "137 29";
Extent = "110 72";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
tooltipprofile = "GuiDefaultProfile";
hovertime = "1000";
text = "00";
maxLength = "1024";
};
new GuiBitmapCtrl(CrossHairGui) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "CrossHairProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "0 0";
Extent = "15 15";
MinExtent = "8 2";
canSave = "1";
Visible = "0";
hovertime = "1000";
bitmap = "~/data/images/GUI/crosshair.png";
wrap = "0";
};
new GuiTextCtrl(PrimaryAmmoGui) {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "left";
VertSizing = "top";
Position = "864 688";
Extent = "150 30";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
maxLength = "1024";Whoo! That was a lot of code. I hope it helps. Sorry if it's a little more than you asked for. So basically, make sure that the mouse input gui is over everything. Even if you make a new gui that pops over the mainScreen, if it's involved with the t2dscene, it must have a mouseInput.
~JackRabbit
Torque Owner Alpha-Kand
Hunter's Meadow