Jump to content




Program arguments

computer lua

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

#1 Ilikemlp123

  • Members
  • 12 posts

Posted 21 April 2016 - 09:38 PM

I need help detecting arguments for a program I'm writing for a server.
I have looked at other programs(and the wiki)to see how but that doesn't work.

#2 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 22 April 2016 - 08:56 AM

post your code so we know how far you have got, use pastebin.com if it's easier

Also, this is not the best example but it works:
full code: http://pastebin.com/LZ7Ks57A
below is just the arg processing
Spoiler

Edited by Lupus590, 22 April 2016 - 09:14 AM.


#3 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 22 April 2016 - 11:47 AM

A smaller easier to read example.

local tArgs = {...}
--#tArgs[1] is the first thing they type after the program name as a string.
--#myProgram hello
--#tArgs[1] is hello
--#It's a string tho, so myProgram 1 wouldn't make that 1 a number.
--#myProgram 1 hello
--#tArgs[1] = "1", tArgs[2] = "hello"
if (tArgs[1] == "hello" ) then
  print("tArgs[1] was hello")
elseif (tonumber(tArgs[1]) ~= nil and tonumber(tArgs[1]) == 1) then
  print("tArgs[1] was the number 1")
end

Edited by Dragon53535, 22 April 2016 - 11:48 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users