<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
	<title><![CDATA[Mumbles' Mumbles]]></title>
	<link>http://herc.ws/board/blog/14-mumbles-mumbles/</link>
	<description><![CDATA[Mumbles' Mumbles Syndication]]></description>
	<pubDate>Sun, 17 Jan 2016 01:15:41 +0000</pubDate>
	<webMaster>haru@dotalux.com (Hercules Board)</webMaster>
	<generator>IP.Blog</generator>
	<ttl>60</ttl>
	<item>
		<title>Crash Course: Scripting 101-B</title>
		<link>http://herc.ws/board/blog/14/entry-71-crash-course-scripting-101-b/</link>
		<category></category>
		<description><![CDATA[I know it's been a while, but hopefully I'll be pushing these out more frequently. This is a continuation to <strong class='bbc'><a href='http://herc.ws/board/blog/14/entry-55-crash-course-scripting-101-a/' class='bbc_url' title=''>Crash Course: Scripting 101-A</a></strong>, which I wrote back in November. Normally, I would have written it all in one huge post; however, due to complications with our forum software deleting my original post twice, I decided to break down the course in parts. This format should help me space out the time between posts, and focus more intensively on specific areas that might otherwise be undermined.<br /><br />Anyway, let's get on with it, shall we?<br /><br /><br /><strong class='bbc'><span style='font-size: 36px;'>III: Expressions</span></strong><br />Logical expressions are often used in scripting to determine a set of rules or prerequisites for a specific event or scenario to happen. These expressions can be used to determine numerous things during gameplay, and can be regularly found in quest NPCs or anything that works around special conditions in order to operate.<br /><br /><strong class='bbc'>Sample script:</strong><pre class='prettyprint lang-auto linenums:0'>
mes "&#91;Random Guy]";
mes "Hello there! What's your name?";
next;

input .@my_name$;

mes "&#91;Random Guy]";
if (strcharinfo(0) != .@my_name$) {
	mes "Well, that's odd! Your nametag...hey, come back here!";
} else {
	mes "That's a nice name you've got there!";
}

close;
</pre><br />Here's a situation where some fellow is asking for a player's name. Players are prompted with the <strong class='bbc'>input</strong> command, storing their answer in a temporary NPC string variable called <strong class='bbc'>.@my_name$</strong>. In the script, we present the player with a logical expression that determines whether or not they told us the truth by comparing <strong class='bbc'>strcharinfo(0)</strong> against <strong class='bbc'>.@my_name$</strong>:<pre class='prettyprint lang-auto linenums:0'>
if (strcharinfo(0) != .@my_name$) {
</pre><br />If the <strong class='bbc'>if</strong> expression is found to be <strong class='bbc'>true</strong>, the script will proceed to include the code within the curly braces <strong class='bbc'>{ }</strong> after the expression; otherwise, it will run the code in the curly braces after <strong class='bbc'>else </strong>in its place. However, no matter what message is displayed, a <strong class='bbc'>close</strong> will be executed afterwards, as it is impartial to the condition set by the <strong class='bbc'>if...else</strong> expression. Note that it is not required to use <strong class='bbc'>else</strong>, but it is useful when substituting text or code. Before we move onto the next section, here are some things you might find useful to know:<ul class='bbc'><li><a href='http://herc.ws/wiki/Strcharinfo' class='bbc_url' title=''><strong class='bbc'>strcharinfo(0)</strong></a> returns the name of the attached player in a string format; if a player's name is Player A, the name will be returned as <strong class='bbc'>"Player A"</strong>.</li><li><strong class='bbc'>strings</strong> are any sequence of characters (letters, numbers, and symbols) that are enclosed in quotation marks.</li></ul><br /><span style='font-size: 36px;'><strong class='bbc'>IV: Concatenation</strong></span><br />In formal language theory and computer programming, string concatenation is the operation of joining two character strings end-to-end; in English, this process is commonly known as "sequencing". In <em class='bbc'>*Athena</em> scripting, concatenation is used to piece words and information together dynamically - and by dynamically, I mean with the ability to change with little or no intervention from the scripter.<br /><br /><strong class='bbc'>Sample script:</strong><pre class='prettyprint lang-auto linenums:0'>
mes "&#91;Random Guy]";
mes "Hello there! What's your name?";
next;

input .@my_name$;

mes "&#91;Random Guy]";
if (strcharinfo(0) != .@my_name$) {
	mes "Well, that's odd! Your nametag doesn't say "+ .@my_name$ +"!";
} else {
	mes "That's a nice name you've got there, "+ strcharinfo(0) +"!";
}

close;
</pre><br />Let's use the script from earlier as an example. In order to concatenate a string, a plus sign <strong class='bbc'>+</strong> must trail a closing quotation mark, followed by the string you want to include. If the player input his name as Player B, <strong class='bbc'>.@my_name$</strong> will be the equivalent of <strong class='bbc'>"Player B"</strong> - quotation marks included. Comparatively, the message in the <strong class='bbc'>if </strong>expression would say:<pre class='prettyprint lang-auto linenums:0'>
mes "Well, that's odd! Your nametag doesn't say "+ "Player A" +"!";
</pre><br />Think of concatenating as adding onto an existing string using variables or functions. In this example, <strong class='bbc'>strcharinfo(0)</strong>, is being used to return the player's name as it is stored on the server; if the player's name is Player A, the function will return the string <strong class='bbc'>"Player A"</strong>. Always keep in mind that you are concatenating <strong class='bbc'>strings</strong>, which must be enclosed in quotation marks to be read by the script parser properly.]]></description>
		<pubDate>Tue, 28 Jan 2014 13:16:00 +0000</pubDate>
		<guid>http://herc.ws/board/blog/14/entry-71-crash-course-scripting-101-b/</guid>
	</item>
	<item>
		<title>Crash Course: Scripting 101-A</title>
		<link>http://herc.ws/board/blog/14/entry-55-crash-course-scripting-101-a/</link>
		<category></category>
		<description><![CDATA[<strong class='bbc'><span style='font-size: 36px;'>Prologue</span></strong><br />When I first got into <em class='bbc'>*Athena</em> scripting, it would have been a great convenience to have a decent guide, teacher, or even a friend to learn with. Back then, the documentation for script commands wasn't very good (not that it's anything glamourous now), people didn't have the patience to sit down and go over the basics, and my friends who were into computers/gaming had no interest in anything remotely related to programming.<br /><br />A lot has changed over the years, and it's been rather interesting to see myself push the limits of <em class='bbc'>*Athena</em> emulators through mere scripting; if you asked me to explain making source modifications for <em class='bbc'>*Athena</em> emulators, you'd hear me blabber things I learned in a C++ programming class I took over summer, and that's about as helpful as I can get - and <em class='bbc'>*Athena</em> emulators were written in C.<br /><br />But enough about me; let's get back to why you're here.<br /><br /><br /><strong class='bbc'><span style='font-size: 36px;'>I: Structure and Formatting</span></strong><br />In this section, we'll cover basic script structure and formatting.<br /><br /><strong class='bbc'>Sample script:</strong><pre class='prettyprint lang-auto linenums:0'>
prontera,144,174,3	script	Test NPC#prt::testnpc	4_M_MOCASS2,{
 
	mes "&#91;Test NPC]";
	mes "Text will be displayed here.";
	close;
	
}
</pre><br />Let's break this down, piece by piece:<pre class='prettyprint lang-auto linenums:0'>
prontera,144,174,3	script	Test NPC#prt::testnpc	4_M_MOCASS2,{</pre><br /><strong class='bbc'>Location</strong><br />Determine the location you would like your NPC to be on by moving to that area and typing '<em class='bbc'>/where</em>' in-game. If you would like your NPC to not have a physical location (known as a "floating" NPC), use a hyphen &lt;<strong class='bbc'>-</strong>&gt;.<br /><ul class='bbc'><li><strong class='bbc'>prontera</strong> - the name of the map which the NPC will be located</li><li><strong class='bbc'>144</strong> - the x-coordinate of the target cell the NPC will be placed upon</li><li><strong class='bbc'>174</strong> - the y-coordinate of the target cell the NPC will be placed upon</li><li><strong class='bbc'>3</strong> - the direction which the NPC will be facing</li></ul>Think of numerical directions as though you were looking at this grid:<pre class='prettyprint lang-auto linenums:0'>
&#91;1]&#91;0]&#91;7]
&#91;2]&nbsp;&nbsp; &#91;6]
&#91;3]&#91;4]&#91;5]</pre><br /><strong class='bbc'>Object</strong><br />Define the type of object you are writing, and its corresponding name(s).<br /><ul class='bbc'><li><strong class='bbc'>script</strong> - defines the object as an NPC script<br />
<ul class='bbc'><li>other objects include duplicates, shops, warps, mapflags, etc. - but we'll get into that later</li></ul></li><li><strong class='bbc'>Test NPC</strong> - the visible part of an NPC's display name; if no other names are given, this defaults as the NPC's unique name as well</li><li><strong class='bbc'>#prt</strong> - the hidden part of an NPC's display name, prefixed with a pound sign &lt;<strong class='bbc'>#</strong>&gt;; it serves as an identifier to distinguish duplicates</li><li><strong class='bbc'>::testnpc</strong> - the NPC's unique name, prefixed with two colons &lt;<strong class='bbc'>::</strong>&gt;; it is the name used when duplicating, warping to, or unloading NPCs</li><li><strong class='bbc'>4_M_MOCASS2</strong> - the NPC's sprite name constant which will be displayed; before <a href='https://github.com/HerculesWS/Hercules/commit/9f32aa958f86a228290c43544c8b9bbf3f1c2cc0' class='bbc_url' title='External link' rel='nofollow external'>9f32aa9</a>, this was commonly just the sprite ID<br />
<ul class='bbc'><li>Sprite IDs are still acceptable to use; if you want your NPC to be invisible, use <strong class='bbc'>-1</strong></li><li>A complete list of constants can be found in <a href='https://github.com/HerculesWS/Hercules/blob/master/db/const.txt' class='bbc_url' title='External link' rel='nofollow external'><strong class='bbc'>db/const.txt</strong></a></li></ul></li><li><strong class='bbc'>,{ </strong>- this is the opening brace (also known as a "curly"), prefixed with a comma &lt;<strong class='bbc'>,</strong>&gt;; it ends the header and indicates the beginning of the script<br />
<ul class='bbc'><li>A common mistake is to forget that comma - so don't forget!</li></ul></li></ul>Keep in mind that the whitespace in the header are actually tabs &lt;<strong class='bbc'>TAB</strong>&gt;, not spaces; the header will not be read properly if spaces are used.<br /><br /><strong class='bbc'>Scripting</strong><pre class='prettyprint lang-auto linenums:0'>
	mes "&#91;Test NPC]";
	mes "Text will be displayed here.";
	close;
</pre>Let's tell our script what we want our NPC to do; write out your script commands! A complete list of script commands can be found in <strong class='bbc'><a href='https://github.com/HerculesWS/Hercules/blob/master/doc/script_commands.txt' class='bbc_url' title='External link' rel='nofollow external'>doc/script_commands.txt</a></strong>.<ul class='bbc'><li><strong class='bbc'>mes</strong> - tells the script parser that we want to display a message in a dialogue box</li><li><strong class='bbc'>"</strong>[Test NPC]<strong class='bbc'>"</strong> - the NPC's name, enclosed in quotation marks &lt;<strong class='bbc'>"</strong>&gt;; quotation marks won't be displayed<br />
<ul class='bbc'><li>This is simply a vanity; an NPC name is not required, but it looks nice</li><li>Any text enclosed in quotation marks from a <strong class='bbc'>mes</strong> command will be displayed in a dialogue box</li></ul></li><li><strong class='bbc'>;</strong> - script commands <strong class='bbc'>MUST</strong> end with a semi-colon &lt;<strong class='bbc'>;</strong>&gt; to indicate the end of the command</li><li><strong class='bbc'>close</strong> - creates a close button and terminates the script once encountered<br />
<ul class='bbc'><li>Don't forget that trailing semi-colon; <strong class='bbc'>close</strong> is a command too!</li></ul></li></ul><strong class='bbc'>Indentation</strong><br />Like our header, the whitespace used to indent sections of our script are tabs, not spaces. Make a habit of indenting your script (especially if its nested/enclosed) with one tab; this improves readability and makes it easier for others to understand different sections of your script.<br /><br /><strong class='bbc'>End of Script</strong><br /><pre class='prettyprint lang-auto linenums:0'>
}</pre>The last thing you'll need to remember is to close that brace we opened earlier, when we wrote the header.<ul class='bbc'><li><strong class='bbc'>}</strong> - the closing brace, which is complementary to the opening brace in the header; it encloses the script and indicates the end of the file</li></ul>For the sake of practicing good scripting habits, always close your braces (and brackets, parentheses, etc.) first, before scripting anything; this will help prevent any enclosures from having stray/missing braces. Braces are also used in expressions, which is what we'll get into next.<br /><br /><br /><span style='font-size: 36px;'><strong class='bbc'>II: Variables</strong></span><br />As your scripts become more complex, you'll find yourself wanting ways to reduce repetitiveness and increase flexibility. Typing the same thing over and over again gets old fast; we can improve scripts by using variables to represent constant values within our script. Variables can also be used to represent temporary values within our script - or even permanent values that can be referred to by other scripts as well. Let's go over the various variable types and how we can use them. For the sake of shorthanding, let's name the example variable "<em class='bbc'>var</em>".<br /><br /><strong class='bbc'>Types</strong><br />There are two types of variables that determine what data can be stored in the variable.<ul class='bbc'><li>Integer variables are not postfixed with anything, and can only store numerical values<br />
<pre class='prettyprint lang-auto linenums:0'>var = 1;</pre></li><li>String variables are postfixed with a dollar &lt;<strong class='bbc'>$</strong>&gt; sign, and can store various letters, symbols, numerical values in the form of strings<br />
<pre class='prettyprint lang-auto linenums:0'>var$ = "Some string of letters (abc), symbols ($#) and numbers (123).";</pre></li></ul><strong class='bbc'>Extent</strong><br />Similar to a type, the extent of a variable indicates how long it can be used.<ul class='bbc'><li>Temporary variables are prefixed with an at &lt;<strong class='bbc'>@</strong>&gt; sign, and only last as long as the variable's scope will allow<br />
<pre class='prettyprint lang-auto linenums:0'>@var = 1;</pre></li><li>Permanent variables are not prefixed with anything other than their scope's prefix, and will last indefinitely unless they are cleared<br />
<pre class='prettyprint lang-auto linenums:0'>var = 1;</pre></li></ul><strong class='bbc'>Scopes</strong><br />Variables have different ranges that they can effect; known as "scopes", these determine what they can be used for. When a variable is "attached", it means that variable is stuck with its attachment wherever they go or are invoked.<ul class='bbc'><li>NPC<br />
NPC variables are prefixed with a period &lt;<strong class='bbc'>.</strong>&gt; and are attached to the invoking script; temporary NPC variables are cleared when the script ends</li><li><pre class='prettyprint lang-auto linenums:0'>.var = 1; // Permanent NPC variable</pre><pre class='prettyprint lang-auto linenums:0'>.@var = 1; // Temporary NPC variable</pre></li><li>Character<br />
Character variables are prefixed with nothing and are attached to the invoking player; temporary character variables are cleared when the player logs out<br />
<pre class='prettyprint lang-auto linenums:0'>var = 1; // Permanent character variable</pre><pre class='prettyprint lang-auto linenums:0'>@var = 1; // Temporary character variable</pre></li><li>Account<br />
Account variables are prefixed with a pound sign &lt;<strong class='bbc'>#</strong>&gt; and are attached to the invoking player's account; there is no temporary version of this scope<br />
<pre class='prettyprint lang-auto linenums:0'>#var = 1; // Permanent account variable</pre></li><li>Global Account<br />
Global account variables are prefixed with two pound signs &lt;<strong class='bbc'>##</strong>&gt; and are stored in the login server; the only differentiation this scope has from normal account variables is that global variables can be accessed across multiple character servers<br />
<pre class='prettyprint lang-auto linenums:0'>##var = 1; // Permanent global account variable</pre></li><li>Global<br />
Global variables are prefixed with a dollar sign &lt;<strong class='bbc'>$</strong>&gt; and can be accessed from any script; temporary global variables are cleared when the server is restarted<br />
<pre class='prettyprint lang-auto linenums:0'>$var = 1; // Permanent global variable</pre><pre class='prettyprint lang-auto linenums:0'>$@var = 1; // Temporary global variable</pre></li><li>Instance<br />
Instance variables are prefixed with an apostrophe &lt;<strong class='bbc'>'</strong>&gt; and are attached to the invoking party's instance; there is no temporary version of this scope<br />
<pre class='prettyprint lang-auto linenums:0'>'var = 1; // Permanent instance variable</pre></li></ul>Remember to only use variables in the scope in which they are needed. Review this section thoroughly until you no longer have to reference it; as we progressively move onto more complex scripts, you'll save much more time <em class='bbc'>knowing</em> the basics rather than having to review them constantly.]]></description>
		<pubDate>Tue, 12 Nov 2013 15:33:00 +0000</pubDate>
		<guid>http://herc.ws/board/blog/14/entry-55-crash-course-scripting-101-a/</guid>
	</item>
</channel>
</rss>