60 lines
3.5 KiB
Markdown
60 lines
3.5 KiB
Markdown
# Hashengine 2.2 Scripting documentation (EN)
|
|
|
|
Scripts in games made in Hashengine 2.2 have restricted access to the game.
|
|
this includes **HASHBASE**, **HASHGAME** and **SOUND**.
|
|
Note: the **print** function is redirected to an log function; all printed text is written into a file instead of stdout.
|
|
|
|
## HASHBASE
|
|
|
|
### **HASHBASE** gives access to the Hashengine module, it is intended to be used when creating **vector2** and **color3**.
|
|
|
|
vector2 describes an position in a game of Hashengine and to create an vector2 HASHBASE.vector2() should be used.
|
|
optional arguments are x and y. by default both are 0.
|
|
|
|
color3 describes an color, for either the foreground or background of an object.
|
|
to create an color HASHBASE.color3() should be used.
|
|
optional arguments are r, g and b. by default, all are 0.
|
|
|
|
To create objects in the game, use HASHBASE.obj().
|
|
No optional arguments.
|
|
|
|
events are used to execute one or more scripts when it is executed.
|
|
normal use cases of events are in objects._touched and all scripts attached to that event
|
|
get executed once that object is colliding with something.
|
|
to attach to an event use \<EVENT>.attach(\<FUNCTION>).
|
|
to create your own event use HASHBASE.event(), you can execute the event with \<EVENT>.execute() which will return a list of created threads where the executed functions run in.
|
|
|
|
Note: **HASHBASE** is sometimes also used to load custom sounds via HASHBASE.loadsound(path)
|
|
this returns an bytearray which can be then used to play the sounds, which will be explained later on.
|
|
|
|
## HASHGAME
|
|
|
|
### **HASHGAME** gives access to the running game class which handles collision, rendering etc.
|
|
|
|
use cases of **HASHGAME** are to access packaged sounds, the renderer, objects, the camera and the keyboard.
|
|
to access the object dictionary directly (which is normally a bad practice) use HASHGAME._objects.
|
|
the key to an object is its ID and the value is the object class.
|
|
to access the renderer (which is also normally bad practice) use HASHGAME._renderer, this gives you access to the running renderer class.
|
|
|
|
How to correctly access/add/remove an object:
|
|
to safely access an Object (no failsafes tho) you can use HASHGAME.getobjbyid(\<ID>).
|
|
to add an Object to the running game use HASHGAME.addobj(\<target object>).
|
|
to remove an object from the running game use HASHGAME.removeobj(\<target object class>) or HASHGAME.removeobjbyid(\<ID>).
|
|
|
|
To check if an specified key is currently pressed use HASHGAME.isdown(\<char>) this will return True if its currently being pressed, False if not and None if its not supported.
|
|
|
|
Supported Keys:
|
|
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, 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
|
|
|
|
back to the camera: the camera is technically just an object with its position describing the rendering offset, meaning that the camera could be made into an player with scripting.
|
|
|
|
## SOUNDS
|
|
|
|
### Hashengine can play sounds too!
|
|
|
|
Hashengine supports audio playback. As previously said, HASHBASE.loadsound(\<PATH>) can be used to load an sound which is generally not good as audio is normally imported in the Hashengine editor and then packaged into the game.
|
|
|
|
to play a sound use SOUND(HASHGAME.sounds[\<Target sound name>]) or if youre using loadsound then SOUND(loadsound(\<PATH>)). this will return a **SOUND** Class which can playback the sound. to play the sound use \<sound>.play().
|
|
to stop the sound use \<sound>.stop() and to yield until the sound is done playing sue \<sound>.wait()
|
|
|