Difference between revisions of "Scripting"

From Wolfire Games Wiki
Jump to: navigation, search
(Added script documentation path for Linux.)
 
(19 intermediate revisions by 6 users not shown)
Line 1: Line 1:
Overgrowth is using AngelScript as its core scripting language. The best AngelScript reference is here: [http://www.angelcode.com/angelscript/sdk/docs/manual/index.html]
+
Overgrowth uses [http://www.angelcode.com/angelscript/ AngelScript] as its core '''scripting''' language. The [http://www.angelcode.com/angelscript/sdk/docs/manual/index.html AngelScript Manual] is the best place to start learning.
  
 +
As of Alpha 209, the game automatically generates a header file showing all the parameters that are exposed to the scripting layer, including comments and parameter names. This file is named aschar_docs.h and can be found
  
 +
'''in Windows'''
 +
*under ~\Documents\Wolfire\Overgrowth
  
Checking for Keypresses:
+
'''in Mac OSX'''
 +
*under ~/Library/Application\ Support/Overgrowth
  
 +
'''in Linux'''
 +
*under ~/.local/share/Overgrowth
 +
 +
http://blog.wolfire.com/2015/02/Overgrowth-a209-video-changelog
 +
 +
 +
==File Locations==
 +
 +
===OSX===
 +
 +
Overgrowth comes as an Application Package. Within this package are folders, which can be navigated by first right-clicking on Overgrowth.app in the Finder and selecting "Show Package Contents" from the contextual menu. To access the scripting files, navigate to
 +
 +
<pre>Overgrowth/Contents/Mac\ OS/Data/Scripts/</pre>
 +
 +
===Windows===
 +
{{stub}}
 +
===Linux===
 +
{{stub}}
 +
 +
In these locations you will see various files, many of which have the suffix '''.as''', for AngelScript (also for ActionScript, but that's another story). They can be opened and edited with your favorite text editor. Any changes made while the game is running will be updated in real time. Be sure to make backups!
 +
 +
==General Usage Scenarios==
 +
=== Checking for User Input: ===
 
You can check for keypresses by using the '''boolean''' check function '''GetInputDown()''':
 
You can check for keypresses by using the '''boolean''' check function '''GetInputDown()''':
  
 
Syntax examples:
 
Syntax examples:
 
 
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
 
|-
 
|-
Line 22: Line 48:
  
  
The following controls are designed to be relative to the player's preferences and are given a binding in the config.txt file.
+
The following controls are designed to be relative to the player's preferences and are given a binding in the [[config.txt|config.txt]] file.
  
 
'''Config.txt Dependent References'''
 
'''Config.txt Dependent References'''
Line 55: Line 81:
 
|  jump
 
|  jump
 
|}
 
|}
 +
 +
 +
'''Mouse Input'''
 +
{| class="wikitable" border="1"
 +
|-
 +
!  Mouse Button
 +
!  Scripting Reference Name
 +
|-
 +
|  Left Mouse Button
 +
|  attack
 +
|-
 +
|  Right Mouse Button
 +
|  grab
 +
|}
 +
  
 
'''Generic Key References'''
 
'''Generic Key References'''
  
Anything you see between quotes is a valid scripting reference tag.  You are looking at the keyTranslator.h file which literally interprets scripting key calls and returns their SDLK counterparts.
+
Here is a complete list of scripting tags for key presses:
  
 +
----
 +
<div style="column-count:7;-moz-column-count:7;-webkit-column-count:7">
 +
: backspace
 +
: tab
 +
: clear
 +
: return
 +
: pause
 +
: esc
 +
: space
 +
: !
 +
: "
 +
: #
 +
: $
 +
: &
 +
: '
 +
: (
 +
: )
 +
: *
 +
: +
 +
: ,
 +
: -
 +
: .
 +
: /
 +
: 0
 +
: 1
 +
: 2
 +
: 3
 +
: 4
 +
: 5
 +
: 6
 +
: 7
 +
: 8
 +
: 9
 +
: :
 +
: ;
 +
: <
 +
: =
 +
: >
 +
: ?
 +
: @
 +
: [
 +
: \
 +
: ]
 +
: ^
 +
: _
 +
: `
 +
: a
 +
: b
 +
: c
 +
: d
 +
: e
 +
: f
 +
: g
 +
: h
 +
: i
 +
: j
 +
: k
 +
: l
 +
: m
 +
: n
 +
: o
 +
: p
 +
: q
 +
: r
 +
: s
 +
: t
 +
: u
 +
: v
 +
: w
 +
: x
 +
: y
 +
: z
 +
: delete
 +
: keypad0
 +
: keypad1
 +
: keypad2
 +
: keypad3
 +
: keypad4
 +
: keypad5
 +
: keypad6
 +
: keypad7
 +
: keypad8
 +
: keypad9
 +
: keypad.
 +
: keypad/
 +
: keypad*
 +
: keypad-
 +
: keypad+
 +
: keypadenter
 +
: keypad=
 +
: up
 +
: down
 +
: right
 +
: left
 +
: insert
 +
: home
 +
: end
 +
: pageup
 +
: pagedown
 +
: f1
 +
: f2
 +
: f3
 +
: f4
 +
: f5
 +
: f6
 +
: f7
 +
: f8
 +
: f9
 +
: f10
 +
: f11
 +
: f12
 +
: f13
 +
: f14
 +
: f15
 +
: numlock
 +
: capslock
 +
: scrollock
 +
: rshift
 +
: lshift
 +
: rctrl
 +
: lctrl
 +
: ralt
 +
: lalt
 +
: rmeta
 +
: lmeta
 +
: lsuper
 +
: rsuper
 +
: mode
 +
: compose
 +
: help
 +
: print
 +
: sysreq
 +
: break
 +
: menu
 +
: power
 +
: euro
 +
</div>
 +
----
 +
[[Category:Overgrowth]]
 +
 +
=== Writing classes and functions in your own script: ===
 +
Scripts can be written outside of the game code, and interact with it using objects and function calls. These do not need to be written as classes and could be simple functions. A simple class might look like this:
 
<pre>
 
<pre>
#include "keyTranslator.h"
+
class Example {
3       
+
    int example_variable; // Variables cannot be initialized here
4        SDLKey keyToSDL(const std::string &s)
+
 
5        {
+
    Example() {
6                if (s == "backspace")
+
        example_variable = 1;
7                        return SDLK_BACKSPACE;
+
        print_var();
8                if (s == "tab")
+
    }
9                        return SDLK_TAB;
+
 
10                if (s == "clear")
+
    void print_var() {
11                        return SDLK_CLEAR;
+
        Print(example_variable);
12                if (s == "return")
+
    }
13                        return SDLK_RETURN;
+
};
14                if (s == "pause")
+
 
15                        return SDLK_PAUSE;
+
// Initialize a class that the game can use
16                if (s == "esc")
+
Example ex1 = Example();
17                        return SDLK_ESCAPE;
+
ex1.example_variable = 2;
18                if (s == "space")
+
ex1.print_var();
19                        return SDLK_SPACE;
 
20                if (s == "!")
 
21                        return SDLK_EXCLAIM;
 
22                if (s == "\"")
 
23                        return SDLK_QUOTEDBL;
 
24                if (s == "#")
 
25                        return SDLK_HASH;
 
26                if (s == "$")
 
27                        return SDLK_DOLLAR;
 
28                if (s == "&")
 
29                        return SDLK_AMPERSAND;
 
30                if (s == "\'")
 
31                        return SDLK_QUOTE;
 
32                if (s == "(")
 
33                        return SDLK_LEFTPAREN;
 
34                if (s == ")")
 
35                        return SDLK_RIGHTPAREN;
 
36                if (s == "*")
 
37                        return SDLK_ASTERISK;
 
38                if (s == "+")
 
39                        return SDLK_PLUS;
 
40                if (s == ",")
 
41                        return SDLK_COMMA;
 
42                if (s == "-")
 
43                        return SDLK_MINUS;
 
44                if (s == ".")
 
45                        return SDLK_PERIOD;
 
46                if (s == "/")
 
47                        return SDLK_SLASH;
 
48                if (s == "0")
 
49                        return SDLK_0;
 
50                if (s == "1")
 
51                        return SDLK_1;
 
52                if (s == "2")
 
53                        return SDLK_2;
 
54                if (s == "3")
 
55                        return SDLK_3;
 
56                if (s == "4")
 
57                        return SDLK_4;
 
58                if (s == "5")
 
59                        return SDLK_5;
 
60                if (s == "6")
 
61                        return SDLK_6;
 
62                if (s == "7")
 
63                        return SDLK_7;
 
64                if (s == "8")
 
65                        return SDLK_8;
 
66                if (s == "9")
 
67                        return SDLK_9;
 
68                if (s == ":")
 
69                        return SDLK_COLON;
 
70                if (s == ";")
 
71                        return SDLK_SEMICOLON;
 
72                if (s == "<")
 
73                        return SDLK_LESS;
 
74                if (s == "=")
 
75                        return SDLK_EQUALS;
 
76                if (s == ">")
 
77                        return SDLK_GREATER;
 
78                if (s == "?")
 
79                        return SDLK_QUESTION;
 
80                if (s == "@")
 
81                        return SDLK_AT;
 
82                if (s == "[")
 
83                        return SDLK_LEFTBRACKET;
 
84                if (s == "\\")
 
85                        return SDLK_BACKSLASH;
 
86                if (s == "]")
 
87                        return SDLK_RIGHTBRACKET;
 
88                if (s == "^")
 
89                        return SDLK_CARET;
 
90                if (s == "_")
 
91                        return SDLK_UNDERSCORE;
 
92                if (s == "`")
 
93                        return SDLK_BACKQUOTE;
 
94                if (s == "a")
 
95                        return SDLK_a;
 
96                if (s == "b")
 
97                        return SDLK_b;
 
98                if (s == "c")
 
99                        return SDLK_c;
 
100                if (s == "d")
 
101                        return SDLK_d;
 
102                if (s == "e")
 
103                        return SDLK_e;
 
104                if (s == "f")
 
105                        return SDLK_f;
 
106                if (s == "g")
 
107                        return SDLK_g;
 
108                if (s == "h")
 
109                        return SDLK_h;
 
110                if (s == "i")
 
111                        return SDLK_i;
 
112                if (s == "j")
 
113                        return SDLK_j;
 
114                if (s == "k")
 
115                        return SDLK_k;
 
116                if (s == "l")
 
117                        return SDLK_l;
 
118                if (s == "m")
 
119                        return SDLK_m;
 
120                if (s == "n")
 
121                        return SDLK_n;
 
122                if (s == "o")
 
123                        return SDLK_o;
 
124                if (s == "p")
 
125                        return SDLK_p;
 
126                if (s == "q")
 
127                        return SDLK_q;
 
128                if (s == "r")
 
129                        return SDLK_r;
 
130                if (s == "s")
 
131                        return SDLK_s;
 
132                if (s == "t")
 
133                        return SDLK_t;
 
134                if (s == "u")
 
135                        return SDLK_u;
 
136                if (s == "v")
 
137                        return SDLK_v;
 
138                if (s == "w")
 
139                        return SDLK_w;
 
140                if (s == "x")
 
141                        return SDLK_x;
 
142                if (s == "y")
 
143                        return SDLK_y;
 
144                if (s == "z")
 
145                        return SDLK_z;
 
146                if (s == "delete")
 
147                        return SDLK_DELETE;
 
148                if (s == "keypad0")
 
149                        return SDLK_KP0;
 
150                if (s == "keypad1")
 
151                        return SDLK_KP1;
 
152                if (s == "keypad2")
 
153                        return SDLK_KP2;
 
154                if (s == "keypad3")
 
155                        return SDLK_KP3;
 
156                if (s == "keypad4")
 
157                        return SDLK_KP4;
 
158                if (s == "keypad5")
 
159                        return SDLK_KP5;
 
160                if (s == "keypad6")
 
161                        return SDLK_KP6;
 
162                if (s == "keypad7")
 
163                        return SDLK_KP7;
 
164                if (s == "keypad8")
 
165                        return SDLK_KP8;
 
166                if (s == "keypad9")
 
167                        return SDLK_KP9;
 
168                if (s == "keypad.")
 
169                        return SDLK_KP_PERIOD;
 
170                if (s == "keypad/")
 
171                        return SDLK_KP_DIVIDE;
 
172                if (s == "keypad*")
 
173                        return SDLK_KP_MULTIPLY;
 
174                if (s == "keypad-")
 
175                        return SDLK_KP_MINUS;
 
176                if (s == "keypad+")
 
177                        return SDLK_KP_PLUS;
 
178                if (s == "keypadenter")
 
179                        return SDLK_KP_ENTER;
 
180                if (s == "keypad=")
 
181                        return SDLK_KP_EQUALS;
 
182                if (s == "up")
 
183                        return SDLK_UP;
 
184                if (s == "down")
 
185                        return SDLK_DOWN;
 
186                if (s == "right")
 
187                        return SDLK_RIGHT;
 
188                if (s == "left")
 
189                        return SDLK_LEFT;
 
190                if (s == "insert")
 
191                        return SDLK_INSERT;
 
192                if (s == "home")
 
193                        return SDLK_HOME;
 
194                if (s == "end")
 
195                        return SDLK_END;
 
196                if (s == "pageup")
 
197                        return SDLK_PAGEUP;
 
198                if (s == "pagedown")
 
199                        return SDLK_PAGEDOWN;
 
200                if (s == "f1")
 
201                        return SDLK_F1;
 
202                if (s == "f2")
 
203                        return SDLK_F2;
 
204                if (s == "f3")
 
205                        return SDLK_F3;
 
206                if (s == "f4")
 
207                        return SDLK_F4;
 
208                if (s == "f5")
 
209                        return SDLK_F5;
 
210                if (s == "f6")
 
211                        return SDLK_F6;
 
212                if (s == "f7")
 
213                        return SDLK_F7;
 
214                if (s == "f8")
 
215                        return SDLK_F8;
 
216                if (s == "f9")
 
217                        return SDLK_F9;
 
218                if (s == "f10")
 
219                        return SDLK_F10;
 
220                if (s == "f11")
 
221                        return SDLK_F11;
 
222                if (s == "f12")
 
223                        return SDLK_F12;
 
224                if (s == "f13")
 
225                        return SDLK_F13;
 
226                if (s == "f14")
 
227                        return SDLK_F14;
 
228                if (s == "f15")
 
229                        return SDLK_F15;
 
230                if (s == "numlock")
 
231                        return SDLK_NUMLOCK;
 
232                if (s == "capslock")
 
233                        return SDLK_CAPSLOCK;
 
234                if (s == "scrollock")
 
235                        return SDLK_SCROLLOCK;
 
236                if (s == "rshift")
 
237                        return SDLK_RSHIFT;
 
238                if (s == "lshift")
 
239                        return SDLK_LSHIFT;
 
240                if (s == "rctrl")
 
241                        return SDLK_RCTRL;
 
242                if (s == "lctrl")
 
243                        return SDLK_LCTRL;
 
244                if (s == "ralt")
 
245                        return SDLK_RALT;
 
246                if (s == "lalt")
 
247                        return SDLK_LALT;
 
248                if (s == "rmeta")
 
249                        return SDLK_RMETA;
 
250                if (s == "lmeta")
 
251                        return SDLK_LMETA;
 
252                if (s == "lsuper")
 
253                        return SDLK_LSUPER;
 
254                if (s == "rsuper")
 
255                        return SDLK_RSUPER;
 
256                if (s == "mode")
 
257                        return SDLK_MODE;
 
258                if (s == "compose")
 
259                        return SDLK_COMPOSE;
 
260                if (s == "help")
 
261                        return SDLK_HELP;
 
262                if (s == "print")
 
263                        return SDLK_PRINT;
 
264                if (s == "sysreq")
 
265                        return SDLK_SYSREQ;
 
266                if (s == "break")
 
267                        return SDLK_BREAK;
 
268                if (s == "menu")
 
269                        return SDLK_MENU;
 
270                if (s == "power")
 
271                        return SDLK_POWER;
 
272                if (s == "euro")
 
273                        return SDLK_EURO;
 
274       
 
275                return (SDLKey)SDLK_SYSREQ;
 
276        }
 
 
</pre>
 
