Difference between revisions of "Manual:Migrating"

From Mudlet
Jump to navigation Jump to search
Line 185: Line 185:
 
</td>
 
</td>
 
<td>
 
<td>
<p>#if <condition> <text></p>
+
<nowiki>#if <condition> <text></nowiki>
<p>#if <condition> { <script> }</p>
+
<nowiki>#if <condition> { <script> }</nowiki>
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 194: Line 194:
 
</td>
 
</td>
 
<td>
 
<td>
<p>#if <condition> { <script> } else { <script> }</p>
+
<nowiki>#if <condition> { <script> } else { <script> }</nowiki>
<p>#if <condition> { <script> } { <script> }</p>
+
<nowiki>#if <condition> { <script> } { <script> }</nowiki>
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 203: Line 203:
 
</td>
 
</td>
 
<td>
 
<td>
<p>#if <condition> { <script> } elsif <condition> { <script> }</p>
+
<nowiki>#if <condition> { <script> } elsif <condition> { <script> }</nowiki>
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 211: Line 211:
 
</td>
 
</td>
 
<td>
 
<td>
<p>#if <condition> { <script> } elsif <condition> { <script> } else { <script> }</p>
+
<nowiki>#if <condition> { <script> } elsif <condition> { <script> } else { <script> }</nowiki>
 
</td>
 
</td>
 
<tr>
 
<tr>
Line 316: Line 316:
 
<tr>
 
<tr>
 
<td><variable name> = "<text value>"</td>
 
<td><variable name> = "<text value>"</td>
<td><p>#set <variable name> <text value></p></td>
+
<td><nowiki>#set <variable name> <text value></nowiki></td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td><variable name> = <expression></td>
 
<td><variable name> = <expression></td>
<td><p>#set <variable name> = <expression></p></td>
+
<td><nowiki>#set <variable name> = <expression></nowiki></td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td><variable name> = nil</td>
 
<td><variable name> = nil</td>
<td><p>#unset <variable name></p></td>
+
<td><nowiki>#unset <variable name></nowiki></td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td><variable> = <variablename> <+ - / *> <number or variable></td>
 
<td><variable> = <variablename> <+ - / *> <number or variable></td>
<td><p>#add <variablename> <expression></p></td>
+
<td><nowiki>#add <variablename> <expression></nowiki></td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>echo "text\n" or echo("text\n")</td>
 
<td>echo "text\n" or echo("text\n")</td>
<td><p>#echo <text></p></td>
+
<td><nowiki>#echo <text></nowiki></td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>echo "text" or echo("text")</td>
 
<td>echo "text" or echo("text")</td>
<td><p>#echo_ <text></p></td>
+
<td><nowiki>#echo_ <text></nowiki></td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>enableAlias("<group name>")/enableTrigger()/enableKey()/enableTimer()</td>
 
<td>enableAlias("<group name>")/enableTrigger()/enableKey()/enableTimer()</td>
<td><p>#groupon <group name></p></td>
+
<td><nowiki>#groupon <group name></nowiki></td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>disableAlias("<group name>")disableTrigger()disableKey()disableTimer()</td>
 
<td>disableAlias("<group name>")disableTrigger()disableKey()disableTimer()</td>
<td><p>#groupoff <group name></p></td>
+
<td><nowiki>#groupoff <group name></nowiki></td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>selectString (line, 1) bg("<color>") resetFormat()</td>
 
<td>selectString (line, 1) bg("<color>") resetFormat()</td>
<td><p> #highlight <color></p></td>
+
<td><nowiki> #highlight <color></nowiki></td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>deleteLine()</td>
 
<td>deleteLine()</td>
<td><p>#gag</p></td>
+
<td><nowiki>#gag</nowiki></td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>openUrl("<url>")</td>
 
<td>openUrl("<url>")</td>
<td><p>#openurl <url></p></td>
+
<td><nowiki>#openurl <url></nowiki></td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>send("<stuff>")</td>
 
<td>send("<stuff>")</td>
<td><p>#send <text></p></td>
+
<td><nowiki>#send <text></nowiki></td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>sendAll("hi", "hello", "bye")</td>
 
<td>sendAll("hi", "hello", "bye")</td>
<td><p>#send_ hi #send_ hello #send bye</p></td>
+
<td><nowiki>#send_ hi #send_ hello #send bye</nowiki></td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>tempTimer(<time in s>, [[ <nowiki><lua code to do once time is up></nowiki> ]])</td>
 
<td>tempTimer(<time in s>, [[ <nowiki><lua code to do once time is up></nowiki> ]])</td>
<td><p>#wait <milliseconds></p></td>
+
<td><nowiki>#wait <milliseconds></nowiki></td>
 
