Posted 29 July 2013 - 03:38 PM
Moving along contents in an array
This is the code (Explanation and problem below):
A short programm explanation:
It's a programm where you can write things in it which you'd like to in the future (ToDo-List).
There is a little menu where you choose between 'Add' and 'Remove'
By typing 'add' you can add a new line.
Several of them will look like this example:
The numbers behind the lines only appear when you type 'remove' in the menu.
And here's my problem:
I want that if you type in 'remove' you can choose the sentence (-> number) which should be removed.
Then, the sentence will disappear and sentences which were below move along one line so no free space is there anymore.
I'm saving the sentences in a array, so how do I manage that?
Thanks.
This is the code (Explanation and problem below):
m = peripheral.wrap("top")
punkte = {}
arrayPunkt = 0
function body()
m.clear()
m.setTextColor(colors.white)
m.setTextScale(1)
m.setCursorPos(1,1)
m.write("-------------------------------------------------------------")
m.setCursorPos(1, 26)
m.write("-------------------------------------------------------------")
m.setTextColor(colors.yellow)
m.setCursorPos(16, 1)
m.write("The holy ToDo-List")
end
function setPunkte()
tiefe = 3
for i = 0, table.getn(punkte) do
print (1)
m.setCursorPos(2, tiefe)
m.setTextColor(colors.lime)
m.write("- ")
m.setTextColor(colors.orange)
m.write(punkte[i])
tiefe = tiefe + 2
end
end
function add()
print ("Eingabe: ")
eingabe = read()
punkte[arrayPunkt] = eingabe
arrayPunkt = arrayPunkt + 1
end
function remove()
zeile = 3
m.setTextColor(colors.cyan)
for i = 0, table.getn(punkte) do
m.setCursorPos(47, zeile)
m.write("("..(i+1)..")")
zeile = zeile + 2
end
print ("Numbers have been generated on the screen.")
print (Choose the numbers which you want to be gone:")
number = tonumber(read())
end
while true do
term.setTextColor(colors.orange)
write ("Command: 'add' | 'remove' (WIP): ")
term.setTextColor(colors.white)
com = read()
if com == "add" then
add()
elseif com == "remove" then
remove()
else
print ("Unknown command.")
end
body()
setPunkte()
end
A short programm explanation:
It's a programm where you can write things in it which you'd like to in the future (ToDo-List).
There is a little menu where you choose between 'Add' and 'Remove'
By typing 'add' you can add a new line.
Several of them will look like this example:
The numbers behind the lines only appear when you type 'remove' in the menu.
And here's my problem:
I want that if you type in 'remove' you can choose the sentence (-> number) which should be removed.
Then, the sentence will disappear and sentences which were below move along one line so no free space is there anymore.
I'm saving the sentences in a array, so how do I manage that?
Thanks.