Select the types of activity you want to include in your feed.
[READ-ONLY] Mirror of https://github.com/thoda-dev/du-lua-framework. A framework to simplify coding in Dual Universe. Permit to create most of the code in Unit > onStart
···11# du-lua-framework
22- A framework to simplidy coding in Dual Universe.
22+ A framework to simplify coding in Dual Universe.
3344 Permit to create most of the code in Unit > onStart
55+66+# Edit the code Online
77+88+[](https://du-lua.dev/#/editor/github/Jericho1060/du-lua-framework)
59610# Guilded Server (better than Discord)
711···24282529## Major Changes compared to the game logic
26302727-System onUpdate and onFlush events are now builded with coroutines, in the framework, onUpdate and onFlush are loading a table of functions that will be runned as coroutines. This way you can have multiple functions running at the same time, and you use the yield function to pause the coroutine and let the other coroutines run. Each coroutine will be resume or restarted if dead each time the system onUpdate or onFlush event is called.
3131+System onUpdate and onFlush events are now built with coroutines, in the framework, onUpdate and onFlush are loading a table of functions that will be runned as coroutines. This way you can have multiple functions running at the same time, and you use the yield function to pause the coroutine and let the other coroutines run. Each coroutine will be resume or restarted if dead each time the system onUpdate or onFlush event is called.
28322933## Code Examples
3034
+1-1
config.json
···11-{"events":[],"handlers":[{"code":"Script.system:update()","filter":{"args":[],"signature":"onUpdate()","slotKey":"-4"},"key":"10"},{"code":"Script.system:inputText(text)","filter":{"args":[{"variable":"*"}],"signature":"onInputText(text)","slotKey":"-4"},"key":"11"},{"code":"Script.system:flush()","filter":{"args":[],"signature":"onFlush()","slotKey":"-4"},"key":"12"},{"code":"Script.system:actionStop(action)","filter":{"args":[{"variable":"*"}],"signature":"onActionStop(action)","slotKey":"-4"},"key":"13"},{"code":"Script.system:actionStart(action)","filter":{"args":[{"variable":"*"}],"signature":"onActionStart(action)","slotKey":"-4"},"key":"14"},{"code":"Script.system:actionLoop(action)","filter":{"args":[{"variable":"*"}],"signature":"onActionLoop(action)","slotKey":"-4"},"key":"15"},{"code":"Script.player:parentChanged(oldId, newId)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"onParentChanged(oldId,newId)","slotKey":"-3"},"key":"3"},{"code":"Script.construct:VRStationEntered(id)","filter":{"args":[{"variable":"*"}],"signature":"onVRStationEntered(id)","slotKey":"-2"},"key":"6"},{"code":"Script.construct:undocked(id)","filter":{"args":[{"variable":"*"}],"signature":"onUndocked(id)","slotKey":"-2"},"key":"8"},{"code":"Script.construct:PvPTimer(active)","filter":{"args":[{"variable":"*"}],"signature":"onPvPTimer(active)","slotKey":"-2"},"key":"4"},{"code":"Script.construct:playerBoarded(id)","filter":{"args":[{"variable":"*"}],"signature":"onPlayerBoarded(id)","slotKey":"-2"},"key":"7"},{"code":"","filter":{"args":[{"variable":"*"}],"signature":"onDocked(id)","slotKey":"-2"},"key":"9"},{"code":"Script.construct:constructDocked(id)","filter":{"args":[{"variable":"*"}],"signature":"onConstructDocked(id)","slotKey":"-2"},"key":"5"},{"code":"Script.unit:timer(tag)","filter":{"args":[{"variable":"*"}],"signature":"onTimer(tag)","slotKey":"-1"},"key":"1"},{"code":"Script.unit:stop()","filter":{"args":[],"signature":"onStop()","slotKey":"-1"},"key":"2"},{"code":"--[[\n DU-LUA-Framework by Jericho\n Permit to code easier by grouping most of the code in a single event Unit > Start\n Unminified Source available here: https://github.com/Jericho1060/du-lua-framework\n]]--\nlocal a=system.print;local b=error;local c=pcall;local d=assert;local e=coroutine;local f=e.create;local g=e.status;local h=e.resume;local i=\"dead\"local j=\"suspended\"function runFunction(k,l,...)local m,n=c(k,...)if not m then b(l..n)end end;local o={__index={cos={update={},flush={}},fns={update={},flush={},action={start={},stop={},loop={}},inputText=nil,start=nil,stop=nil},ACTIONS={FORWARD=\"forward\",BACKWARD=\"backward\",YAW_LEFT=\"yawleft\",YAW_RIGHT=\"yawright\",STRAFE_LEFT=\"strafeleft\",STRAFE_RIGHT=\"straferight\",LEFT=\"left\",RIGHT=\"right\",UP=\"up\",DOWN=\"down\",GROUND_ALTITUDE_UP=\"groundaltitudeup\",GROUND_ALTITUDE_DOWN=\"groundaltitudedown\",LEFT_ALT=\"lalt\",LEFT_SHIFT=\"lshift\",GEAR=\"gear\",LIGHT=\"light\",BRAKE=\"brake\",OPTION_1=\"option1\",OPTION_2=\"option2\",OPTION_3=\"option3\",OPTION_4=\"option4\",OPTION_5=\"option5\",OPTION_6=\"option6\",OPTION_7=\"option7\",OPTION_8=\"option8\",OPTION_9=\"option9\",LEFT_MOUSE=\"leftmouse\",STOP_ENGINES=\"stopengines\",SPEED_UP=\"speedup\",SPEED_DOWN=\"speeddown\",ANTIGRAVITY=\"antigravity\",BOOSTER=\"booster\"},main={update=f(function()end),flush=f(function()end)},update=function(self)local p=g(self.main.update)if p==i then self.main.update=f(function()self:runUpdate()end)elseif p==j then d(h(self.main.update))end end,flush=function(self)local p=g(self.main.flush)if p==i then self.main.flush=f(function()self:runFlush()end)elseif p==j then d(h(self.main.flush))end end,action=function(self,q,r)if self.fns.action[q][r]then runFunction(self.fns.action[q][r],\"System Action \"..q..\" Error: \")end end,actionStart=function(self,r)self:action('start',r)end,actionStop=function(self,r)self:action('stop',r)end,actionLoop=function(self,r)self:action('loop',r)end,inputText=function(self,s)if self.fns.inputText then runFunction(self.fns.inputText,\"System Input Text Error: \",s)end end,runUpdate=function(self)for t,u in pairs(self.cos.update)do local m=g(u)if m==i then self.cos.update[t]=f(self.fns.update[t])elseif m==j then d(h(u))end end end,runFlush=function(self)for t,u in pairs(self.cos.flush)do local m=g(u)if m==i then self.cos.flush[t]=f(self.fns.flush[t])elseif m==j then d(h(u))end end end,onUpdate=function(self,v)for t,w in pairs(v)do self.fns.update[t]=w;self.cos.update[t]=f(w)end end,onFlush=function(self,v)for t,w in pairs(v)do self.fns.flush[t]=w;self.cos.flush[t]=f(w)end end,onAction=function(self,q,v)for t,w in pairs(v)do self.fns.action[q][t]=w end end,onActionStart=function(self,v)self:onAction(\"start\",v)end,onActionStop=function(self,v)self:onAction(\"stop\",v)end,onActionLoop=function(self,v)self:onAction(\"loop\",v)end,onInputText=function(self,k)self.fns.inputText=k end}}local x={__index={timers={},stopFn=function()end,timer=function(self,y)if self.timers[y]then runFunction(self.timers[y],\"Unit Timer \"..y..\" Error: \")end end,setTimer=function(self,y,z,k)self.timers[y]=k;unit.setTimer(y,z)end,stopTimer=function(self,y)unit.stopTimer(y)self.timers[y]=nil end,onStop=function(self,k)self.stopFn=k end,stop=function(self)if self.stopFn then runFunction(self.stopFn,\"Unit Stop Error: \")end end}}local A={__index={parentChangedFn=function(B,C)end,onParentChange=function(self,k)self.parentChangedFn=k end,parentChanged=function(self,B,C)if self.parentChangedFn then runFunction(self.parentChangedFn,\"Player Parent Changed Error: \",B,C)end end}}local D={__index={dockedFn=function(E)end,onDocked=function(self,k)self.dockedFn=k end,docked=function(self,E)if self.dockedFn then runFunction(self.dockedFn,\"Construct Docked Error: \",E)end end,undockedFn=function(E)end,onUndocked=function(self,k)self.undockedFn=k end,undocked=function(self,E)if self.undockedFn then runFunction(self.undockedFn,\"Construct Undocked Error: \",E)end end,playerBoardedFn=function(E)end,onPlayerBoarded=function(self,k)self.playerBoardedFn=k end,playerBoarded=function(self,E)if self.playerBoardedFn then runFunction(self.playerBoardedFn,\"Construct Player Boarded Error: \",E)end end,VRStationEnteredFn=function(E)end,onVRStationEntered=function(self,k)self.VRStationEnteredFn=k end,VRStationEntered=function(self,E)if self.VRStationEnteredFn then runFunction(self.VRStationEnteredFn,\"Construct VR Station Entered Error: \",E)end end,constructDockedFn=function(E)end,onConstructDocked=function(self,k)self.constructDockedFn=k end,constructDocked=function(self,E)if self.constructDockedFn then runFunction(self.constructDockedFn,\"Construct Construct Docked Error: \",E)end end,PvPTimerFn=function(F)end,onPvPTimer=function(self,k)self.PvPTimerFn=k end,PvPTimer=function(self,F)if self.PvPTimerFn then runFunction(self.PvPTimerFn,\"Construct PvP Timer Error: \",F)end end}}DU_Framework={__index={system=setmetatable({},o),unit=setmetatable({},x),player=setmetatable({},A),construct=setmetatable({},D)}}\n\nScript = {}\nsetmetatable(Script, DU_Framework)\n\n\n--[[\n You can declare here all the functions you want to call in the diffent events from system, unit, player and construct.\n Major changes compared to the base game concept:\n - System onUpdate and onFlush events are now builded with coroutines, in the framework, onUpdate and onFlush are loading a table of functions that will be runned as coroutines. This way you can have multiple functions running at the same time, and you use the yield function to pause the coroutine and let the other coroutines run. Each coroutine will be resume or restarted if dead each time the system onUpdate or onFlush event is called.\n\n]]\n\n--Functions to load as coroutines that will be runned in system > onUpdate (based on FPS)\nlocal system_update = {}\nsystem_update.co1 = function ()\n for i=0, 10 do\n system.print(\"coroutine 1 --- update --- \"..i)\n coroutine.yield() -- pause the coroutine 1, it will wait till the next onUpdate event to be resumed\n end\nend\nsystem_update.co2 = function ()\n for i=0, 10 do\n system.print(\"coroutine 2 --- update --- \"..i)\n coroutine.yield() -- pause the coroutine 2, it will wait till the next onUpdate event to be resumed\n end\nend\n\n--Functions to load as coroutines that will be runned in system > onFlush (60 times / s)\nlocal system_flush = {}\nsystem_flush.co1 = function ()\n for i=0, 10 do\n system.print(\"coroutine 1 --- flush --- \"..i)\n coroutine.yield() -- pause the coroutine 1, it will wait till the next onFlush event to be resumed\n end\nend\nsystem_flush.co2 = function ()\n for i=0, 10 do\n system.print(\"coroutine 2 --- flush --- \"..i)\n coroutine.yield() -- pause the coroutine 2, it will wait till the next onFlush event to be resumed\n end\nend\n\n--Function to run on actions\nlocal system_action_start = {}\nsystem_action_start[Script.system.ACTIONS.BRAKE] = function()\n system.print(\"I'm braking\");\nend\nlocal system_action_stop = {}\nsystem_action_stop[Script.system.ACTIONS.BRAKE] = function()\n system.print(\"I stopped braking\");\nend\nlocal system_action_loop = {}\nsystem_action_loop[Script.system.ACTIONS.BRAKE] = function()\n system.print(\"I'm still braking\");\nend\n\n--Function to run when input text to the lua chat\nlocal system_inputText = function (text)\n system.print(\"Input: \" .. text)\nend\n\n--Function to run when the program is stopping\nlocal unit_onstop = function ()\n system.print(\"Program is stopping\")\nend\n\n--Function to run when the player change parent\nlocal player_onparentchanged = function (oldParent, newParent)\n system.print(\"Player changed parent from ID \"..oldParent..\" to ID \"..newParent)\nend\n\n--Function to run when the construct is docked or undocked\nlocal construct_onDocked = function(id)\n system.print(\"Construct docked on ID \"..id)\nend\nlocal construct_onUndocked = function(id)\n system.print(\"Construct undocked from ID \"..id)\nend\n\n--Function to run when a player board the construct\nlocal construct_onplayerboarded = function(id)\n system.print(\"Player with ID \" .. id .. \" boarded construct\")\nend\n\n--Function to run when a player enter the VR Station\nlocal construct_vrstationentered = function(id)\n system.print(\"Player with ID \" .. id .. \" entered VR Station\")\nend\n\n--Function to run when another construct is docked on this construct\nlocal construct_constructdocked = function(id)\n system.print(\"Construct with ID \" .. id .. \" docked on this construct\")\nend\n\n--Function to run when pvp timer is changing state\nlocal construct_onpvptimer = function(active)\n if active then\n system.print(\"PVP is now active\")\n else\n system.print(\"PVP is now inactive\")\n end\nend\n\n--[[\n Here how to load the functions in the framework\n]]\nScript.system:onUpdate(system_update) --loading coroutines for system > onUpdate\nScript.system:onFlush(system_flush) --loading coroutines for system > onFlush\n\nScript.system:onActionStart(system_action_start) --loading all \"actionStart\" functions\nScript.system:onActionStop(system_action_stop) --loading all \"actionStop\" functions\nScript.system:onActionLoop(system_action_loop) --loading all \"actionLoop\" functions\n\nScript.system:onInputText(system_inputText) --loading the function to trigger when input text in lua chat\n\nScript.unit:setTimer(\"hello\", 1, function()system.print(\"hello\")end) --add a timer displaying \"hello\" every seconds\nScript.unit:setTimer(\"hello5\", 5, function()system.print(\"hello 5\")end) --add a timer displaying \"hello 5\" every 5 seconds\nScript.unit:onStop(unit_onstop) --loading the function to trigger when the program is stopping\n\nScript.player:onParentChanged(player_onparentchanged) --loading the function to trigger when the player change parent\n\nScript.construct:onDocked(construct_onDocked) --loading the function to trigger when the construct is docked\nScript.construct:onUndocked(construct_onUndocked) --loading the function to trigger when the construct is undocked\nScript.construct:onPlayerBoarded(construct_onplayerboarded) --loading the function to trigger when a player board the construct\nScript.construct:onVRStationEntered(construct_vrstationentered) --loading the function to trigger when a player enter the VR Station\nScript.construct:onConstructDocked(construct_constructdocked) --loading the function to trigger when another construct is docked on this construct\nScript.construct:onPvPTimer(construct_onpvptimer) --loading the function to trigger when pvp timer is changing state","filter":{"args":[],"signature":"onStart()","slotKey":"-1"},"key":"0"}],"methods":[],"slots":{"0":{"name":"slot1","type":{"events":[],"methods":[]}},"1":{"name":"slot2","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-5":{"name":"library","type":{"events":[],"methods":[]}},"-4":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"player","type":{"events":[],"methods":[]}},"-2":{"name":"construct","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}}}}11+{"events":[],"handlers":[{"code":"Script.system:update()","filter":{"args":[],"signature":"onUpdate()","slotKey":"-4"},"key":"10"},{"code":"Script.system:inputText(text)","filter":{"args":[{"variable":"*"}],"signature":"onInputText(text)","slotKey":"-4"},"key":"11"},{"code":"Script.system:flush()","filter":{"args":[],"signature":"onFlush()","slotKey":"-4"},"key":"12"},{"code":"Script.system:actionStop(action)","filter":{"args":[{"variable":"*"}],"signature":"onActionStop(action)","slotKey":"-4"},"key":"13"},{"code":"Script.system:actionStart(action)","filter":{"args":[{"variable":"*"}],"signature":"onActionStart(action)","slotKey":"-4"},"key":"14"},{"code":"Script.system:actionLoop(action)","filter":{"args":[{"variable":"*"}],"signature":"onActionLoop(action)","slotKey":"-4"},"key":"15"},{"code":"Script.player:parentChanged(oldId, newId)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"onParentChanged(oldId,newId)","slotKey":"-3"},"key":"3"},{"code":"Script.construct:VRStationEntered(id)","filter":{"args":[{"variable":"*"}],"signature":"onVRStationEntered(id)","slotKey":"-2"},"key":"6"},{"code":"Script.construct:undocked(id)","filter":{"args":[{"variable":"*"}],"signature":"onUndocked(id)","slotKey":"-2"},"key":"8"},{"code":"Script.construct:PvPTimer(active)","filter":{"args":[{"variable":"*"}],"signature":"onPvPTimer(active)","slotKey":"-2"},"key":"4"},{"code":"Script.construct:playerBoarded(id)","filter":{"args":[{"variable":"*"}],"signature":"onPlayerBoarded(id)","slotKey":"-2"},"key":"7"},{"code":"","filter":{"args":[{"variable":"*"}],"signature":"onDocked(id)","slotKey":"-2"},"key":"9"},{"code":"Script.construct:constructDocked(id)","filter":{"args":[{"variable":"*"}],"signature":"onConstructDocked(id)","slotKey":"-2"},"key":"5"},{"code":"Script.unit:timer(tag)","filter":{"args":[{"variable":"*"}],"signature":"onTimer(tag)","slotKey":"-1"},"key":"1"},{"code":"Script.unit:stop()","filter":{"args":[],"signature":"onStop()","slotKey":"-1"},"key":"2"},{"code":"--[[\n DU-LUA-Framework by Jericho\n Permit to code easier by grouping most of the code in a single event Unit > Start\n Unminified Source available here: https://github.com/Jericho1060/du-lua-framework\n]]--\nlocal a=system.print;local b=error;local c=pcall;local d=assert;local e=coroutine;local f=e.create;local g=e.status;local h=e.resume;local i=\"dead\"local j=\"suspended\"function runFunction(k,l,...)local m,n=c(k,...)if not m then b(l..n)end end;local o={__index={cos={update={},flush={}},fns={update={},flush={},action={start={},stop={},loop={}},inputText=nil,start=nil,stop=nil},ACTIONS={FORWARD=\"forward\",BACKWARD=\"backward\",YAW_LEFT=\"yawleft\",YAW_RIGHT=\"yawright\",STRAFE_LEFT=\"strafeleft\",STRAFE_RIGHT=\"straferight\",LEFT=\"left\",RIGHT=\"right\",UP=\"up\",DOWN=\"down\",GROUND_ALTITUDE_UP=\"groundaltitudeup\",GROUND_ALTITUDE_DOWN=\"groundaltitudedown\",LEFT_ALT=\"lalt\",LEFT_SHIFT=\"lshift\",GEAR=\"gear\",LIGHT=\"light\",BRAKE=\"brake\",OPTION_1=\"option1\",OPTION_2=\"option2\",OPTION_3=\"option3\",OPTION_4=\"option4\",OPTION_5=\"option5\",OPTION_6=\"option6\",OPTION_7=\"option7\",OPTION_8=\"option8\",OPTION_9=\"option9\",LEFT_MOUSE=\"leftmouse\",STOP_ENGINES=\"stopengines\",SPEED_UP=\"speedup\",SPEED_DOWN=\"speeddown\",ANTIGRAVITY=\"antigravity\",BOOSTER=\"booster\"},main={update=f(function()end),flush=f(function()end)},update=function(self)local p=g(self.main.update)if p==i then self.main.update=f(function()self:runUpdate()end)elseif p==j then d(h(self.main.update))end end,flush=function(self)local p=g(self.main.flush)if p==i then self.main.flush=f(function()self:runFlush()end)elseif p==j then d(h(self.main.flush))end end,action=function(self,q,r)if self.fns.action[q][r]then runFunction(self.fns.action[q][r],\"System Action \"..q..\" Error: \")end end,actionStart=function(self,r)self:action('start',r)end,actionStop=function(self,r)self:action('stop',r)end,actionLoop=function(self,r)self:action('loop',r)end,inputText=function(self,s)if self.fns.inputText then runFunction(self.fns.inputText,\"System Input Text Error: \",s)end end,runUpdate=function(self)for t,u in pairs(self.cos.update)do local m=g(u)if m==i then self.cos.update[t]=f(self.fns.update[t])elseif m==j then d(h(u))end end end,runFlush=function(self)for t,u in pairs(self.cos.flush)do local m=g(u)if m==i then self.cos.flush[t]=f(self.fns.flush[t])elseif m==j then d(h(u))end end end,onUpdate=function(self,v)for t,w in pairs(v)do self.fns.update[t]=w;self.cos.update[t]=f(w)end end,onFlush=function(self,v)for t,w in pairs(v)do self.fns.flush[t]=w;self.cos.flush[t]=f(w)end end,onAction=function(self,q,v)for t,w in pairs(v)do self.fns.action[q][t]=w end end,onActionStart=function(self,v)self:onAction(\"start\",v)end,onActionStop=function(self,v)self:onAction(\"stop\",v)end,onActionLoop=function(self,v)self:onAction(\"loop\",v)end,onInputText=function(self,k)self.fns.inputText=k end}}local x={__index={timers={},stopFn=function()end,timer=function(self,y)if self.timers[y]then runFunction(self.timers[y],\"Unit Timer \"..y..\" Error: \")end end,setTimer=function(self,y,z,k)self.timers[y]=k;unit.setTimer(y,z)end,stopTimer=function(self,y)unit.stopTimer(y)self.timers[y]=nil end,onStop=function(self,k)self.stopFn=k end,stop=function(self)if self.stopFn then runFunction(self.stopFn,\"Unit Stop Error: \")end end}}local A={__index={parentChangedFn=function(B,C)end,onParentChange=function(self,k)self.parentChangedFn=k end,parentChanged=function(self,B,C)if self.parentChangedFn then runFunction(self.parentChangedFn,\"Player Parent Changed Error: \",B,C)end end}}local D={__index={dockedFn=function(E)end,onDocked=function(self,k)self.dockedFn=k end,docked=function(self,E)if self.dockedFn then runFunction(self.dockedFn,\"Construct Docked Error: \",E)end end,undockedFn=function(E)end,onUndocked=function(self,k)self.undockedFn=k end,undocked=function(self,E)if self.undockedFn then runFunction(self.undockedFn,\"Construct Undocked Error: \",E)end end,playerBoardedFn=function(E)end,onPlayerBoarded=function(self,k)self.playerBoardedFn=k end,playerBoarded=function(self,E)if self.playerBoardedFn then runFunction(self.playerBoardedFn,\"Construct Player Boarded Error: \",E)end end,VRStationEnteredFn=function(E)end,onVRStationEntered=function(self,k)self.VRStationEnteredFn=k end,VRStationEntered=function(self,E)if self.VRStationEnteredFn then runFunction(self.VRStationEnteredFn,\"Construct VR Station Entered Error: \",E)end end,constructDockedFn=function(E)end,onConstructDocked=function(self,k)self.constructDockedFn=k end,constructDocked=function(self,E)if self.constructDockedFn then runFunction(self.constructDockedFn,\"Construct Construct Docked Error: \",E)end end,PvPTimerFn=function(F)end,onPvPTimer=function(self,k)self.PvPTimerFn=k end,PvPTimer=function(self,F)if self.PvPTimerFn then runFunction(self.PvPTimerFn,\"Construct PvP Timer Error: \",F)end end}}DU_Framework={__index={system=setmetatable({},o),unit=setmetatable({},x),player=setmetatable({},A),construct=setmetatable({},D)}}\n\nScript = {}\nsetmetatable(Script, DU_Framework)\n\n\n--[[\n You can declare here all the functions you want to call in the diffent events from system, unit, player and construct.\n Major changes compared to the base game concept:\n - System onUpdate and onFlush events are now built with coroutines, in the framework, onUpdate and onFlush are loading a table of functions that will be runned as coroutines. This way you can have multiple functions running at the same time, and you use the yield function to pause the coroutine and let the other coroutines run. Each coroutine will be resume or restarted if dead each time the system onUpdate or onFlush event is called.\n\n]]\n\n--Functions to load as coroutines that will be runned in system > onUpdate (based on FPS)\nlocal system_update = {}\nsystem_update.co1 = function ()\n for i=0, 10 do\n system.print(\"coroutine 1 --- update --- \"..i)\n coroutine.yield() -- pause the coroutine 1, it will wait till the next onUpdate event to be resumed\n end\nend\nsystem_update.co2 = function ()\n for i=0, 10 do\n system.print(\"coroutine 2 --- update --- \"..i)\n coroutine.yield() -- pause the coroutine 2, it will wait till the next onUpdate event to be resumed\n end\nend\n\n--Functions to load as coroutines that will be runned in system > onFlush (60 times / s)\nlocal system_flush = {}\nsystem_flush.co1 = function ()\n for i=0, 10 do\n system.print(\"coroutine 1 --- flush --- \"..i)\n coroutine.yield() -- pause the coroutine 1, it will wait till the next onFlush event to be resumed\n end\nend\nsystem_flush.co2 = function ()\n for i=0, 10 do\n system.print(\"coroutine 2 --- flush --- \"..i)\n coroutine.yield() -- pause the coroutine 2, it will wait till the next onFlush event to be resumed\n end\nend\n\n--Function to run on actions\nlocal system_action_start = {}\nsystem_action_start[Script.system.ACTIONS.BRAKE] = function()\n system.print(\"I'm braking\");\nend\nlocal system_action_stop = {}\nsystem_action_stop[Script.system.ACTIONS.BRAKE] = function()\n system.print(\"I stopped braking\");\nend\nlocal system_action_loop = {}\nsystem_action_loop[Script.system.ACTIONS.BRAKE] = function()\n system.print(\"I'm still braking\");\nend\n\n--Function to run when input text to the lua chat\nlocal system_inputText = function (text)\n system.print(\"Input: \" .. text)\nend\n\n--Function to run when the program is stopping\nlocal unit_onstop = function ()\n system.print(\"Program is stopping\")\nend\n\n--Function to run when the player change parent\nlocal player_onparentchanged = function (oldParent, newParent)\n system.print(\"Player changed parent from ID \"..oldParent..\" to ID \"..newParent)\nend\n\n--Function to run when the construct is docked or undocked\nlocal construct_onDocked = function(id)\n system.print(\"Construct docked on ID \"..id)\nend\nlocal construct_onUndocked = function(id)\n system.print(\"Construct undocked from ID \"..id)\nend\n\n--Function to run when a player board the construct\nlocal construct_onplayerboarded = function(id)\n system.print(\"Player with ID \" .. id .. \" boarded construct\")\nend\n\n--Function to run when a player enter the VR Station\nlocal construct_vrstationentered = function(id)\n system.print(\"Player with ID \" .. id .. \" entered VR Station\")\nend\n\n--Function to run when another construct is docked on this construct\nlocal construct_constructdocked = function(id)\n system.print(\"Construct with ID \" .. id .. \" docked on this construct\")\nend\n\n--Function to run when pvp timer is changing state\nlocal construct_onpvptimer = function(active)\n if active then\n system.print(\"PVP is now active\")\n else\n system.print(\"PVP is now inactive\")\n end\nend\n\n--[[\n Here how to load the functions in the framework\n]]\nScript.system:onUpdate(system_update) --loading coroutines for system > onUpdate\nScript.system:onFlush(system_flush) --loading coroutines for system > onFlush\n\nScript.system:onActionStart(system_action_start) --loading all \"actionStart\" functions\nScript.system:onActionStop(system_action_stop) --loading all \"actionStop\" functions\nScript.system:onActionLoop(system_action_loop) --loading all \"actionLoop\" functions\n\nScript.system:onInputText(system_inputText) --loading the function to trigger when input text in lua chat\n\nScript.unit:setTimer(\"hello\", 1, function()system.print(\"hello\")end) --add a timer displaying \"hello\" every seconds\nScript.unit:setTimer(\"hello5\", 5, function()system.print(\"hello 5\")end) --add a timer displaying \"hello 5\" every 5 seconds\nScript.unit:onStop(unit_onstop) --loading the function to trigger when the program is stopping\n\nScript.player:onParentChanged(player_onparentchanged) --loading the function to trigger when the player change parent\n\nScript.construct:onDocked(construct_onDocked) --loading the function to trigger when the construct is docked\nScript.construct:onUndocked(construct_onUndocked) --loading the function to trigger when the construct is undocked\nScript.construct:onPlayerBoarded(construct_onplayerboarded) --loading the function to trigger when a player board the construct\nScript.construct:onVRStationEntered(construct_vrstationentered) --loading the function to trigger when a player enter the VR Station\nScript.construct:onConstructDocked(construct_constructdocked) --loading the function to trigger when another construct is docked on this construct\nScript.construct:onPvPTimer(construct_onpvptimer) --loading the function to trigger when pvp timer is changing state","filter":{"args":[],"signature":"onStart()","slotKey":"-1"},"key":"0"}],"methods":[],"slots":{"0":{"name":"slot1","type":{"events":[],"methods":[]}},"1":{"name":"slot2","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-5":{"name":"library","type":{"events":[],"methods":[]}},"-4":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"player","type":{"events":[],"methods":[]}},"-2":{"name":"construct","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}}}}
+1-1
source/unit/onStart.lua
···280280--[[
281281 You can declare here all the functions you want to call in the diffent events from system, unit, player and construct.
282282 Major changes compared to the base game concept:
283283- - System onUpdate and onFlush events are now builded with coroutines, in the framework, onUpdate and onFlush are loading a table of functions that will be runned as coroutines. This way you can have multiple functions running at the same time, and you use the yield function to pause the coroutine and let the other coroutines run. Each coroutine will be resume or restarted if dead each time the system onUpdate or onFlush event is called.
283283+ - System onUpdate and onFlush events are now built with coroutines, in the framework, onUpdate and onFlush are loading a table of functions that will be runned as coroutines. This way you can have multiple functions running at the same time, and you use the yield function to pause the coroutine and let the other coroutines run. Each coroutine will be resume or restarted if dead each time the system onUpdate or onFlush event is called.
284284285285]]
286286