Game Script Documentation & How-To
Welcome to the Game Script language! This is a custom binary-compiled language designed to make game creation simple and readable.
This workspace comes with three main tools:
- The Compiler (
compiler.py): Translates your human-readable .script files into a machine-readable binary file (.bin).
- The Virtual Machine (
vm.py): Acts as your game engine, reading the binary .bin file and executing the commands in real-time.
- The IDE (
ide.py): A visual code editor with syntax highlighting and a 1-click Run button that compiles and executes your code for you.
🚀 How to Write and Run Code
Option 1: Using the Standalone App (Recommended)
You can run the IDE as a downloadable application without needing to install Python.
- Locate the standalone executable in the
dist/ folder (dist/GameScriptIDE).
- Run it directly (e.g.,
./dist/GameScriptIDE in terminal or double-click it in your file manager).
- The IDE will open, allowing you to edit and run your scripts with a single click.
Option 2: Using the IDE via Python
- Open your terminal.
- Run the command:
python3 ide.py
- A code editor window will open. Write your code in the top window.
- Click the green ▶ Compile & Run Script button at the top left.
- The bottom console will display the Virtual Machine's execution output!
Option 3: Using the Terminal Manually
If you prefer to compile and run via the command line:
- Write your code in
game.script.
- Compile it to binary by running:
python3 compiler.py game.script program.bin
- Execute the compiled binary by running:
python3 vm.py program.bin
📖 Language Syntax Guide
Below is a list of all the commands you can use in Game Script. Note: Arguments to commands must be wrapped in double quotes ("like this").
Game & Screen Setup
Setgame("type1,type2") - Sets up the base engine rendering context (e.g. "2D,3D,text").
Gametype("type") - Defines the genre/style of the game.
Gamescreen("height px", "width px") - Sets the window size.
Settype("types") - Define overall variables.
gamemap(tilesize["height px","width px","length px"], chunksize["height tiles","width tiles","length tiles"] mapsize["width chunks","length chunks"]) - Initializes the map/chunk rendering.
Camera Controls
camerapusishin("x", "y", "layer") - Sets the camera to a specific static position on the map and layer/Z-index.
camerafollow("sprite name") - Tells the camera to automatically follow a specific sprite (like the player).
camerazoom("value") - Sets the zoom level of the camera (e.g. "1.0" is default, "2.0" is zoomed in).
Entities (Sprites)
Sprites are the objects, characters, and items in your game. You spawn one, and the subsequent commands configure it.
Spawnspirit("sprite name") - Creates a new entity.
2Dtexture("texture file.png") - Applies a 2D image to the recently spawned sprite.
3Dtexture("texture file.obj") - Applies a 3D model to the recently spawned sprite.
HitBox("shape", ["height px","width px"]) - Gives the sprite collision.
pusishin("x", "y") - Sets the (x, y) coordinates. (Position)
type("type of sprite") - Sets the category (e.g. "enemy", "player").
rotashon("angle") - Sets rotation.
layer("layer") - Sets the Z-index or drawing layer.
destroy("sprite name") - Removes an entity from the game.
getkey("key")="Variable name" - Binds a keyboard key to a variable state.
ontouch("sprite name") - Listens for mobile screen tap/touch on a sprite.
onswipe("direction") - Listens for swipe gestures (up, down, left, right).
joystick("true/false") - Enables a virtual on-screen joystick for mobile movement.
"Variable name"[=,+,-,/,^,sqar](https://github.com/gamescript/gamescript/"value") - Math operations.
if "Variable name" ["<",">","="] ("value") then - Conditional logic.
"Variable"[and,or,not,nand,nor]"Variable"="new Variable" - Logic gates.
Movement & Actions
moveforwered("sprite name")("value") - Move forward.
moveback("sprite name")("value") - Move backward.
moveleft("sprite name")("value") - Move left.
moveright("sprite name")("value") - Move right.
moveup("sprite name")("value") - Move up.
movedown("sprite name")("value") - Move down.
Wait("value") - Wait / Sleep / Pause execution for a number of ticks. (Wait)
Text & UI
Spawn text just like you spawn a sprite!
spawntext("text name") - Creates a UI text element.
font("font") - Sets the text font.
text("the text") - The actual words to display.
size("value") - Font size.
color("color") - Text color.
pusishin("x", "y") - UI coordinates on the screen.
layer("layer") - Sets the Z-index or drawing layer.
Functions
You can bundle blocks of code into reusable functions!
funoshin("function name") - Defines a new function.
"code..." - Put your code underneath.
call("function name") - Runs the function you defined.
🛠️ Example Script
Here is an example of what a simple game setup looks like in game.script:
Setgame("2D")
Gamescreen("800", "600")
Spawnspirit("Player1")
2Dtexture("hero.png")
pusishin("100", "100")
HitBox("square", ["32", "32"])
spawntext("ScoreDisplay")
text("Score: 0")
pusishin("10", "10")
funoshin("MovePlayerLoop")
moveforwered("Player1")("5")
call("MovePlayerLoop")
Happy programming in Game Script!
| |