</tr>
 
</tr>
 
</table>
 
</table>

Revision as of 06:34, 8 July 2011

From Nexus

Trigger patterns
Lets start with triggers. For translating Nexus patterns into Mudlet, use the following table below. Make sure to set the pattern type in Mudlet to be perl regex, because the default substring works differently.

Mudlet Nexus What it does
(\w+) {w} Match one or more non-whitespace characters (a 'word')
(\d+) {d} Match one or more numeric digits (a number)
([abc]) {[abc]} Match one or more of either 'a', 'b' or 'c'. (a character class)
([^abc]) {[^abc]} Match one or more of anything EXCEPT 'a', 'b', or 'c'
(.*) {*} Match zero or more characters (anything)
^ {<} Match the beginning of a line (not the actual newline character)
$ {>} Match the end of a line (not the actual newline character)
Note:
If you just have a pattern with a {<} and {>} and nothing else, copy the pattern over without the {<}{>} and select the exact match pattern type. For example {<}You sit down.{>} in Nexus would become You sit down. in Mudlet with the pattern type of exact match. This is easier to read and matches way faster!

Basic scripting
The Nexus way of doing a function is like this: #function stuff it does. In Mudlet, it’s function(stuff it does). Note that if you’d like to give text to a function, you put it inside double or single quotes.

Calling functions

Calling functions
Mudlet Nexus

<lua> send("hi") echo("Hello to me!") </lua>

#send hi
#echo Hello to me!

Note:

If you’d like to use a variable inside text, you’d put it outside the quotes and glue it together with two dots.

Setting variables

Setting variables
Mudlet Nexus

<lua> number = 1234 echo("My number is: " .. number.. "\n") echo("the " .. number .. " is in the middle of my text\n") echo(string.format("And here's another - %s - way to format things\n", number)) </lua>

#set number 1234
#echo My number is: $number
#echo the $number is in the middle of my text

Wildcards
To use the wildcard variable in Nexus, you’d use $1 for the first match, $2 for the second and so on. In Mudlet, the matches[] table contains the matches - and it starts placing the matches from 2. So the Nexus $1 would be matches[2], $2 would be matches[3].
Mudlet Nexus

<lua> (\w+) kicks you\. badguy = matches[2] echo(badguy .. " kicked me!") </lua>

{w} kicks you.
#set badguy $1
#echo $badguy kicked me!

<lua> alias pattern: ^t (.*)$ alias script: target = matches[2] </lua>

alias name: t
alias script: #set target $1

Note:

The reason the first match goes into matches[2] and not matches[1] is because matches[1] contains the part of the line that matched your trigger / alias.

#wait
In Nexus, a #wait will freeze the script while it’s executing - such that commands after it are delayed. In Mudlet, we use tempTimer which that works a bit differently - it doesn’t freeze the script, but instead makes it so commands a tempTimer is asked to do will get done in the future. So the difference is that a tempTimer doesn’t freeze the commands following it at all, everything gets done at once as usual. Just things a tempTimer was asked to do get done in the future.
Mudlet Nexus

<lua> send("hello") tempTimer(1, send("hi")) tempTimer(1.5, send("bye")) </lua>

#send hello
#wait 1000
#send hi
#wait 500
#send bye

ifs in Mudlet
Next are the #if statements. Here’s a table comparing the syntaxes of Nexus and Mudlet:

Mudlet Nexus

if <condition> then <text> end

#if <condition> <text> #if <condition> { <script> }

if <condition> then <script> else <script> end

#if <condition> { <script> } else { <script> } #if <condition> { <script> } { <script> }

if <condition> then <script> elseif <condition> then <script> end

#if <condition> { <script> } elsif <condition> { <script> }

if <condition> then <script> elseif <condition> then <script> else <script> end

#if <condition> { <script> } elsif <condition> { <script> } else { <script> }


Here is the sample side-by-side comparison of how you’d use it:

Mudlet Nexus

<lua> -- If foo is true, echo that fact.

 if foo then echo ("Foo is true!") end -- If foo is true, echo that fact.

-- A slight modification of the above that illustrates an 'else' clause. -- Note that the 'then' is always necessary to avoid confusion.

 if foo then echo ("Foo is true!") else echo ("Foo is false!") end

-- Illustration of putting more than one statement in a block (also -- spans lines here). Note the if doesn't end until the last 'end' is -- encountered. -- We also add a \n at the end of multiple echos so each one is on it's own line.

 if foo then
   echo ("Foo is true!\n")
   echo ("Isn't it grand?\n")
   echo ("These commands are all on separate lines too!\n")
 end