</pre>
 +
This script could be included in any of those in Data/Scripts, by writing <code>#include "path_to_script.as"</code>, where <code>path_to_script</code> would just be your script name if it were in the scripts folder.
  
 +
It can then be used to create new classes, or use ones defined in your script.
  
 
+
Writing you scripts separate from the game files makes your code easier to develop and update!
[[Category:Overgrowth]]
 

Latest revision as of 11:29, 7 September 2015

Overgrowth uses AngelScript as its core scripting language. The AngelScript Manual is the best place to start learning.

As of Alpha 209, the game automatically generates a header file showing all the parameters that are exposed to the scripting layer, including comments and parameter names. This file is named aschar_docs.h and can be found

in Windows

  • under ~\Documents\Wolfire\Overgrowth

in Mac OSX

  • under ~/Library/Application\ Support/Overgrowth

in Linux

  • under ~/.local/share/Overgrowth

http://blog.wolfire.com/2015/02/Overgrowth-a209-video-changelog


File Locations

OSX

Overgrowth comes as an Application Package. Within this package are folders, which can be navigated by first right-clicking on Overgrowth.app in the Finder and selecting "Show Package Contents" from the contextual menu. To access the scripting files, navigate to

Overgrowth/Contents/Mac\ OS/Data/Scripts/

