local inp = read()
and the user would enter "/hi".
How would I check if the first character of the string is a slash, (/) and if so, not do anything?
Thanks
- Mackan
local inp = read()
if(string.sub(read(),1,1) == "/") then
--# don't do anything?
else
--# do something?
end
if(string.sub(read(),1,1) == "/") then --# don't do anything? else --# do something? end
you can replace the read() with your local variable obviously ;)/>
function input()
while true do
_, p1 = os.pullEvent("key")
if(p1 == 28) then
local inp = read()
if(string.sub(inp, 1,5) == "/nick") then
if(string.len(string.sub(inp, 6)) >= 1) then
local np = string.sub(inp, 7)
send(name.." is now known as "..np)
name = np
elseif(string.sub(inp, 1,3) == "/me") then
send("* "..name.." "..string.sub(inp, 4))
elseif(string.sub(inp, 1,1) == "/") then
end
else
send("<" .. name .. "> "..inp)
end
end
end
end
string.sub(var,1,1)
tovar:sub(1,1)
Spoiler
if(string.sub(read(),1,1) == "/") then --# don't do anything? else --# do something? end
you can replace the read() with your local variable obviously ;)/>
Well, I have this herefunction input() while true do _, p1 = os.pullEvent("key") if(p1 == 28) then local inp = read() if(string.sub(inp, 1,5) == "/nick") then if(string.len(string.sub(inp, 6)) >= 1) then local np = string.sub(inp, 7) send(name.." is now known as "..np) name = np elseif(string.sub(inp, 1,3) == "/me") then send("* "..name.." "..string.sub(inp, 4)) elseif(string.sub(inp, 1,1) == "/") then end else send("<" .. name .. "> "..inp) end end end end
If I input /me or /nick it works, but not line 13..
inp=read()
--//this checks if the line matches "/<cmd>", with optional arguments separated from the
--//command with a space. the ^ and $ just require the pattern to match the whole string,
--//from beginning to end
local cmd,args = imp:match("^/(%w+)%s*(.-)$")
if cmd then
--//cmd will only be "true" if the pattern matched, so here we know we have a command
if cmd=="nick" then
--//args is the new nickname
elseif cmd=="me" then
--//args is the text to pose
else
--unknown command, give error locally
end
else
--//didn't match the cmd pattern, just text to say, so send inp
end