-- This shows how ifs continue (on 'logical' lines) even though the -- blocks in its constituent clauses may have multiple lines. The -- following lines are all _one_ single if statement.

 if foo > 50 then
   echo ("Foo is big!\nYes it is.")
 elseif foo > 10 then
   echo ("Foo is pretty big...\n")
   echo ("I've seen bigger.")
 else
   echo ("Foo is actually kind of small.")
 end

-- Ifs can be nested too.

 if foo then
   if bar then
     echo ("Both foo and bar are true.")
   else
     echo ("Foo's true, but bar isn't.")
   end
 end

</lua>


// If $foo is true, echo that fact.

 #if $foo #echo Foo is true!     // If $foo is true, echo that fact.


// A slight modification of the above that illustrates an 'else' clause.
// The second form shows that the word 'else' is actually optional too.
// (The two lines are functionally the same.)

 #if $foo { #echo Foo is true! } else { #echo Foo is false! }
 #if $foo { #echo Foo is true! } { #echo Foo is false! }


// Illustration of putting more than one statement in a block (also
// spans lines here). Note the if doesn't end until the last '}' is
// encountered.

 #if $foo {
   #echo Foo is true!
   #echo Isn't it grand?
   #echo These commands are all on separate lines too!
 }


// This shows how ifs continue (on 'logical' lines) even though the
// blocks in its constituent clauses may have multiple lines. The
// following lines are all _one_ single if statement.

 #if $foo > 50 {
   #echo Foo is big!
   #echo Yes it is.
 } elsif $foo > 10 {
   #echo Foo is pretty big...
   #echo I've seen bigger.
 } else {
   #echo Foo is actually kind of small.
 }

// Ifs can be nested too.

 #if $foo {
   #if $bar {
     #echo Both foo and bar are true.
   } else {
     #echo Foo's true, but bar isn't.
   }
 }

Mudlet equivalents of Nexus functions

Now that we got the ifs covered, lets go over the Mudlet equivalents of other Nexus functions. Note that this is a direct Nexus→Mudlet comparison; certain functions in Mudlet have much more capability.

