I’m trying to make a cmd.exe terminal and trying :print doesn’t work because it’ll just print “:print ”, how do I make it so it removes the “:print” part?
You can gsub
it out: msg:gsub(":print ", "")
I’m trying to make a cmd.exe terminal and trying :print (msg) doesn’t work becuase it’ll just print “:print (msg)”, how do I make it so it removes the “:print” part?
You can use string.split() to split a string at certain characters (like spaces), returns a table of the arguments. Commonly used in admins to get the parameters of the commands.
What do you mean by “detect the print”? You can just use if string.split(stuff goes here) then
to detect if it has :print inside of it. The other stuff behind the print doesn’t need to be used yet.
So is it like this?
You should turn it into a variable so you can tap into it later to get the arguments and join them together, but other than that, yeah
So how would i make it split into the console?
You could just have a table with the commands as the index
local cmds = { -- table to host the commnds
[":print"] = function(...) -- index (name of the command) function (what to do)
-- do stuff
end
}
local msg = ":print hello world!" -- message that they sent
local args = msg:split(" ") -- divide it among spaces
if cmds[args[1]] then -- check the first word (because first arg is suppose to be the command)
local cmd = cmds[args[1]] -- the target command
table.remove(args, 1) -- remove the first argument
cmd(table.unpack(args)) -- do the function with everything else that was sent
end
You can just use string patterns to capture a part of the string:
Here is an example:
local OutputText = string.match(":print Hello World!", "^:print%s+(.*)$")
if OutputText ~= nil then
print(OutputText)
end
--Output
-->Hello World!
local userInputService = game:GetService("UserInputService")
local cmds = {
[":print"] = function(...)
-- do stuff
end
}
userInputService.InputBegan:Connect(function(io, isTyping)
if io.KeyCode ~= Enum.KeyCode.Return then return end
local msg = script.Parent.Text -- basically, just change the default "msg" to the actual message
local args = msg:split(" ")
if cmds[args[1]] then
local cmd = cmds[args[1]]
table.remove(args, 1)
cmd(table.unpack(args))
end
end)
It depends on your system… You can keep cloning a TextLabel over and over again while defining it’s position in a variable (so you can push it downwards, of course) in a ScrollingFrame.
Not related but the Bliss background is copyright of Microsoft so I’d recommend removing that and if you want to make it XP themed, make the titlebar blue. Would also recommend you to change the CMD icon to fit instead of Stretch.
I don’t think you get it, im trying to make it into a cmd.exe, not a simple print.
I do get it but I don’t think you don’t get the fact the fact that the code I posted was an example on showing how string patterns work on a basic level.
I just showed you a possibility, I have no intention to edit the code to make it fit with your system, that’s for you to figure out by trial and error while researching about it.
If I do get a copyright warning I will change it. Its fine for now
I would still change it though to avoid that.