These are just some notes I've kept while learning ColdC and learning about the ColdCore. I hope you find them useful.
A self-contained example of adding a command to yourself. Requires programmer priveleges.
The following command will define a new command for yourself, 'bork'. When typed, you'll see 'You bork loudly.' People around you will see 'Xidus borked loudly.', assuming your name is Xidus. In order to do this, we need to create a new message definition, set the messages, define a method, and add the command. The following chunk does everything at once, then explanations will follow:
@def-msg me:bork +b=actor @msg me:bork=[actor] borks loudly. @msg me:bork.actor=You bork loudly. @program me.bork_cmd() arg cmdstr, cmd; var vars, message; vars = #[["actor", sender().name()], ["$actor", sender()]]; message = .eval_message("bork", $user_xidus, vars); sender().location().announce(message); . @ac bork to $user_xidus.bork_cmd @rehash bork
Amazing, isn't it? Just 12 or so commands. ;) Here's the breakdown:
The first statement, @program, is creating a method on your character, named bork_cmd. The following lines up to the single dot are part of that method. Note that the fifth line of the method involves an objref to your character, which should be $user_(yourname). In the example above, my character name was Xidus, so the ref is $user_xidus. Now, for the play-by-play:
The @def-msg command creates a new message set on yourself named bork. It creates one message branch, known as general, by default. The +b=actor tells it to also create a message branch named actor. Messages are then set for these two branches in the next two lines. The first @msg sets the message for the general branch. This message will be shown to everyone except the person who types 'bork'. We're using a special construct in the message in place of the person's name, [actor]. We'll see later how this is replaced. The second message definition specifies which branch to set the message for -- actor -- and sets a static message. The person typing the 'bork' command, or the actor, will see that message.
Now to the method itself. The @program command defines a method on yourself named bork_cmd. This method will be called when the command is executed. Here's a line-by-line for the method:
Once the method is defined, a command is added that calls the method. Then, @rehash is used to rescan the available commands. Now the bork command will be available for you.