This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
CRUGG's profile picture

Arguments

Started by CRUGG, 26 March 2018 - 04:55 PM
CRUGG #1
Posted 26 March 2018 - 06:55 PM
How do I code arguments.

I want to code for e.g. apt install nano

I want to code it like this:


if arg1 = "install" then
	if arg2 = "nano" then
		...
	end
else if arg1 = "remove" then
	if arg2 = "nano" then
		...
	end
else
print("...")
end

But how can I save the arguments into variables?
KingofGamesYami #2
Posted 27 March 2018 - 04:40 AM

local arg1, arg2, arg3 = ...

https://www.lua.org/pil/5.2.html
Edited on 27 March 2018 - 02:41 AM
CRUGG #3
Posted 27 March 2018 - 08:48 AM

local arg1, arg2, arg3 = ...

https://www.lua.org/pil/5.2.html
I know how to make a variable, I want to know what to put behind the '='. And your link doesn't help me as well…
SquidDev #4
Posted 27 March 2018 - 09:08 AM
I know how to make a variable, I want to know what to put behind the '='. And your link doesn't help me as well…
Literally just
Edited on 27 March 2018 - 07:08 AM
CRUGG #5
Posted 27 March 2018 - 09:29 AM
I know how to make a variable, I want to know what to put behind the '='. And your link doesn't help me as well…
Literally just
Thanks. But now I get the following message when launching my program:
bios.lua:14: [string "test"]:3: 'then' expected.
In line 3 there's:
if arg1 = "Test" then
SquidDev #6
Posted 27 March 2018 - 09:31 AM
In line 3 there's:
if arg1 = "Test" then
You need to use double equals. So your code should read:

if arg1 == "Test" then
Most languages use a single equal sign for assignment, and two for equality tests. It's a bit odd, but makes sense when you consider the history of it.
CRUGG #7
Posted 27 March 2018 - 09:35 AM
In line 3 there's:
if arg1 = "Test" then
You need to use double equals. So your code should read:

if arg1 == "Test" then
Most languages use a single equal sign for assignment, and two for equality tests. It's a bit odd, but makes sense when you consider the history of it.

Big thanks. The equal sign was the problem. I got a bit confused from too many programing languages inside of my head. :lol:/>
Edited on 27 March 2018 - 07:35 AM