Scripting in Dragon's Gate
This page is about scripting in Dragon's Gate: how the game reads your script's commands, what it says back, and short scripts for everyday tasks. You see this page in Help only when you're playing Dragon's Gate. The language, every verb and how waits work, is in Scripting. The variables a script can read are in Settings > Variables.
The game text on this page shows how the game answers. The game's wording can change, so copy the words for a waitfor or a pattern from your own game window or logs.
When you copy, check the apostrophes. The game types a straight one, like this: '. Some programs, such as word processors, change it to a curly one, like this: ’. A script looks for the exact characters, so a curly apostrophe never matches the game's straight one, and the script waits for words that never come.
Item names in a script
Send one word for an item
After a command such as get, open or ready, the game reads only one word. It uses that word to find the item. When a script sends more than one word, the game looks for the first word and ignores the rest.
send get silver coinsThe game answers I see no "silver" in the room! It looked for an item called silver and found none. This line works:
send get coinsThe game answers You pick up 12 silver coins.
Let Merlin find the word
Some variables already hold the one word the game wants, so a script can use them as they are:
$weaponholds the weapon in your right hand. For a short simple dagger, it holdsdagger.$lootholds a list of what your kill dropped, one word for each thing. Silver coins arecoins.$targetholds the creature you last attacked. When there are two hounds and you attacked the second, it holds2nd hound.
send unready $weaponThis reads as: put away the weapon in your right hand, whatever it is.
When a name comes from somewhere else, such as a list you wrote, text can keep only its last word. The last word is usually the one the game wants.
set item long bronze dagger
text word last $item
send get $wordThis reads as: from long bronze dagger, keep the last word, dagger, then pick up the dagger.
A few items need two words, such as throwing dagger. Those are listed in a file called item-nouns.txt, and you can add your own. To find it, open your Merlin folder, then the game's folder, then Config. $weapon and $loot use that list too.
Number the second one
When there are two of the same thing, the game numbers them. The second bag is the 2nd bag, and the first needs no number. text turns a plain number into the game's way of counting:
set n 2
text which ordinal $n
send open $which bagThis reads as: turn 2 into 2nd, then open the 2nd bag.
For creatures, a plain number works too. attack 2 target reaches the 2nd practice target, so a script can use a counter such as $n without changing it.
Delays
Almost everything you do starts a delay, and the game prints it: [3 sec. delay]. A command sent during a delay waits in the game's queue and goes out late. pause waits out the delay for you, so a pause after each action is enough. Merlin also holds a script's next command until the game has answered the last one, so two send lines in a row never pile up.
After a fight, some things wait. For 35 seconds after the last blow, the game refuses hide, train, the healer and quit with You cannot do that while in combat! See Wait until the fight is over.
Running out of energy. With too little fatigue left, a command gets You try, but find you don't have enough energy to do that! $stamina is your fatigue as a percent. Resting brings it back. See Rest until your fatigue is full.
Everyday scripts
Short scripts for things you do every day. Change the words to fit what you carry.
Rest until your fatigue is full
send lie
send rest
repeat
pause 30
until You are fully rested
send standThis reads as: lie down, rest, and check every 30 seconds until the game says ** You are fully rested. Then stand up.
- Resting can take 5 to 25 minutes. That's longer than one
waitforcan wait, so the loop keeps checking as long as it takes. - Any command ends the rest, and the game says
You stir from your rest.That includes a command a timer sends.
Treat your wounds
send lie
waitreply
repeat 30
send treat $firstname
pause 1
until Target is not injured
send standThis reads as: lie down, then treat your own wounds, again and again, until the game says Target is not injured. Then stand up. It stops after 30 tries at most.
- The game won't let you treat standing up. Treating while standing answers
Target must be sitting or lying upon the ground., so the script lies down first. $firstnameis your character's first name, so the script works for any character.- Each treat answers
You tend your wounds.and starts a delay. Thepausewaits it out.
Visit the healer
send shop heal
waitfor restored to full vitalityThis reads as: ask the healer to heal you, and wait until the game says You are healed and restored to full vitality! For 35 seconds after a fight, the game still counts you as in combat, and the healer won't heal you until that time is up. See Wait until the fight is over.
Train a skill when it's ready
send train list
waitreply
if $ready(Hiding) = yes then send train raise $trainnum(Hiding)This reads as: ask the trainer for the list, wait for the whole answer, then raise Hiding if it's ready.
$ready(Hiding)isyesonce the game has saidYou now feel prepared to train further in Hiding.$trainnum(Hiding)is the number the trainer gives Hiding. Merlin learns the numbers fromtrain list, which is why the script sends it first.- Training ends with
…escorted back out into the entry area. - Write the skill's name the way the skills list shows it.
Pick up every pile of coins
repeat 20
send get coins
pause 1
until I see no "coins"This reads as: pick up coins until the game says I see no "coins" in the room! Each get coins picks up one pile: You pick up 12 silver coins.
Put coins in the bank
matchre Done new account balance is (\d+) silver
send bank deposit 100 silver
matchwait
Done:
echo You have $arg1 silver in the bank.This reads as: put 100 silver in the bank, then show the new balance. The teller answers The teller says, "Your new account balance is 100 silver." The pattern catches the number, and the script shows it as $arg1.
Buy at the Supply Depot
args number
repeat 3
send shop buy $number
waitfor The merchant accepts your
untilThis reads as: buy the item with this number, three times. Read shop list all first, then type .buy and the item's number, such as .buy 12.
Each purchase answers with a line that starts The merchant accepts your, then the price and the item. The price depends on the shop and the item, and it can change. The script waits only for The merchant accepts your, the words every purchase has, so it works whatever the price is.
- The numbers can change, so read the list before you buy.
Open a bag, whatever the answer
send open backpack
waitforre You open|already opened|locked|I don't seeThis reads as: open your backpack, and go on whichever answer comes:
You open the closed large leather backpack.But it's already opened!It's locked.I don't see what you are referring to.
Light a torch when it's dark
action send ready torch when too dark to see anythingThis reads as: whenever the game says It's too dark to see anything!, ready your torch. Readying a torch lights it: You light the wooden torch. Then The area brightens.
When you're out of torches, the game says You don't have a 'torch' in your inventory! Two more actions can catch that line. One tells you out loud, and the other ends the script, so it doesn't carry on in the dark:
action send ready torch when too dark to see anything
action speak Out of torches when You don't have a 'torch'
action stop when You don't have a 'torch'This reads as: when it's too dark to see, ready your torch. If you have no torch, say "Out of torches" out loud, then end the script. The speak line comes before the stop line, because nothing happens after a script stops.
An action lasts only while its script runs. To watch all the time, make it a trigger instead. See Triggers.
Wait until the fight is over
waiteval 60 $incombat = no
send shop healThis reads as: wait until you're out of combat, then ask the healer to heal you.
$incombatstaysyesfor 35 seconds after the last blow. That's longer than a wait's usual 30 seconds, so the60gives it room.
Get back up after a fall
action send stand when You stumble and fall downThis reads as: whenever you're knocked down, stand back up. The game answers You stand up. Put the line near the top of a script, and it works the whole time the script runs.
Patterns for Dragon's Gate text
Some lines start with spaces
The game starts some lines with spaces, such as the line for a broken weapon:
Your damaged short simple dagger just broke!In a pattern, ^ means the start of the line. Because of the spaces, ^Your never matches this line. Write ^\s*Your instead. \s* means any number of spaces, or none, so the pattern matches whether the line has spaces or not.
Tell your line from another player's
When another player's weapon breaks, the game prints the same words with their name in front:
Belka's damaged short wooden stick just broke!A waitfor just broke would wake for both. To catch only the line about your weapon, start the pattern with ^\s*Your:
action set broke yes whenre ^\s*Your .+ just brokeThis reads as: when a line starts with Your and ends with just broke, set broke to yes. Another player's broken weapon starts with their name, so it doesn't count.
Weapons and gear in a script
After a weapon breaks
A broken weapon leaves your hand, so $weapon holds none. A script can check that and ready another:
if $weapon = none then send ready swordThe broken weapon is still in your inventory, and ready refuses it: Sorry, but it is too damaged to be used! This matters when you carry a spare. ready dagger can reach the broken dagger first, even with a good one in your inventory, and a script that only tries ready dagger again gets the same refusal every time.
Throw a weapon away only when the game has just said it's too damaged:
match Broken too damaged to be used
match Ready is now your ready weapon
send ready dagger
matchwait
Ready:
stop
Broken:
send throw dagger
waitfor It shatters on impact
send ready daggerThis reads as: try to ready the dagger. If it's ready, stop. If the game says it's too damaged, throw that dagger away, wait until it shatters, then ready the good one. A good dagger is never thrown, because the throw happens only after the game has refused the dagger as too damaged. The game picks which dagger to throw. It throws the same one ready just refused: the broken one.
Thrown weapons
Many thrown weapons, such as a javelin, land on the floor after a throw. Pick the weapon up and ready it again before the next throw:
send throw javelin at target
pause 1
send get javelin
pause 1
send ready javelin
pause 1This reads as: throw the javelin at the target, pick it up, then ready it again. Each pause 1 waits out the delay before the next command goes out. The game answers each step:
You throw your simple javelin at the practice target!You pick up a simple javelin.The simple javelin is now your ready weapon.
Bows
A bow needs an arrow before every shot. nock arrow puts one on the string, and the game answers Done. Then attack shoots it. Attacking without an arrow answers You must LOAD or NOCK an arrow or bolt first!
repeat 5
send nock arrow
send attack target
pause 1
untilThis reads as: five times, put an arrow on the string, then shoot at the target. The game answers You fire your simple wooden long-bow at the practice target! Nocking has no delay, so the pause 1 after the shot is enough to wait it out.
Keep your distance with a bow
A bow needs room. When the target is too near, a shot answers You're too close. and no arrow flies. Step back with retreat and shoot again:
action set close yes when You're too close
set close no
repeat 10
send nock arrow
send attack target
pause 1
if $close = yes {
send retreat 1
pause 1
set close no
}
untilThis reads as: watch for "too close" the whole time. Then, ten times, nock an arrow and shoot. If the shot was too close, step back once and try again.
retreat 1steps back one step. The game counts distance in UDs and answersYou retreat 1 UDs to the rear!Each step back starts a 3-second delay, and thepausewaits it out.- The arrow stays on the string after a "too close". The next
nock arrowanswersYour wooden short bow is already loaded!That's fine. The shot after it still goes. - Sometimes you can't retreat any further. At the back of the room,
retreatanswersYou may not retreat any further into this area!Then you have toadvanceinstead.
Melee weapons
A melee weapon is one you hit with while holding it, such as a sword or a dagger. It needs to be close to its target. When the target is too far, an attack answers You must move closer to your opponent's rank to engage in combat. An action can step you forward:
action send advance 1 when You must move closerThis reads as: whenever the target is too far to hit, step forward one. The game answers You advance another 1 UDs! Stepping forward has no delay. At the front of the room, advance answers You cannot advance further in the area.
Armor
Armor breaks the same way weapons do. When it breaks, the game says Your damaged simple leather armor absorbs a bit of the damage, and is ruined! Like the broken-weapon line, it starts with spaces, so catch it with ^\s*Your .+ is ruined.
Creatures in a script
Look before you count
$monstercount is how many creatures are in the room. It changes only when you look, or when a room's description prints. A creature that walks in while you're busy isn't counted until then. Look first, and wait for the answer:
send look
waitreply
if $monstercount = 0 then echo The room is empty.This reads as: look around, wait until the game has finished answering, then check whether any creatures are here.
Get past a blocked exit
A creature can block the way: The dark hound blocks you from leaving! Each try is a new chance, and most get through within three tries.
repeat 5
move north
until eval $moved = yesThis reads as: try to go north up to five times, and stop trying once you get through. $moved holds yes when you reach the new room, and no when you're blocked. walkto tries again on its own, so a walk doesn't need this.
When the server restarts
The game prints ... PLEASE HOLD ... and then << You shake off the disorientation as the world returns. >> It puts your character back the way it was saved a little earlier. You may be in a room you had already left, and something you just picked up may be gone. Merlin still remembers things the way they were before the restart, so look around to update it:
action send look when You shake off the disorientationThis reads as: when the world comes back, look around, so Merlin knows where you are again. Check your inventory before carrying on, too.