193 posts
Posted 08 April 2012 - 12:06 AM
In read() function there is tHistory.
But I dont understand what it does.
So I have read("*", SOMETHING)
What is that something?
193 posts
Posted 08 April 2012 - 12:20 AM
This was answered.
Answer: It provides a history table of commands.
So I could press up and get that last word I put in
378 posts
Location
In the TARDIS
Posted 08 April 2012 - 01:27 AM
This was answered.
Answer: It provides a history table of commands.
So I could press up and get that last word I put in
Sry If that sounds noobish but how do I call that history? I didn't even know that this function exists ;D
1604 posts
Posted 08 April 2012 - 01:38 AM
tHistory is an optional parameter, it's the input history to use. So when you press the up/down arrows it shows you the previous input.
When you type commands in the CraftOS shell, it saves them and you can press up to see the last command you used. That's the tHistory parameter in action :P/>/>
It has to be a table containing the text, something like this:
local tHistory = {
"Line1",
"Line2",
"copy disk/startup startup",
"etc."
}
local input = read(nil, tHistory)
378 posts
Location
In the TARDIS
Posted 08 April 2012 - 01:42 AM
OK So I could do something like this:
local History = {}
if History[0] == nil then
text = read()
table.insert(History, text)
else
text = read("", History)
end
1604 posts
Posted 08 April 2012 - 02:50 AM
Yes, but it's not necesary to check if it's empty, it will work if it is. So you can do it like:
local history = {}
while true do
local text = read(nil, history) -- nil for the replacement character, so it doesn't replace the text
table.insert(history, text)
do_something(text)
end
Wich is much like the shell loop works (with a little bit more of code to run programs :P/>/>)
378 posts
Location
In the TARDIS
Posted 08 April 2012 - 10:08 AM
Nice thanks for your help! +1 For you