Scripting Basics
This guide gets you from zero to a working behavior script.
Where Scripts Live
Gameplay scripts usually live under:
Assets/ScriptsAssets/Events
Most runtime behavior classes extend Sendama\Engine\Core\Behaviours\Behaviour.
Your First Behavior
<?php
namespace MyGame\Scripts\Player;
use Sendama\Engine\Core\Behaviours\Behaviour;
use Sendama\Engine\Core\Vector2;
use Sendama\Engine\IO\Input;
use Sendama\Engine\IO\Enumerations\KeyCode;
final class PlayerController extends Behaviour
{
public float $speed = 1.0;
public function onUpdate(): void
{
$motion = new Vector2();
if (Input::isKeyPressed(KeyCode::a)) {
$motion->setX(-$this->speed);
}
if (Input::isKeyPressed(KeyCode::d)) {
$motion->setX($this->speed);
}
$this->getTransform()->translate($motion);
}
}
Attach this script to a game object in the inspector.
KeyCode enum values are the preferred style because they avoid key-name typos.
String keys still work when needed (for example Input::isKeyPressed('a')).
Core Hooks To Know First
Start with these hooks:
awake()onStart()onUpdate()onFixedUpdate()
Use onUpdate() for most gameplay frame logic.
Accessing Object Context
Inside a behavior you can use:
getGameObject()getTransform()getRenderer()activeScenescene
Serialized Values From Scene/Prefab Data
You can tune behavior values in metadata and read them in scripts.
Example metadata payload:
[
'type' => Sendama\MyGame\Scripts\Player\PlayerController::class,
'data' => [
'speed' => 4.0,
],
]
This lets designers tune behavior without editing script code each time.
Practical Authoring Loop
- create behavior script
- attach to object or prefab
- expose fields to tune
- set values in inspector
- save scene and playtest