User Tools

Site Tools


Basic EntityScript

  • A script load some resources and define some entity scripts.
  • The context is not shared with other scripts, so global variables are only available for this script.
  • Each lua script is executed when the lua threads are created (so the script can be executed 8 times if there are 8 threads).

Global initialization

Since the entity scripts are executed in threads, it's not possible to use graphical functions in them, so you need to load any GPU resource at the script execution.

Simple example (in this case the script is executed in both sides, client and server) :

-- global initialization
-- load a hemisphere mesh
mesh_hemisphere = DataManager.loadMesh("shinsekai.archzenvald.com_repos_test_room1/objects/hemisphere.sho")
-- or DataManager.loadMesh(REPODIR.."/objects/hemisphere.sho")
-- load a texture (client-side)
if client then
  tex_sky = DataManager.loadTexture("shinsekai.archzenvald.com_repos_test_room1/textures/skydome_night.jpg",true)

Define the entity script

MyEntity = {}
-- overload some methods
  print("Nice to be alive.")
  -- create the sky
  if client then = self:createFalseInstance() -- set sky flag
    self:sceneAdd( -- add the object to the scene
MyEntity:frame(time) -- called at every client/server frames
  print("Please, not yet.")
-- register the entity script
registerEntityScript("MyEntity",MyEntity) -- choose a unique class name for your entity, without space

To spawn it on your own server, add the entity to the entities.list :

MyEntity my_entity1


Tutorials can't cover everything and every changes made to the scripting interface, here is the up to date online documentation.

dev/tutorials/basic.txt · Last modified: 2017/04/03 15:37 by archzenvald