From The Mana World
(Narrow down scope a bit; rewrote punctuation)
m (Archival of a rewrite I started on earlier this year)
Line 1: Line 1:
This is a proposal-in-making on standardizing both eAthena and TMWserv scripting. Any suggestions are welcome to be posted on the discussion page.
== Current and proposed practice ==
In my mind a scripting language should be simple to both understand and use. You should not need to be a C++/Lua hacker to be able to create a dialogue menu where some replies depends on certain circumstances. Here follows a few suggestions how the tmwserv Lua scripting could look.


== Typographical style ==
=== NPC dialogue ===
There exist various schools on typographical conventions, and most of them vary depending on situation. The following are recommendations for writing scripts in the Mana World. Examples for both [[eAthena Scripting Standards|eAthena]] and [[scripting|TMWserv]] will follow alongside each other. These style recommendations should of course be adjusted to the language in question when doing [[translations]].
Currently on eAthena:


=== Punctuation ===
// A comment!
# Ending a sentence:
#* Use multiple punctuation marks sparingly.
mes "[Maji Chan]";
#* Refrain from separating sentences with two or more spaces.
mes "\"How do you do my dear quester?\"";
# Something cut off or missing:
next;
#* Use an [http://en.wikipedia.org/wiki/Ellipsis ellipsis] (…) for something missing. (Replace with three dots, ..., in eAthena scripting.)
#* Use an [http://en.wikipedia.org/wiki/Dash#Em_dash em dash] (—) for something cut off. (Replace with two normal dashes in eAthena scripting.)
# Offsetting text parenthetically:
#* Use the [http://en.wikipedia.org/wiki/Dash#Em_dash em dash] (—) surrounded by a single pair of spaces. (Replace with two normal dashes in eAthena scripting.)
# Intervals and other ranges:
#* Use an [http://en.wikipedia.org/wiki/Dash#En_dash en dash] (–) for marking ranges, both numeric and other. (Replace with two normal dashes in eAthena scripting.)
#* Compounds use the normal dash.


'''eAthena example'''
Currently on tmwserv:
// 1. Sentence ending punctuation
 
  mes "A sentence. Another sentence!";
  -- A comment!
   
   
  // 2. Missing or cut off text
  do_message(npc, char, "“How do you do my dear quester?”")
mes "\"No, I don't want to--\"";
 
mes "It seems ... he died.";
Which is quite unwieldy. When scripting you most often only have the NPC say something to the player, so this could be simplified a fair bit to something like:
 
-- A comment!
   
   
  // 3. Parenthetically offset text
  message("“How do you do my dear quester?”")
  mes "By this apple -- and not any other -- she will rule the world.";
 
I would actually propose to <tt>gettext</tt>-ize it:
 
  -- A comment!
   
   
  // 4. Ranges
  message(_("“How do you do my dear quester?”"))
mes "Lately the Tulimshar--Hurnscald highway is rather non-lethal.";
mes "\"Give me 100--200 itens, pliz!\"";


'''TMWserv example'''
==== Using variables ====
  -- 1. Sentence ending punctuation
Currently on eAthena:
  do_message(npc, char, "A sentence. Another sentence!")
 
  set @variable_1 = 42; // numeral variable for the local script
  set @variable_2$ = "Bottle of Sand"; // string variable for the local script
   
   
  -- 2. Missing or cut off text
  mes "\"Did you bring " + @variable_1 + " [" + @variable_2$ + "]?\"";
do_message(npc, char, "“No, I don’t want to—”")
 
  do_message(npc, char, "It seems … he died.")
 
Currently on tmwserv:
 
...
 
==== Displaying dialogue options ====
Currently on eAthena:
 
  mes "It seems Maji Chan is waiting for an answer...";
next;
   
   
  -- 3. Parenthetically offset text
  menu
do_message(npc, char, "By this apple — and not any other — she will rule the world.")
"I'm fine!, thanks for asking.", L_a_good_option,
"...", -, // Continue after the menu
"Quite well, and you?", L_another_good_option;
   
   
  -- 4. Ranges
  mes "[Maji Chan]";
do_message(npc, char, "Lately the Tulimshar–Hurnscald highway is rather non-lethal.")
  mes "\"\You could at least say something!\"";
  do_message(npc, char, "“Give me 100–200 itens, pliz!”")
close;


=== Quotes ===
Currently on tmwserv:
* Use \" for direct speech.
** For the double quotation mark not to interfere with the scripting code, a backslash needs to be prepended it.
* Contractions and quotes within the direct speech use the single quote '.


