What do you want to achieve? Ingame code creation with custom commands.
What is the issue? It doesnt get through the if statements
function run(code)
for line in code:gmatch("([^\n]*)\n?") do
local args = split(line)
if args[1] == 'print' then
local splitData = {splitByChar(args[2])}
if splitData[1] == [[']] then
print('as')
if splitData[#splitData-1] == [[']] then
print('as')
local text = args[2]
text = text:gsub([[']],'')
print(text)
end
end
if splitData[1] == [["]] then
print('as')
if splitData[#splitData-1] == [["]] then
print('as')
local text = args[2]
text = text:gsub([["]],'')
print(text)
end
end
end
end
end
function split(lineOfCode)
local args = {}
for word in string.gmatch(lineOfCode,[[([^(),]+)]]) do
table.insert(args,#args+1,word)
end
return args
end
function splitByChar(str)
local r = {}
for a = 1, string.len(str)+1 do
table.insert(r,#r+1,string.sub(str,a,a))
end
return r
end
game:GetService('ReplicatedStorage'):FindFirstChild('RunCode').OnServerEvent:Connect(function(plr,code)
run(code)
end)
You can run custom code during a game using the loadstring method. It allows you create and run code during a game. Here is an already existing post that I’m sure answers your question.
I would assume you need to use loadstring however, allowing loadstring in settings makes your game easier to hack. I would recommend avoiding that, If you hit f9 and then hit the server button you can run commands without loadstring.
You created a new table with the first element as a table created by the splitting the string. You don’t need the extra {}.
local splitData = splitByChar(args[2])
Is there any particular reason for this over str:split("")?
You need to create a lexer and a parser for this as it looks like you’re trying to create a simple programming language. e.g. tokenise the code. e.g. print("hello world") into
Are statements terminated just by line breaks? Is semicolon to terminate a statement in the code allowed?
Are whitespaces between parenthesis allowed?
Is var required to declare a variable, or int var1 = 50 is just fine? And about int, is it 32-bit, 64-bit or arbitary precision? Is it statically typed or dynamically typed or both?
Is there any reason for braces after then over if (bool) {} or if bool then end? Is then required?
What are the reserved keywords? Same as Lua 5.1?
Are functions also first class like Lua? Can I assign kill, teleport and randomPlr to another value?
Is there anything else aside from functions, variables and if statements? Operators? Metatables?
Is the code creation only available to you or certain users, or is it available to everyone?
May I ask, why do you need this for admin commands?
Are statements terminated just by line breaks? Is semicolon to terminate a statement in the code allowed? Currently line breaks but I might change it to semicolons.
Are whitespaces between parenthesis allowed? Yes.
Isvarrequired to declare a variable, orint var1 = 50is just fine? It is required to declare a variable. If it is a var its read and write. If its a const it cant be written to after declaring the variable
And about int , is it 32-bit, 64-bit or arbitary precision? 64-bit
Is it statically typed or dynamically typed or both? Statically typed.
Is there any reason for braces afterthenoverif (bool) {}orif bool then end? Isthenrequired? Then was just a idea but I think I dont want it.
What are the reserved keywords? Same as Lua 5.1? Same as lua 5.1.
Are functions also first class like Lua? Yes.
Can I assignkill,teleportandrandomPlrto another value? Yes.
Is there anything else aside from functions, variables and if statements? Operators? Metatables? Yes. Operators.
Is the code creation only available to you or certain users, or is it available to everyone? There will be a game with a limited version of it like a free admin commands game and I will use the not limited version on my games as admin commands.
May I ask, why do you need this for admin commands? More powerful then normal chat admin commands.