Mudlet Nexus
<variable name> = "<text value>" #set <variable name> <text value>
<variable name> = <expression> #set <variable name> = <expression>
<variable name> = nil #unset <variable name>
<variable> = <variablename> <+ - / *> <number or variable> #add <variablename> <expression>
echo "text\n" or echo("text\n") #echo <text>
echo "text" or echo("text") #echo_ <text>
enableAlias("<group name>")/enableTrigger()/enableKey()/enableTimer() #groupon <group name>
disableAlias("<group name>")disableTrigger()disableKey()disableTimer() #groupoff <group name>
selectString (line, 1) bg("<color>") resetFormat() #highlight <color>
deleteLine() #gag
openUrl("<url>") #openurl <url>
send("<stuff>") #send <text>
sendAll("hi", "hello", "bye") #send_ hi #send_ hello #send bye
tempTimer( #wait <milliseconds>

How to call aliases in Mudlet
The typical workflow in Nexus is that you’d define the aliases for yourself to use, and also use aliases for system-related things (things like checking if you’d need to eat a herb, etc).

While the first use is good, the second isn’t - because the user can also run this alias at an inopportune time, because if you want to call an alias it has to match all alises again, and so on.

Now, while in Mudlet you can call another alias with the expandAlias() function, this is strongly discouraged. What you do instead if create a function (for example, send() and echo() are functions) that you can then call from your alias or trigger. This has many advantages - it’s faster, you can easily give your function values, and your function can return you values, too.

To make a function, you go to the Scripts section, create a new script, and write in your function: <lua>

 function <name> ()
   <stuff it does>
 end

</lua> For example, if we want to make a function that does two things for us at once, we’d do this: <lua>

 function eat_bloodroot()
   send ("outr bloodroot")
   send ("eat bloodroot")
 end

</lua> Then just do this in our alias or trigger to outr and eat bloodroot: <lua>

 eat_bloodroot()

</lua> As mentioned, you can also give things to functions - in this case lets expand the function to eat any herb for us we tell it: <lua>

 function eat (what)
   send ("outr " .. what)
   send ("eat " .. what)
 end
 [...]
 eat ("bloodroot")
 eat ("kelp")
 eat ("ginseng")

</lua> Lastly, functions can also give you data back. One useful example for this is to break down tasks into functions, which will help your code readability: <lua>

 function can_i_stand()
   if not paralyzed and not prone and not stunned then
     return true
   else
     return false
 end
 [...]
 if can_i_stand() and have_balance and have_equilibrium then
   send ("stand")
 end

</lua>

Notes to be aware of

To finish off, a couple of points that should be remembered:

  • Mudlet does profile snapshots (nexus archives) automatically - to load a different one, select it from the list when connecting
  • Mudlet can import and export xml
  • Mudlet and Nexus xml formats aren’t compatible
  • Mudlet can do nexus graphics, here is a package for - [Achaea], [Lusternia]
  • Mudlet has a ton more features such are more speed, less bugs, copy from the normal window, replay logging, color html logging, more powerful scripting, and the list goes on.

From MUSHclient

  1. Mudlet doesn't use %#'s - uses matches[] instead. "%1" or %1 would be matches[2], "%2" or %2 would be matches[3] and so on
  2. No variables in trigger patterns - but you can check against your variables in scripts, or lua function pattern types

From CMUD

Changing over to Mudlet requires learning some simple syntax changes and some general concept changes:

In a mudlet trigger for example: Name is just the name you want to use to label the trigger. It doesn't effect the actual firing of the trigger. The trigger fires based on the "pattern" and you can have multiple patterns for a single piece of code. You can also have a multi-line trigger, where the entire trigger must see all the patterns to fire. Example #1 - Using a variable and a temp trigger Cmud: <lua> Pattern: ^A (.*) shard appears and clatters to the ground\.$

Code:

  1. IF (@autogold) {
  2. temp {You have recovered balance on all limbs.}

{get shard} } </lua>

Mudlet Example: <lua> Pattern: ^A (.*) shard appears and clatters to the ground\.$

Code: if autogold then shardtrigger = tempTrigger("You have recovered balance on all limbs.)", send("get shard") killTrigger(shardtrigger)) end </lua>

Example #2 - Doing Math: Cmud: <lua> Pattern: ^You put (\d+) gold sovereigns in (.*)\.$

Code:

  1. ADD goldcounter %1

</lua> Mudlet: <lua> Pattern: ^You put (\d+) gold sovereigns in (.*)\.$

Code: goldcounter = goldcounter + tonumber(matches[2]) </lua>

Example #3 - Replacing Text Cmud <lua> Pattern: ^You raze (\w+) magical shield with (.*)\.$

Code:

  1. sub {%ansi(yellow,cyan,bold)(*X*)%ansi(white) RAZED %ansi(red)%1's %ansi(white)Shield %ansi(yellow,cyan,bold)(*X*)}

</lua> Mudlet <lua> Pattern: ^You raze (\w+) magical shield with (.*)\.$

Code: deleteLine() cecho("<yellow:cyan>You RAZED " .. matches[2] .. " shield") </lua>

Example #4 - Enable/Disable Classes

Cmud: <lua>

  1. T+ ClassFolderName

</lua>

Mudlet: <lua> enableAlias("ClassFolderName")

Note: Alias can be an alias, trigger, time, key, etc. You can disable entire classes or just single triggers. </lua>

Example 5 - Multi-action Commands Let's say we create an alias called silly

Cmud: <lua> Pattern: sillyAction

Code: look;ct Hello City;pt Hello Party;laugh

Now in cmud if we called this alias from a trigger or another alias, we would just call sillyAction

</lua> Mudlet: <lua> Pattern: sillyAction

Code: sendAll("look","ct Hello City","pt Hello Party", "laugh") </lua>

Now, in mudlet, if we want to call on that alias, we need to tell mudlet that we want to execute the alias sillyAction rather than sending "sillyAction" directly to the mud. To do that we would do:

<lua> expandAlias("sillyAction") </lua>

Example 6 - Using if statements with and, or and nil.

Cmud Code: <lua>

  1. IF (@myclass="knight" & !(@pets))

{ say cool } </lua> Mudlet Code: <lua> if myclass == "knight" and not pets then

 send("say cool")

end </lua>

Example 7 - Hitting your target OR your first argument. This is for when you want to either hit the person you have targeted, or the name you type.

For example, to kick Das you'd type: kk Das

Or if Das is your target, just typing kk

Cmud: <lua> Pattern: ^kk ?(\w+)?$

  1. VAR target Das

if (@target) { kick @target } if (%1) { kick %1 } </lua>

Mudlet: <lua> Pattern: ^kk ?(\w+)?$

Code: target = "Das" send("kick "..(matches[2] or target)) </lua> Example #7 - Two Pattern Examples <lua>^rz(?:(.*)|)$ This would let you do rzDas to raze Das for example. </lua> Versus: <lua> ^rz ?(\w+)?$ This would require you to do rz Das with a space between rz and Das. </lua>

From zMUD