Difference between revisions of "Scripting"

From Wolfire Games Wiki
Jump to: navigation, search
(Added script documentation path for Linux.)
 
(26 intermediate revisions by 7 users not shown)
Line 1: Line 1:
Overgrowth is using AngelScript as its core scripting language.  Resources for learning AngelScript can be found here:
+
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 15: Line 41:
 
|-
 
|-
 
|GetInputDown("attack")
 
|GetInputDown("attack")
|returns true if the mouse left key is being pressed, returns false if not
+
|returns true if the left mouse button is being pressed, returns false if not
 
|-
 
|-
 
|GetInputDown("move_left")
 
|GetInputDown("move_left")
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 56: Line 82:
 
|}
 
|}
  
'''Generic Key References'''
+
 
 +
'''Mouse Input'''
 
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
 
|-
 
|-
Desired Input Key
+
Mouse Button
!  Scripting Representation
+
!  Scripting Reference Name
 
|-
 
|-
left mouse button
+
Left Mouse Button
 
|  attack
 
|  attack
|-  
+
|-
right mouse button
+
Right Mouse Button
 
|  grab
 
|  grab
|-
 
|  a
 
|  a
 
|-
 
|  b
 
|  b
 
|-
 
|  c
 
|  c
 
|-
 
|  d
 
|  d
 
|-
 
|  e
 
|  e
 
|-
 
|  f
 
|  f
 
|-
 
|  g
 
|  g
 
|-
 
|  h
 
|  h
 
|-
 
|  i
 
|  i
 
|-
 
|  j
 
|  j
 
|-
 
|  k
 
|  k
 
|-
 
|  l
 
|  l
 
|-
 
|  m
 
|  m
 
|-
 
|  n
 
|  n
 
|-
 
|  o
 
|  o
 
|-
 
|  p
 
|  p
 
|-
 
|  q
 
|  q
 
|-
 
|  r
 
|  r
 
|-
 
|  s
 
|  s
 
|-
 
|  t
 
|  t
 
|-
 
|  u
 
|  u
 
|-
 
|  v
 
|  v
 
|-
 
|  w
 
|  w
 
|-
 
|  x
 
|  x
 
|-
 
|  y
 
|  y
 
|-
 
|  z
 
|  z
 
 
|}
 
|}
 +
 +
 +
'''Generic Key References'''
 +
 +
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>
 +
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();
 +
</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!

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!