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

Program with multiple different functions/arguements

Started by MindArkantos, 02 February 2015 - 10:39 PM
MindArkantos #1
Posted 02 February 2015 - 11:39 PM
I am in the process of making a program to write a fancy todo list, but I cannot seem to find any documentation on how to do what I'm trying to do. I want to be able to just go "ToDo Add "Finish Program"" or "ToDo Remove "Finish Program""

I have no idea how to being with this sort of endeavor any help would be appreciated.
KingofGamesYami #2
Posted 03 February 2015 - 02:13 AM
Perhaps you could explain what you want to accomplish here - arguments are easy enough.


local tArgs = { ... }
if tArgs[ 1 ]:lower() == "add" then
  --#bla bla bla
else
  --#other stuff
end

If you want a program that can remember arguments from previous runs, you'll want to look into files, specifically the fs api.
Bomb Bloke #3
Posted 03 February 2015 - 05:41 AM
Tables, too. You'll certainly want to understand those.

It's difficult to comment without knowing your levels of knowledge or experience. Seeing some of your past code (or your attempts so far at writing this code) would help there.
lifewcody #4
Posted 03 February 2015 - 06:12 AM
Perhaps you could explain what you want to accomplish here - arguments are easy enough.


local tArgs = { ... }
if tArgs[ 1 ]:lower() == "add" then
  --#bla bla bla
else
  --#other stuff
end

If you want a program that can remember arguments from previous runs, you'll want to look into files, specifically the fs api.

To add on to that:


local tArgs = { ... }

local file = fs.open("todo", "r")
todo = textutils.unserialize(file.readAll())
file.close()

if tArgs[ 1 ]:lower() == "add" then
  table.insert(todo, tArgs[2])
end

local file = fs.open("todo", "w")
file.write(textutils.serialize(file.readAll())
file.close()


Just came up with that, test it and let me know if it works :)/>