toast/programming_examples.md

122 lines
3.0 KiB
Markdown

# Creation
This document can be considered a "cheat sheet" to be read in conjuction with
the [ToastStunt Programmer's Manual](https://github.com/lisdude/toaststunt-documentation/).
## Quickstart: Creating your First Object
```
@create $thing named "Bowl of Spaghetti"
@describe bowl as "Yummy yummy sketti"
@add-alias "sketti" to bowl
give sketti to vilmibm
```
Then, once you're sick of it...
```
@recycle bowl
```
## Quickstart: Creating Rooms
Check `help @dig`. The in-game documentation does a better job at explaining
this than I can.
Note that any registered account can create rooms that hang out in the void of
nothingness. In order to link your room to an existing room, you need to
either:
- Obtain permission from the other room's owner
- Convince them to run `@add-exit` and `@add-entrance` to your
entrances/exits
- Link to a publicly linkable room (Such as the Grassy Plains).
To make your room publicly linkable, you can change the permissions on the
`entrances`/`exits` properties:
```
;set_property_info(#DATABASE_ID, "entrances", {#131, "rwc"})
;set_property_info(#DATABASE_ID, "exits", {#131, "rwc"})
```
## Quickstart: Integrating with tilde.town
Typically, the use of `exec` and `curl` is restricted to wizard accounts. But
we all love each other here!
Check `help $tilde_utils`.
exec's "executables" directory is `/home/moo/executables`. Ask in #moo if you'd
like something added there.
## How to Reverse Engineer Objects
A great way to learn is to look at other objects around the MOO.
- `@show` can print out an object in detail, including properties (Provided you
have permission.)
- `@find` can find objects, properties, verbs.
- `@list` can print out verbs.
Eg, to print out the source code for the `who` command, you can use:
```
> @find :who
The verb :who is on rbiv(#131)--ANSI PC(#100)
> @list #100:who
```
## Example Objects
### The Orb of Seeing
Demonstrates how to get information about the players that interact with
objects.
```
@create $thing named "Orb of Seeing"
@verb orb:description tnt
@program orb:description
return {
"The "+this.name+" sees many things!",
"Viewer name: "+player.name,
"Item owner: "+this.owner.name
};
.
```
### George
Everyone's favorite sleepy lad.
Shows some more advanced concepts.
Defines a custom verb, "awaken", such that one may "awaken george".
```
@create $thing named "George"
@property george.awakened_time 0
@property george.time_awake 20
@verb george:description this none this rxd
@verb george:awaken this none none rxd
@program george:awaken
if ((time() - this.awakened_time) > this.time_awake)
player:tell("W H A M M U ! You awaken George!");
player.location:announce("W H A M M U ! "+player.name+" awakens George!");
this.awakened_time = time();
else
player:tell("George is already awake.");
endif
.
@program george:description
if ((time() - this.awakened_time) > this.time_awake)
return "He appears to be sleeping. Hopefully nobody AWAKENS him.";
else
return "George is awake and unfathomably powerful.";
endif
.
```