// Quote example
...
mes "<span style="color:green;">\"</span>Ah, Agostine! The <span style="color:green;">'legendary tailor'</span>!<span style="color:green;">\"</span>";
mes "<span style="color:green;">\"</span>Aw, you <span style="color:green;">don't</span> have enough gold on you!<span style="color:green;">\"</span>";


=== Text formatting ===
==== Variable dialogue options ====
* Item and monster names, please use the names in the way shown by the client (e.g., Black Scorpion, Bottle of Sand) outside direct speech in the dialogues.
Currently on eAthena (easy but quickly unwieldy solution):
* Emphasis may be formatted with capital letters, use it sparingly.
* Actions may be put inside asterisks, use it sparingly.


  // Formatting example
  set @variable = 108;
  mes "\"I was fighting <span style="color:green;">scorpions</span> for experience and I bumped into a <span style="color:green;">RED</span> one.\"";
mes "\"I fought, of course! It hit me here <span style="color:green;">*points at a bruise at his shoulder*</span>.\"";
if (@variable < 100)
  menu
"Ye olde dialogue option.", L_usual_option,
"Good bye!", -;
if (@variable >= 100)
menu
"Ye olde dialogue option.", L_usual_option,
"A new exciting option!", L_ohhhh,
"Good bye!", -;
close;
 
Currently on eAthena (more complex solution):


== Scripting style ==
...
Should in general follow the [[Hacking#Coding_style_guidelines|coding style guidelines]].


=== Comments ===
Currently on tmwserv:
* Each file should begin with a comment block describing the scope and use of the file.
** <span style="color:red;">Put a template here?</span>


=== Indentation ===
...
* All indentations are made with tabs, one for each indentation level.
* Labels use no indentations at all.
* Menus have all their options on their own lines, and indented one level.
* <span style="color:red;">If clauses...</span>


// Indentation example
=== Starting a script from scratch ===
L_label:
...
mes "What do you want to do?";
next;
menu
"Spend money", -,
"Script a fun quest", L_good_choice;
close;


=== Blocks of code ===
== See also ==
* Code blocks should be separated from each other in a dinstinct way; the best way of doing it is to insert a blank line between code blocks.
* [[Scripting|Script bindings]] — things we currently can access through scripts
* Do not add blank lines within individual blocks.
* [[User:Crush/Scripting|Script bindings to do]] — things we should be able to access through scripts... in time
* The opening brackets should be at the end of the parent line, not in a new line; the closing ones should be on a line of their own.
* [http://gitorious.org/tmwserv-data/mainline/blobs/raw/master/scripts/test.lua Current tmwserv script example]
* [[eAthena Scripting Standards|eAthena scripting standards]] — scripting on the old eA server software

Revision as of 08:03, 28 September 2009

Current and proposed practice

In my mind a scripting language should be simple to both understand and use. You should not need to be a C++/Lua hacker to be able to create a dialogue menu where some replies depends on certain circumstances. Here follows a few suggestions how the tmwserv Lua scripting could look.

NPC dialogue

Currently on eAthena:

// A comment!

mes "[Maji Chan]";
mes "\"How do you do my dear quester?\"";
next;

Currently on tmwserv:

-- A comment!

do_message(npc, char, "“How do you do my dear quester?”")

Which is quite unwieldy. When scripting you most often only have the NPC say something to the player, so this could be simplified a fair bit to something like:

-- A comment!

message("“How do you do my dear quester?”")

I would actually propose to gettext-ize it:

-- A comment!

message(_("“How do you do my dear quester?”"))

Using variables

Currently on eAthena:

set @variable_1 = 42; // numeral variable for the local script
set @variable_2$ = "Bottle of Sand"; // string variable for the local script

mes "\"Did you bring " + @variable_1 + " [" + @variable_2$ + "]?\"";


Currently on tmwserv:

...

Displaying dialogue options

Currently on eAthena:

mes "It seems Maji Chan is waiting for an answer...";
next;

menu
	"I'm fine!, thanks for asking.", L_a_good_option,
	"...", -, // Continue after the menu
	"Quite well, and you?", L_another_good_option;

mes "[Maji Chan]";
mes "\"\You could at least say something!\"";
close;

Currently on tmwserv:

...

Variable dialogue options

Currently on eAthena (easy but quickly unwieldy solution):

set @variable = 108;

if (@variable < 100)
	menu
		"Ye olde dialogue option.", L_usual_option,
		"Good bye!", -;

if (@variable >= 100)
	menu
		"Ye olde dialogue option.", L_usual_option,
		"A new exciting option!", L_ohhhh,
		"Good bye!", -;

close;

Currently on eAthena (more complex solution):

...

Currently on tmwserv:

...

Starting a script from scratch

...

See also