--[[ This was coded in Lua because it's pretty easy to read for most people. I understand Hypixel uses Java, but the logic is pretty much the same across languages. ]] -- Imagine this is the list of functions in a house! local houseFunctions = { foo = { id = "foo", actions = { { action = "message", message = "foo start" }, { action = "trigger_function", func = "bar" }, { action = "trigger_function", func = "bar" }, { action = "trigger_function", func = "baz" }, -- This one causes recursion { action = "message", message = "foo end" }, } }, bar = { id = "bar", actions = {{ action = "message", message = "bar" }}, }, baz = { id = "baz", actions = { { action = "message", message = "baz" }, { action = "trigger_function", func = "foo" } } } } -- simple util func, dont mind it function table.shallow_copy(t) local t2 = {} for k,v in pairs(t) do t2[k] = v end return t2 end -- a container for the top level of action running function startRunActions(functionName) local starterTable = {} starterTable[functionName] = true runActions(houseFunctions[functionName], starterTable) end -- Function Data = the data for the function including id and action list -- Action Data = the data for the current action being ran -- Depth Chain = the chain of functions followed to get to this one function runActions(functionData, depthChain) for i, actionData in ipairs(functionData.actions) do if actionData.action == "message" then print(actionData.message) end if actionData.action == "trigger_function" then -- only if it has not yet been run in this chain will we run it! -- this doesn't account for the 4 tick cooldown exception, but it'd be super easy to implement. if depthChain[actionData.func] == nil then local newDepthChain = table.shallow_copy(depthChain) newDepthChain[actionData.func] = true runActions(houseFunctions[actionData.func], newDepthChain) else print("Attempted recursion was caught and stopped!") end end end end startRunActions("foo")
Write, Run & Share Lua code online using OneCompiler's Lua online compiler for free. It's one of the robust, feature-rich online compilers for Lua language, running the latest Lua version 5.4. Getting started with the OneCompiler's Lua editor is easy and fast. The editor shows sample boilerplate code when you choose language as Lua and start coding.
OneCompiler's Lua online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Lua program which takes name as input and prints hello message with your name.
name = io.read("*a")
print ("Hello ", name)
Lua is a light weight embeddable scripting language which is built on top of C. It is used in almost all kind of applications like games, web applications, mobile applications, image processing etc. It's a very powerful, fast, easy to learn, open-source scripting language.
-- global variables
a = 10
-- local variables
local x = 30
Value Type | Description |
---|---|
number | Represents numbers |
string | Represents text |
nil | Differentiates values whether it has data or not |
boolean | Value can be either true or false |
function | Represents a sub-routine |
userdata | Represents arbitary C data |
thread | Represents independent threads of execution. |
table | Can hold any value except nil |
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while(condition)
do
--code
end
Repeat-Until is also used to iterate a set of statements based on a condition. It is very similar to Do-While, it is mostly used when you need to execute the statements atleast once.
repeat
--code
until( condition )
For loop is used to iterate a set of statements based on a condition.
for init,max/min value, increment
do
--code
end
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increase re-usuability and modularity.
optional_function_scope function function_name( argument1, argument2, argument3........, argumentn)
--code
return params with comma seperated
end