Difference between revisions of "Manual:Basic Essentials"

From Mudlet
Jump to navigation Jump to search
(→‎echo: added link to cecho)
(→‎Basic Essentials: updated syntax highlighting)
Line 11: Line 11:
 
{{note}} If you want your command to be checked as if it's an alias, use [[Manual:Miscellaneous Functions#expandAlias|expandAlias()]] instead - send() will ignore them.
 
{{note}} If you want your command to be checked as if it's an alias, use [[Manual:Miscellaneous Functions#expandAlias|expandAlias()]] instead - send() will ignore them.
  
<lua>
+
<syntaxhighlight lang="lua">
 
send( "Hello Jane" ) --echos the command on the screen
 
send( "Hello Jane" ) --echos the command on the screen
 
send( "Hello Jane", true ) --echos the command on the screen
 
send( "Hello Jane", true ) --echos the command on the screen
Line 18: Line 18:
 
-- use a variable in the send:
 
-- use a variable in the send:
 
send("kick "..target)
 
send("kick "..target)
</lua>
+
</syntaxhighlight>
  
  
Line 33: Line 33:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
-- a miniconsole example
 
-- a miniconsole example
  
Line 50: Line 50:
 
cecho("sys", "<blue:OrangeRed>and this is with a blue foreground. ")
 
cecho("sys", "<blue:OrangeRed>and this is with a blue foreground. ")
 
cecho("sys", "<bisque:BlueViolet>Lastly, this is with both a foreground and a background.\n")
 
cecho("sys", "<bisque:BlueViolet>Lastly, this is with both a foreground and a background.\n")
</lua>
+
</syntaxhighlight>
  
<lua>
+
<syntaxhighlight lang="lua">
 
-- a label example
 
-- a label example
  
Line 64: Line 64:
 
setBackgroundColor("messageBox", 255, 204, 0, 200)
 
setBackgroundColor("messageBox", 255, 204, 0, 200)
 
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]])
 
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]])
</lua>
+
</syntaxhighlight>
  
 
===display===
 
===display===
Line 74: Line 74:
 
{{note}} Do not use this to display information to end-users. It may be hard to read. It is mainly useful for developing/debugging.
 
{{note}} Do not use this to display information to end-users. It may be hard to read. It is mainly useful for developing/debugging.
  
<lua>
+
<syntaxhighlight lang="lua">
 
myTable = {} -- create an empty lua table
 
myTable = {} -- create an empty lua table
 
myTable.foo = "Hello there" -- add a text
 
myTable.foo = "Hello there" -- add a text
Line 80: Line 80:
 
myTable.ubar = function () echo("OK") end -- add more stuff
 
myTable.ubar = function () echo("OK") end -- add more stuff
 
display( myTable ) -- take a look inside the table
 
display( myTable ) -- take a look inside the table
</lua>
+
</syntaxhighlight>
  
  
 
[[Category:Mudlet API]]
 
[[Category:Mudlet API]]
 
[[Category:Mudlet Manual]]
 
[[Category:Mudlet Manual]]

Revision as of 04:00, 29 June 2017

Basic Essentials

These functions are generic functions used in normal scripting. These deal with mainly everyday things, like sending stuff and echoing to the screen.


send

send( command, show on screen )
This sends "command" directly to the network layer, skipping the alias matching. The optional second argument of type boolean (print) determines if the outgoing command is to be echoed on the screen.

See also: sendAll()

Note Note: If you want your command to be checked as if it's an alias, use expandAlias() instead - send() will ignore them.

send( "Hello Jane" ) --echos the command on the screen
send( "Hello Jane", true ) --echos the command on the screen
send( "Hello Jane", false ) --does not echo the command on the screen

-- use a variable in the send:
send("kick "..target)


echo

echo([miniconsole or label], text)
This function appends text at the end of the current line.
Parameters
  • miniconsole: (optional) the miniconsole to echo to, or:
  • label: (optional) the label to echo to.
  • text: text you'd like to see printed. You can use \n in an echo to insert a new line. If you're echoing this to a label, you can also use styling to colour, center, increase/decrease size of text and various other formatting options as listed here.

See also: moveCursor(), insertText(), cecho(), decho(), hecho()

Example
-- a miniconsole example

-- first, determine the size of your screen
local windowWidth, windowHeight = getMainWindowSize()

-- create the miniconsole
createMiniConsole("sys", windowWidth-650,0,650,300)
setBackgroundColor("sys",255,69,0,255)
setMiniConsoleFontSize("sys", 8)
-- wrap lines in window "sys" at 40 characters per line - somewhere halfway, as an example
setWindowWrap("sys", 40)

echo("sys","Hello world!\n")
cecho("sys", "<:OrangeRed>This is random spam with the same background\n")
cecho("sys", "<blue:OrangeRed>and this is with a blue foreground. ")
cecho("sys", "<bisque:BlueViolet>Lastly, this is with both a foreground and a background.\n")
-- a label example

-- This example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle 
-- of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent 
-- and 255 opaque) the background text can still be read through.
local width, height = getMainWindowSize()
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1)
resizeWindow("messageBox",500,70)
moveWindow("messageBox", (width/2)-300,(height/2)-100 )
setBackgroundColor("messageBox", 255, 204, 0, 200)
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]])

display

display( content )
This is much like echo, in that is will show text at your screen, not send anything to anywhere. However, it also works with other objects than just text. This way, you can easily take a look at the contents of a lua table, etc.

See also: display()

Note Note: Do not use this to display information to end-users. It may be hard to read. It is mainly useful for developing/debugging.

myTable = {} -- create an empty lua table
myTable.foo = "Hello there" -- add a text
myTable.bar = 23 -- add a number
myTable.ubar = function () echo("OK") end -- add more stuff
display( myTable ) -- take a look inside the table