Game Development Community

Binds

by Juha Eerola · in Torque Game Engine · 08/15/2006 (4:50 am) · 4 replies

I haven't coded with torque for long time so I need a little bit help here.

The little feature I'd like to have is message-binds.
For those that are familiar with CS or quakes, it goes like this:
/bind "say Hello world!"

Type that to console and next time you press whatever key you bound it to, your player says "Hello world!".
Of course typing that to console would be boring so I thought I'll make a little GUI for that.
But that comes later. Now I need to know how should I start making the feature and that's where you, torque programmers, come in :)

Thanks in advance!

- Juha Eerola

#1
08/15/2006 (9:57 am)
Hi Juha,

I can get you started but it will be up to you to season this to your liking.

The main problem I can foresee is users trying to bind a message to a key that is already being used. In the following example, I only allow users the ability to bind messages to keys 1 - 5.

All this code will do is create a simple GUI which allows users to enter in a message and assign that message to keys 1- 5. When the key is pressed the message is printed in the mainChatHud window. Press M to bring up the GUI.

This is very basic and most likely you'll need to expand and improve on it. Really this is just an example I quickly wrote to illustrate some key commands that you may need in your own implementation.

Open starter.fps\client\init.cs

- Add this line in with the rest of them:
exec("./ui/messageBind.gui");

Create a new GUI file named messageBind.gui

- Place this newly created file in your starter.fps\client\ui directory.

- Within this file add this:
//--- OBJECT WRITE BEGIN ---
new GuiControl(messageBind) {
   Profile = "GuiDefaultProfile";
   HorizSizing = "right";
   VertSizing = "bottom";
   position = "0 0";
   Extent = "1024 768";
   MinExtent = "8 2";
   Visible = "1";

   new GuiWindowCtrl(messageBindWindow) {
      Profile = "GuiWindowProfile";
      HorizSizing = "center";
      VertSizing = "center";
      position = "462 284";
      Extent = "150 200";
      MinExtent = "8 2";
      Visible = "1";
      text = "Message Bind";
      maxLength = "255";
      resizeWidth = "0";
      resizeHeight = "0";
      canMove = "1";
      canClose = "1";
      canMinimize = "0";
      canMaximize = "0";
      minSize = "50 50";
      closeCommand = "Canvas.popDialog(messageBind);";

      new GuiTextCtrl(enterMessageText) {
         Profile = "GuiTextProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "4 24";
         Extent = "133 18";
         MinExtent = "8 2";
         Visible = "1";
         text = "Enter your message below:";
         maxLength = "255";
      };
      new GuiTextEditCtrl(messageEntered) {
         Profile = "GuiTextEditProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "4 44";
         Extent = "133 18";
         MinExtent = "8 2";
         Visible = "1";
         maxLength = "255";
         historySize = "0";
         password = "0";
         tabComplete = "0";
         sinkAllKeyEvents = "0";
         password = "0";
         passwordMask = "*";
      };
      new GuiTextCtrl(bindKeyText) {
         Profile = "GuiTextProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "4 64";
         Extent = "106 18";
         MinExtent = "8 2";
         Visible = "1";
         text = "Bind this message to?";
         maxLength = "255";
      };
      new GuiPopUpMenuCtrl(bindPopUp) {
         Profile = "GuiPopUpMenuProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "4 84";
         Extent = "64 18";
         MinExtent = "8 2";
         Visible = "1";
         maxLength = "255";
         maxPopupHeight = "200";
      };
   };
};
//--- OBJECT WRITE END ---

function messageBind::onWake(%this)
{
   %this.updateBindList();
}

function showMessageBindGui(%val)
{
   if (%val)
      messageBind.toggle(%val);
}

function messageBind::toggle(%this,%val)
{
   if (%this.isAwake())
   {
      Canvas.popDialog(%this);
   }

   else
   {
      Canvas.pushDialog(%this);
   }
}

function  messageBind::updateBindList()
{
   bindPopUp.clear();
   bindPopUp.add("1", 0);
   bindPopUp.add("2", 1);
   bindPopUp.add("3", 2);
   bindPopUp.add("4", 3);
   bindPopUp.add("5", 4);
   bindPopUp.setSelected(0);
}

function bindPopUp::onSelect( %this, %id, %text )
{
   if (%text $= "")
      return;

   $messageBinding = %text;
   moveMap.bind(keyboard, $messageBinding, messageBind);
}

function messageBind(%val,%message)
{
   %message = messageEntered.getText();

   if (%val > 0 )
      commandtoserver('messageBind', %message);
}

function serverCmdMessageBind(%this,%message)
{
   messageAll ("",%message);
}

moveMap.bind(keyboard, m, showMessageBindGui);

Now, delete your starter.fps\client\config.cs file and start up your game. Hit M to test it out. If you followed my instructions correctly, it should look something like this:

i5.photobucket.com/albums/y189/fjs/screenshot_017-00001.jpg
i5.photobucket.com/albums/y189/fjs/screenshot_017-00002.jpg
#2
08/15/2006 (10:09 am)
Whoa! thanks :)

Quote:
The main problem I can foresee is users trying to bind a message to a key that is already being used
How hard it would be to make binds to work like ALT + ?
Then there would be _alot_ of buttons to bind :)
#3
08/15/2006 (10:29 am)
Not hard at all.

You have to work out exactly what you want from a design point of view. I.e. tell me exactly what you want, then I can give you some more specific help.

Have you tried my example above? Did it work? What did you think?

If you can follow the code, it would be quite easy for you to customize it in any number of different ways. You could store more messages, add more options to the GUI etc etc.
#4
08/16/2006 (10:44 am)
I didnt try it out yesterday and I'm pretty busy today but I'll try it as soon as I can :)
I thought it would be best to have a big list (like the keymapping-list)
where all the keys are on the left side and the text-field is on the right side.
Then player could just type out the text for the key he wants and also he could see what he has bound and where.
Dunno how does it sound but personally I think it could work.