Notes for Genesis/ColdCore


These are just some notes I've kept while learning ColdC and learning about the ColdCore. I hope you find them useful.

Jeremy Weatherford


Data types:

Object Name/Number

The lowest level of identifier usually used to reference objects in Genesis is the object name. This is a name, usually prefixed with a $, (eg, $user_xidus) which is unique in the entire game. It's not neccessarily related to the displayed name for the object. Genesis also assigns dbrefs to each object (eg, #42), but these are almost never used in programming. Object names can be changed via @rename.

Other constructs:


There are two odd looking and very non-C-like constructs used to simplify the handling of exceptions. They're called the critical and propagate expressions, and look like (| expr |) and (> expr <), respectively. Both can be used either as statements or expressions. The first has an obvious use -- it keeps you from having to use a try/catch with an empty catch block. Its value is false if an exception occurs. Note that this can be used in an if-else condition, so that's important. The propagate construct's importance isn't quite as obvious. In ColdC, exception information is not normally propagated. An unhandled exception in a method will result in a ~methoderr exception being thrown in the calling routine, which is uninformative. Using the propagate construct rethrows the exception itself, including any associated information. This should be used when a calling method should handle any problems that arise. You may frequently see something like (> .perms(caller()) <) at the beginning of ColdCore functions. This calls a routine to check permissions, and if there are any problems, it rethrows the problem to the calling method, without handling it directly, and without just throwing a generic ~methoderr exception.



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 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);

@ac bork to $user_xidus.bork_cmd


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.