Skip to content

Commit

Permalink
Convert some of the "Scripting" section pages to markdown
Browse files Browse the repository at this point in the history
this was done automatically with pandoc, page formatting may still be broken in some parts
  • Loading branch information
guilherme-gm committed Apr 11, 2024
1 parent c0994c5 commit adca37b
Show file tree
Hide file tree
Showing 15 changed files with 3,065 additions and 2,413 deletions.
399 changes: 228 additions & 171 deletions docs/scripting/basic-scripting.md

Large diffs are not rendered by default.

139 changes: 73 additions & 66 deletions docs/scripting/functions.md
Original file line number Diff line number Diff line change
@@ -1,109 +1,116 @@
== Why would a function be useful? ==
## Why would a function be useful?

A function is mainly a chunk of code that either is used for multiple actions of the same item, or a simple way to check the status of something. This eliminates lots of code from the main script and makes it a bit cleaner for you to see and debug.
A function is mainly a chunk of code that either is used for multiple actions of the same item, or a simple way to check
the status of something. This eliminates lots of code from the main script and makes it a bit cleaner for you to see and
debug.

== Creating a Function ==
## Creating a Function

In order to create a function, you can do one of many things. Many scripters place their functions in 1 of 2 locations. I, myself, place my functions in a functions.txt script file and load that independently. By doing this, you can organize your functions and keep all your other scripts clean and free of clutter. Another method is to simply place them inside the script itself, however, I find this to lengthen the script quite a bit, and makes it complicated to find where the function is located in case another script file is calling it.
In order to create a function, you can do one of many things. Many scripters place their functions in 1 of 2 locations.
I, myself, place my functions in a functions.txt script file and load that independently. By doing this, you can
organize your functions and keep all your other scripts clean and free of clutter. Another method is to simply place
them inside the script itself, however, I find this to lengthen the script quite a bit, and makes it complicated to find
where the function is located in case another script file is calling it.

<pre>function(TAB)script(TAB)name(TAB){
// code
}</pre>


== The RETURN Command ==
function(TAB)script(TAB)name(TAB){
// code
}

Sometimes it's necessary to send back information that you retrieved from your function. Such as a TRUE/FALSE 0/1 response, or sometimes even more. In order to do this, your function needs a return statement.
## The RETURN Command

<pre>return <Value>;
return <Variable>;</pre>
Sometimes it's necessary to send back information that you retrieved from your function. Such as a TRUE/FALSE 0/1
response, or sometimes even more. In order to do this, your function needs a return statement.

return <Value>;
return <Variable>;

== Calling a Function ==
## Calling a Function

There are a few ways to call functions, depends on what information you are retrieving.

<pre>callfunc "MyFunction";</pre> // Simply calls the function that does not use a RETURN command
callfunc "MyFunction";

=== Using Arguments in a Function ===
// Simply calls the function that does not use a RETURN command

Sometimes it's helpful to pass variables or values to a function in order to retrieve the information that you would like. These values are called arguments. Many people use these in order to make calculations.
### Using Arguments in a Function

==== The Function ====
Sometimes it's helpful to pass variables or values to a function in order to retrieve the information that you would
like. These values are called arguments. Many people use these in order to make calculations.

<pre>function(TAB)script(TAB)calc(TAB){
set @a, getarg(0) + getarg(1);
return @a;
}</pre>
#### The Function

function(TAB)script(TAB)calc(TAB){
set @a, getarg(0) + getarg(1);
return @a;
}

#### Calling the Function

==== Calling the Function ====
set @a, callfunc("calc",1,2)
mes @a;

<pre>set @a, callfunc("calc",1,2)
mes @a;</pre>
#### The Result/Return

==== The Result/Return ====
3

<pre>3</pre>
#### Passing Arrays as Arguments

==== Passing Arrays as Arguments ====
Calling the Function:

Calling the Function:
<pre>callfunc "calc", MyArrayName;</pre>
callfunc "calc", MyArrayName;

The Function:
<pre>function(TAB)script(TAB)calc(TAB){
getelementofarray(getarg(0), 1);
}
</pre>

* Please note, that npc variable arrays will not function in the same manner (this will be updated at a later date)
function(TAB)script(TAB)calc(TAB){
getelementofarray(getarg(0), 1);
}

- Please note, that npc variable arrays will not function in the same manner (this will be updated at a later date)

==== Calling Function as a Script Command ====
#### Calling Function as a Script Command

<pre>
prontera,150,150,5<TAB>script<TAB>Calculator<TAB>999,{
prontera,150,150,5<TAB>script<TAB>Calculator<TAB>999,{

function<TAB>Add<TAB>{
return (getarg(0)+getarg(1));
}
function<TAB>Add<TAB>{
return (getarg(0)+getarg(1));
}

mes Add(1,2);
}
</pre>
mes Add(1,2);
}

=== Special Notes ===
### Special Notes

Variables are passed to functions by reference

This means that you can do normal variable operations on a variable reference returned by getarg.

Ex:

<pre>function<tab>script<tab>F_Increment<tab>-1,{
// getarg(0) returns a reference to the .@num variable in NPC_Test
// NOTE: you can't use .@num directly, it's a different variable from the .@num in NPC_Test
set getarg(0), getarg(0) + 1;
return;
}

