ID:1120274
 
Now that BYOND is migrating towards custom interfaces and in-map gui's, I have a neat little trick that will help speed up your interfaces.

If you haven't learned by now, everything you write in DM is server-side code; things that happen on the host machine. Clients are stupid, and don't do anything for themselves. The clients have to tell the server what the user is doing (mouse and keyboard) and the server replies with the result. This can make somethings slow, especially if packets are delayed by some amount. For example, if the user is experiencing a high ping on the connection, and initiates an action (lets say open a shop keeper dialog), the client may be waiting up to a second or even longer for that dialog to actually display. This is simply because of the distance between the computers and the amount of information being sent over the internet connection (and throttled if the connection is slow!).

This is not something we want to occur when the user is trying to input information into the client application. In BYOND, we don't really have the luxury of this option unless we're using the windows controls provided in the interface editor. But with these controls, we are somewhat limited to what type of things we can accomplish, and even then if we want to compute any type of logic with these controls, those once again, occur on the server side of things.

Here's one simple client skin command that you can apply to your project that will allow very quick response. Here, we're letting the skin (client) control part of our interface logic with an input box. In this example, we're basically showing/hiding and switching focus to an input control for the user to type in. Once the user is finished typing his message or input, we return focus to the map and hide the input again.

Here's the skin command (add it to the command of a macro of your choice):

//assumes you have the following:
//default is your main window
//that window has an input1 and a map1 control
//input1 is default
//map1 is default
.winset "default.input1.is-visible=true ? default.input1.is-visible=false default.input1.focus=false default.map1.focus=true : default.input1.is-visible=true default.input1.focus=true default.map1.focus=false"


Now, you need to actually add this to a key macro in your macro file. The reason for this is we don't depend on the server at all for this computation to happen. This will check to see if the input control is visible, and if it isn't, show it, and switch focus, and vice versa. Next, you'll need to make sure that this input box has a pre-command [such as say "]. The reason for this is you need to parse anything going into this command box, and once you're done parsing, return control to the map (and hide the input again). This is because the input control can't do this for its' self, but at least we've eliminated the dependency for the server on the initial reaction on the client (which would be rather annoying if it did not happen instantly).

Hopefully you've learned a little bit about how to work around the server-side only problems we can encounter in custom interface design.