-
Notifications
You must be signed in to change notification settings - Fork 0
Example scripts
I have one particular user that has written many scripts to support his D&D Fifth Edition games. Rather than writing comprehensive documentation, which I am bad at, I am copying some of his scripts here and using those to point out script features. Hopefully this is good enough documentation to get people started.
This macro is run to set up variables used by other macros. It's pretty simple but still teaches a lot about the language.
!macro set !reset !! ignore table("delete channel Health");
ignore table("delete channel Group");
ignore table("delete channel Group");
ignore table("delete channel Type");
ignore table("delete channel groupNames");
ignore table("delete channel Status");
ignore table("create channel Health");
ignore table("create channel Group");
ignore table("create channel Type");
ignore table("create channel groupNames");
ignore table("create channel Status");
channel.groupNames[0] = "**Close Range (1 - 30 ft.)**
";
channel.groupNames[1] = "**Medium Range (31 - 60 ft.)**
";
channel.groupNames[2] = "**Long Range (61 - 90 ft.)**
";"table" is a function used to bridge between the programming language and the more normal single-line commands. Since you can do "!table delete channel groupNames" I needed a way to do the same thing in the language. I made all !command commands into function calls that simply take the rest of the command as a string. It's a hack.
Because it's a hack I also had to implement "ignore." The "!table delete channel groupNames" outputs "Table deleted." The programming language then tries to execute that string normally, which would generate an error. "ignore" takes its input and does what it says: it ignores it so that it doesn't generate an error.
"channel.groupNames[0]" is how you reference a table on a channel from within the script. You can edit tables using this syntax, but the script writer used table() syntax for creating and deleting because I haven't put a way to do that into the language proper.
This sets up a character in combat. It takes several arguments, which is the main new thing in this macro.
!macro set !hset !! channel.Health[{1}] = {3};
channel.Group[{1}] = {2};
if ({4} == "true") {channel.Type[{1}] = "Monster";} else {channel.Type[{1}] = "Player";}{0} and so forth is how you reference arguments to the macro. So you usually use this macro by doing !hset creature group health isMonster
We can also see here if statements and == for comparison.
Adds a status effect to a creature.
!macro set !s !! channel.Status[{1}] = {2+};The main new thing in this macro is the use of {2+}. This takes arguments from 2 to however many you provide and puts those into a single string.
This is a huge one and is the ultimate culmination of the macros above. This one displays all the info we've been managing about users and enemies.
!macro set !d !! echo "
";
echo channel.groupNames[0];
echo "```";
foreach(channel.Group) {
if (channel.Group[key] == 0 && channel.Type[key] != "Monster" ){
echo key + ": " + channel.Health[key] + " HP (" + channel.Status[key] + ")
";}
}
echo "
";
foreach(channel.Group) {
if (channel.Group[key] == 0 && channel.Type[key] != "Player" ){
echo key + ": " + channel.Health[key] + " HP (" + channel.Status[key] + ")
";}
}
echo "```
";
echo channel.groupNames[1];
echo "```";
foreach(channel.Group) {
if (channel.Group[key] == 1 && channel.Type[key] != "Monster" ){
echo key + ": " + channel.Health[key] + " HP (" + channel.Status[key] + ")
";}
}
echo "
";
foreach(channel.Group) {
if (channel.Group[key] == 1 && channel.Type[key] != "Player" ){
echo key + ": " + channel.Health[key] + " HP (" + channel.Status[key] + ")
";}
}
echo "```
";
echo channel.groupNames[2];
echo "```";
foreach(channel.Group) {
if (channel.Group[key] == 2 && channel.Type[key] != "Monster" ){
echo key + ": " + channel.Health[key] + " HP (" + channel.Status[key] + ")
";}
}
echo "
";
foreach(channel.Group) {
if (channel.Group[key] == 2 && channel.Type[key] != "Player" ){
echo key + ": " + channel.Health[key] + " HP (" + channel.Status[key] + ")
";}
}
echo "```