Coding Overview

  • [code]

The Ares coding experience is different from what you might be familiar with from other MUSH servers. There is no softcode. You can’t alter the code just by slinging some &CMD-+WHERE #123=$+where:think pemit(%#,switch(...)) text into your MUSH client. The game code lives on the server. Unlike old MUSH hardcode, though, it can be changed while the game is running.

What Ares Code is Like

The Ares game server code is written in Ruby. Ruby is a mainstream language, so you’ll find tons of tutorials, reference guides and community support sites.

You can run quick one-off tasks straight from your MU client, but anything more advanced will require you to change the code server-side and then reload it. You can do this while the game is running.

Many people find Ares code more readable and easier to learn than softcode. The following example shows a snippet of code from the AFK command (afk <message>), comparing traditional MUSH softcode and Ares code.

Normally MUSHcode would be all smushed together in one line, but let's assume we're using a code prettifier to break it apart:

    @@ Update the afk message and flag on the character executing the command (%#)
    
    [set(%#,afk_message: %0)]
    [set(%#,is_afk: 1)]
    
    @@ Save their last IC location so they can go back with the 'onstage' command later.

    [u(#493/fun_update_last_ic_location, %#)]
    
    @@ Tell the room they went AFK. 
    
    [remit(%l, %N has gone afk: %0.)]
    
    

Ares code is inherently done on multiple lines so there's no need for a prettifier tool:
 
    # Store the command arguments into a variable

    self.message = cmd.args
    
    # Update the afk message and flag on the character executing the command (enactor)

    enactor.update(afk_message: self.message)
    enactor.update(is_afk: true)
    
    # Save their last IC location so they can go back with the 'onstage' command later.

    Status.update_last_ic_location(char)
    
    # Tell the room they went AFK.  
    
    enactor.room.emit_ooc "#{enactor.name} has gone AFK: #{self.message}."

    

A lot of learning Ares code boils down to knowing what functions are available and how to call them. That’s what the basic Ares coding tutorials will teach you.

Triggering Commands

The scaffolding around how commands get triggered is also different. In MUSH Softcode, commands are placed on objects, which in turn are placed in rooms. To make a command global, you put an object into the master room. Commands are triggered by pattern matching:

&CMD-Cookie Cookie Command Object=$+cookie *:(cookie code goes here)

In Ares, all commands are global. Commands don’t live on objects, but rather in Ruby classes in the server-side code.

class CookieCmdHandler
   def handle
     (cookie code goes here)
   end
end

There’s a dispatcher for each plugin that sends the command to the appropriate class - typically based on the command’s base name (aka root) and switch.

module Cookies
  def get_cmd_handler(cmd, client)
    if (cmd.root_is?("cookie"))
      if (cmd.switch_is?("here"))
        return CookieHereCmdHandler
      else
        return CookieCmdHandler
    end
  end
end

Although all commands are technically global, you can restrict code to only work under certain conditions. For example:

  • If the character is in a particular room or area.
  • If the character belongs to a particular faction.
  • If the character has a certain skill.

In other situations, that command would give an error.