prontera,156,156,4<tab>script<tab>NPC_Test<tab>56,{
// initial number
set .@num, 123;
mes .@num;

// increment inside the function
callfunc("F_Increment", .@num);
mes .@num;

close;
}</pre>
function<tab>script<tab>F_Increment<tab>-1,{
// getarg(0) returns a reference to the .@num variable in NPC_Test
// NOTE: you can't use .@num directly, it's a different variable from the .@num in NPC_Test
set getarg(0), getarg(0) + 1;
return;
}

prontera,156,156,4<tab>script<tab>NPC_Test<tab>56,{
// initial number
set .@num, 123;
mes .@num;
// increment inside the function
callfunc("F_Increment", .@num);
mes .@num;
close;
}

Operators always return values, so this would provoke an error on the set inside F_Increment:

<pre>callfunc("F_Increment", .@num + 1);</pre>
callfunc("F_Increment", .@num + 1);

It's important to note the difference between the reference of the variable and the value of the variable:

* ''reference'' : the variable itself. It knows it's name, value and index. The type of variable is determined from the name.
* ''value'': the value of the variable (string or number).
- *reference* : the variable itself. It knows it's name, value and index. The type of variable is determined from the
name.
- *value*: the value of the variable (string or number).
72 changes: 44 additions & 28 deletions docs/scripting/index.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,71 @@
# Scripting

All pages that specifically related to the '''Scripting''' goes in this Category Page.
All pages that specifically related to the **Scripting** goes in this Category Page.

Articles will cover the following topics Map Flags, Permanent Monster Spawns, Non Playable Characters, Warp Points, Shops, and Functions.
Articles will cover the following topics Map Flags, Permanent Monster Spawns, Non Playable Characters, Warp Points,
Shops, and Functions.

All articles related to scripting can be found alphabetically [[:Category:Scripting]]
All articles related to scripting can be found alphabetically [:Category:Scripting](:Category:Scripting "wikilink")

## General

== General ==
Articles in this category are mainly written to create or improve your foundations on Scripting.

More Information:
* [[Adding_a_Script|[Tutorial] Add a Script]]
* [[Basic_Scripting|[Tutorial] NPC Scripting (Basics)]]
* [[Overview_of_Errors|NPC Errors]]
* [[Tips_and_Tricks_(Scripting)|Tips and Tricks]]

== Map Flags ==
A Map Flag describes restriction, property, and behavior of a certain map. The map flags alter the behavior of the map regarding teleporting, storing location when disconnected, dead branch usage, penalties upon death, PVP behavior, WoE behavior, ability to use skills or open up trade deals ,current weather effects, and whether day/night will be in effect on this map. Articles about Map Flags are placed under this category...
- \[\[Adding_a_Script\|\[Tutorial\] Add a Script\]\]
- \[\[Basic_Scripting\|\[Tutorial\] NPC Scripting (Basics)\]\]
- [NPC Errors](Overview_of_Errors "wikilink")
- [Tips and Tricks](Tips_and_Tricks_(Scripting) "wikilink")

Read more at [[Mapflag|Map Flags]]
## Map Flags

A Map Flag describes restriction, property, and behavior of a certain map. The map flags alter the behavior of the map
regarding teleporting, storing location when disconnected, dead branch usage, penalties upon death, PVP behavior, WoE
behavior, ability to use skills or open up trade deals ,current weather effects, and whether day/night will be in effect
on this map. Articles about Map Flags are placed under this category...

Read more at [Map Flags](Mapflag "wikilink")

## Monster Spawns

== Monster Spawns ==
In Depth articles that are related to Monster Spawns can be found under this category.

* [[Permanent_Monster_Spawn|Permanent Monster Spawns]]
- [Permanent Monster Spawns](Permanent_Monster_Spawn "wikilink")

## Non Playable Character

== Non Playable Character ==
In Depth articles that are related to NPC Scripting can all be found under this category.

More Information
* [[Loops|NPC Loops]]
* [[Timers (Scripting)|NPC Timers]]
* [[Variables|NPC Variables]]
* [[Menus|NPC Menus]]

== Warp Points ==
- [NPC Loops](Loops "wikilink")
- [NPC Timers](Timers_(Scripting) "wikilink")
- [NPC Variables](Variables "wikilink")
- [NPC Menus](Menus "wikilink")

## Warp Points

In Depth articles related to Warp Points are listed in this category
* [[Defining_Warp_Points|Defining a warp point]]

== Shops ==
- [Defining a warp point](Defining_Warp_Points "wikilink")

## Shops

Articles about Shops and Cash Shops are placed under this category.
* [[General Shop creation]]

== Functions ==
- [General Shop creation](General_Shop_creation "wikilink")

## Functions

In Depth articles that are related to Functions can all be found under this category.
* [[Functions|How functions work]]
* [[WoE|Functions used in WoE]]

== Help Expand This Section ==
- [How functions work](Functions "wikilink")
- [Functions used in WoE](WoE "wikilink")

## Help Expand This Section

Help minimize the broadness of Scripting by helping create or expand the following pages

* [[Basic Scripting]]
* [[Binaries|Binary Variable System]]
- [Basic Scripting](Basic_Scripting "wikilink")
- [Binary Variable System](Binaries "wikilink")
Loading

0 comments on commit adca37b

Please sign in to comment.