Core

From Crumbled World Wiki

CoreExampleCode

Static functions

return function description
setUpdateHz(float hz) Sets the update frequency of the script based on in game time. minimum hz that can be set is >0.1 below that it will update every frame
setUpdateHzRealTime(float hz) Sets the update frequency of the script based on real time. minimum hz that can be set is >0.1 below that it will update every frame
skipFrames(int frames) Skip a specified number of frames once.
skipTime(float seconds) Skip a specified time only once. This function needs to be called every time the script want to skip a specified number of frames.
float getAverageDeltaTime() Get the average delta time over the last 100 frames.
float getDeltaTime() Get the last frames delta time.
float getRealDeltaTime() Get the last frames delta time without speed factor.
double getGameTime() Get time since the program started, with speed factor.
float getTime() Get time since the program started.
float getTimeSpeed() Get time speed.
setTimeSpeed(float speed) Set time speed bettwen [0,10], defult is 1.0.
FontCharacter getFontCharacter(String font, int fontHeight, String character) Get a font character.
Sound getSound() Load sound.
Work getCurrentWork() Return the current work.
LuaScript getCurrentLuaScript() Returns the the current executing Lua script.
setSoundCamera(Camera camera) Set to which camera sound will go. This will be removed in the future.
setSoundCameraMatrix(Matrix cameraMatrix) Set sound camera matrix. this is only useful when sound camera is set to nil.
setDebug2DCamera(Camera camera) Set to which camera 2D debug text should be renderd to.
addDebugLine(Vec3 l1, Vec3 l2, float time, Vec3 color) Add debug line.
addDebugLine(Line3D line, float time, Vec3 color) Add debug line.
addDebugSphere(Sphere sphere, float time, Vec3 color) Add debug sphere.
addDebugBox(Box box, float time, Vec3 color) Add debug box.
clearDebugLines() Clear all debug data, this includes lines, Spheres and debugBoxes.
int getFrameNumber() get number of rendered frame sence program started.
Model getModel(string modelName) Load model.
Shader getShader(string shaderName) Load shader.
Shader getShader(string shaderName, string definition) Load shader with one definition.
Shader getShader(string shaderName, table definitions) Load shader with one definitions.
Texture getTexture(string textureName) Load texture.
Texture getTexture(File aFile) Load texture from a file.
File getDataFolder() Get main folder.
File getDataFolder(string subFolder) Get sub folder from main folder.
Vec2 getScreenResolution() Get screen resolution.
Vec2 getRenderResolution() Get render resolution.
float getRenderScale() Get render scale.
string getSteamName() returns the name of the current steam user, if available.
bool setScriptNetworkId(string name) Sets the network name of this script. returns true on success. [This name should be set by all clients individually]
requireScriptNetworkIdToRunUpdate(bool set) If set true, the script will not run "update" until setScriptNetworkId() is set
number getPlayerId() returns the unique player id of the client. to know where he is supossed to be.
string getNetworkName() returns netName for the current script
Client getNetworkClient() Returns the client, using multiple times will return the same client. (There is one client)
Server getNetworkServer() Returns the server, using multiple times will return the same server. (There is one server)
{ {name=string(), ip=string(), port=int(), time=int()} } getServerList() Returns the global serverlist.
{ {name=string(), ip=string(), port=int(), time=int()} } getServerList(int time) Returns the global serverlist. Time is in the format epoch seconds.
bool isInMultiplayer() Returns true if the client is connected to a server.
bool isInFullscreen() Returns true if in fullscreen mode
number getIndexOfNetworkName(string networkName) Returns the index of the script with the networkName, or 0 if none was found
LuaScript getScriptOfNetworkName(string networkName) Returns the script that uses the networkName, or nil if none was found
string getNetworkNameOf(object param) Returns the Network name of the script. takes number(index of a script) or a LuaScript
ComUnit getComUnit() Get screen resolution.
bool existLuaScript(int luaIndex) Returns true if lua script is running.
Billboard getBillboard() Get the billboard for this script.
Billboard getBillboard(int luaIndex) Get the billboard for luaIndex.
Billboard getBillboard(string name) Get billboard by name.
Input getInput() Get input.
HighScore getHighScore() Get HighScore.
Cursor getCursor() Get cursor.
stopCore() Stop score.
quitMainMenu() If game is in main menu then the game will be shutdown.
quitToMainMenu() Quit from mapeditor or game to main menu.
quitToMapeditor() Quit from game to mapeditor.
bool isInEditor() Return true when in editor or when testing a map from the editor.
startMap(string fileName) start map with name like fileName="Data/Map/fil.map".
startMultiplayerClonedMaps(string fileName, nil clientIds) start map with name like fileName="Data/Map/fil.map".

clientIds is a list of all client ids that need a private world to be loaded. example {2,3,4,5}

startMapInDebugMode(string fileName) start map in debug mode with name like fileName="Data/Map/fil.map".
startMapEditor(string fileName) start mapEditor. If fileName is "" then a new map will be created.
Panel getPanelWithKeyboardFocus() Return the curent panel with keyboard focus.
Billboard getGlobalBillboard(string billboardName) Create or collect the billboard with a given name. The Billboard will exist unit the game shutsdown. The billboardName must be unique or allready exist as a globalBillboard.
Billboard getGameSessionBillboard(string billboardName) Create or collect the billboard with a given name. The Billboard will exist unit the game current map is shutdown.
Camera getMainCamera() Get the main camera.
setMainCamera(Camera mainCamera) set the main camera.
setRenderScale(float scale) set the scale factor of the current render resolution. should be between [0.5,2.0]
setRenderResolution(Vec2 resolution) set Render resolution.
setMaxFrameRate(int maxFrameRate)
skipRenderFrame()
setCursor(string cursorFilePath) Set the cursor icon. NOTE! must be a *.bmp file.
setSounMasterGain(float gain) set sound master gain, gain is between [0,1]
setSoundMusicGain(float gain) set music gain, gain is between [0,1]
setSounEffectGain(float gain) set effect gain, gain is between [0,1]
float getSounMasterGain() get sound master gain
float getSounMusicGain() get sound master gain
float getSounEffectGain() get sound master gain
Panel getPanelWithMouseFocus() get panel with mouse focus.
Panel getPanelWithKeyboardFocus() get panel with mouse focus.
string getMachineId() get the machine ID.
setFullscreen(bool fullscreen) Set if we should use fullscreen.
setVsync(bool vSync) Set if vSyncshould turned od.
DirectionalLight getDirectionalLight(SceneNode node) get the current direction light
AmbientLight getAmbientLight(SceneNode node) get the current ambientlight