You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hyper is still a work-in-progress engine at this time. The scripting system is in its alpha stage, and changes might happen without order; however, this guide remains viable for the scripting basics of the engine.
To attach a script to an entity, create a .lua
-- Player.lualocalPlayer= {}
returnPlayer
The script must return a table. It is used to access other parts of the system. A script file has three primary methods.
-- called once, when the script was loadedfunctionPlayer:init()
end-- called for every framefunctionPlayer:update(dt)
end-- called when the scene endsfunctionPlayer:destroy()
end
the init and destroy methods can be omitted, but the update method is required and compulsory; In other words, there should be no script file if there's no update method.
How to interact with the entity's component
Each script is attached to an entity, as a component. An entity can have many elements, and by default has an ID, tag and transform component. Presumably, these components are always existing for an entity.
Here's how we can interact with components from the script:
functionPlayer:init()
self.velocity=10transform=self.owner:get(self.id(), Transform)
print(transform.position)
print(transform.scale)
print(transform.rotation)
endfunctionPlayer:update(dt)
transform=self.owner:get(self.id(), Transform)
transform.position.x=transform.position.x+self.velocity*dt-- continue moving to the rightend
self.owner: The S in ECS. It's an interface to the scene's registry where entities and their components are managed. It provides methods such as has, get, valid, remove, clear and emplace. These methods take two parameters, an entity ID, and the component type. self.id: The script's entity ID.
Available Components:
IDComponent
TagComponent
Transform
SpriteComponent
CircleComponent
TextComponent
reference /hyper/src/scene/components.hpp to see the component structures
The text was updated successfully, but these errors were encountered:
Firstly, right-click the scene hierarchy panel and select the popup menu to create an entity. Select the new entity (already done by default), you should see its components rendered in the properties panel.
Nothing is rendered on the viewport for now, that's because the current entity does not have any drawable component yet. You should see a button labelled add component, click it and select your preferred drawable component (for the sake of this doc, choose SpriteComponent).
Congrats! You can play around with the entity, and also try using the controls (see below) to manipulate your entity"
Script Reference
To attach a script to an entity, create a .lua
The script must return a table. It is used to access other parts of the system. A script file has three primary methods.
the
init
anddestroy
methods can be omitted, but theupdate
method is required and compulsory; In other words, there should be no script file if there's noupdate
method.How to interact with the entity's component
Each script is attached to an entity, as a component. An entity can have many elements, and by default has an ID, tag and transform component. Presumably, these components are always existing for an entity.
Here's how we can interact with components from the script:
self.owner
: The S in ECS. It's an interface to the scene's registry where entities and their components are managed. It provides methods such ashas
,get
,valid
,remove
,clear
andemplace
. These methods take two parameters, an entity ID, and the component type.self.id
: The script's entity ID.Available Components:
The text was updated successfully, but these errors were encountered: