Jump to content




Commands


  • You cannot reply to this topic
3 replies to this topic

#1 cptdeath58

  • Members
  • 139 posts
  • LocationError 404: Could not find.

Posted 09 July 2014 - 10:30 PM

I need help with the part of identifying if args was given or not.
It's at the "Stop" command
Spoiler
if anyone can help, I'll appreciate it.

Edited by cptdeath58, 09 July 2014 - 10:31 PM.


#2 Emma

  • Members
  • 216 posts
  • Locationtmpim

Posted 09 July 2014 - 11:51 PM

I think this is what you are asking for:
if args~=nil then --Could also be written if args then
--watever
end


#3 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 11 July 2014 - 03:25 PM

View Postincinirate, on 09 July 2014 - 11:51 PM, said:

I think this is what you are asking for:
if args~=nil then --Could also be written if args then
--watever
end
Nope. args will always be a string. If the :match call finds no arguments, it'll be an empty string.
if args == "" then ...

EDIT: I would use " *(.*)" (space and dash) in the pattern instead of " ?(.*)" (space and question mark) so if there's a command like "/heck ", args won't be full of whitespaces.

Actually, this is the way I usually parse command lines (if the command always begins with a forward slash):
local words = {}
for word in input:gmatch("[^/%s]+") do table.insert(words, word) end
if words[1]:lower() == "stop" then ...

Edited by LBPHacker, 11 July 2014 - 03:33 PM.


#4 cptdeath58

  • Members
  • 139 posts
  • LocationError 404: Could not find.

Posted 11 July 2014 - 11:14 PM

Thanks, You helped me alot!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users