Windows

This article is a stub. You should help Wolfire by expanding it.

Linux

This article is a stub. You should help Wolfire by expanding it.

In these locations you will see various files, many of which have the suffix .as, for AngelScript (also for ActionScript, but that's another story). They can be opened and edited with your favorite text editor. Any changes made while the game is running will be updated in real time. Be sure to make backups!

General Usage Scenarios

Checking for User Input:

You can check for keypresses by using the boolean check function GetInputDown():

Syntax examples:

GetInputDown("a") returns true if the 'a' key is being pressed, returns false if not
GetInputDown("attack") returns true if the left mouse button is being pressed, returns false if not
GetInputDown("move_left") returns true if the "left key" is being pressed, returns false if not (by default this key is defined in the config.txt to be the 'a' key)


The following controls are designed to be relative to the player's preferences and are given a binding in the config.txt file.

Config.txt Dependent References

Predefined Term Default binding in Config.txt Scripting Reference Name
Left Key a move_left
Right Key d move_right
Up Key w move_up
Down Key s move_down
Crouch Key left shift crouch
Jump Key space jump


Mouse Input

Mouse Button Scripting Reference Name
Left Mouse Button attack
Right Mouse Button grab


Generic Key References

Here is a complete list of scripting tags for key presses:


backspace
tab
clear
return
pause
esc
space
 !
"
#
$
&
'
(
)
*
+
,
-
.
/
0
1
2
3
4
5
6
7
8
9
 :
 ;
<
=
>
 ?
@
[
\
]
^
_
`
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
delete
keypad0
keypad1
keypad2
keypad3
keypad4
keypad5
keypad6
keypad7
keypad8
keypad9
keypad.
keypad/
keypad*
keypad-
keypad+
keypadenter
keypad=
up
down
right
left
insert
home
end
pageup
pagedown
f1
f2
f3
f4
f5
f6
f7
f8
f9
f10
f11
f12
f13
f14
f15
numlock
capslock
scrollock
rshift
lshift
rctrl
lctrl
ralt
lalt
rmeta
lmeta
lsuper
rsuper
mode
compose
help
print
sysreq
break
menu
power
euro

Writing classes and functions in your own script:

Scripts can be written outside of the game code, and interact with it using objects and function calls. These do not need to be written as classes and could be simple functions. A simple class might look like this:

class Example {
    int example_variable; // Variables cannot be initialized here

    Example() {
        example_variable = 1;
        print_var();
    }

    void print_var() {
        Print(example_variable);
    }
};

// Initialize a class that the game can use
Example ex1 = Example();
ex1.example_variable = 2;
ex1.print_var();

This script could be included in any of those in Data/Scripts, by writing #include "path_to_script.as", where path_to_script would just be your script name if it were in the scripts folder.

It can then be used to create new classes, or use ones defined in your script.

Writing you scripts separate from the game files makes your code easier to develop and update!