#1
Posted 26 January 2014 - 12:29 AM
#2
Posted 26 January 2014 - 02:15 AM
local FileList = fs.list("")
term.clear()
term.setCursorPos(1,1)
local counter = 0
for _, file in ipairs(FileList) do
if counter % 2 == 0 then
term.setTextColor(colors.blue) -- even lines
else
term.setTextColor(colors.pink) -- odd lines
end
print(file)
counter = counter+1
end
term.setTextColor(colors.white)
As counter increments, counter % 2 will give the remainder of counter / 2. Essentially, it will be either 0 (even) or 1 (odd). Then the conditional statement in the if control structure will allow us to change the text color accordingly. I started counter at 0, so the first line will be considered even and print in blue in my example. Odd lines will print in pink. I reset the text color to white at the end of the program.
The example I gave above makes the most sense from a the perspective of trying to wrap your brain around the logic, however, you could do the same thing without an if ... else control structure like this:
local FileList = fs.list("")
term.clear()
term.setCursorPos(1,1)
local counter = 0
local color = {colors.blue,colors.pink}
for _, file in ipairs(FileList) do
term.setTextColor(color[(counter % 2) +1])
print(file)
counter = counter+1
end
term.setTextColor(colors.white)
As for the paint.api and pastebin, I got nothing. Somebody else will have to address that.
Edited by surferpup, 26 January 2014 - 02:42 AM.
#3
Posted 26 January 2014 - 11:33 AM
#4
Posted 26 January 2014 - 10:50 PM
Edited by ClassicRockFan, 26 January 2014 - 11:04 PM.
#5
Posted 26 January 2014 - 11:20 PM
- A while loop to capture up, down and enter key events
- On an up or down key event, you would need to know what position you are on the screen and move the highlight text accordingly, essentially reprinting the file on that line in the correct color and highlight. You could also update an informational section on the screen giving more info about that file. As for information what type of file, you would probably have to use file extensions (because all files are text based, and lua code files often aren't given the .lua extension).
- If enter is pressed and the highlight is on a directory, change directories and repaint the screen with the new directory.
- You might need to make the first file in a directory listing ".." which would indicate the user wants to go up a directory level.
I did a bunch of user interface work on my Tank Building Turtle code. Take a look at it and steal liberally from whatever is useful. It handles the cursor keys and enter key, changing highlights and reprinting sections of the User Interface. It would probably be helpful to you to tear it apart a bit.
If what I have posted is useful to you (here and above), please vote up each useful post.
Let me know if that gets you started.
Edited by surferpup, 26 January 2014 - 11:26 PM.
#6
Posted 26 January 2014 - 11:39 PM
Edited by ClassicRockFan, 26 January 2014 - 11:40 PM.
#7
Posted 26 January 2014 - 11:48 PM
The startup program correctly downloaded your three files and executed your desktop correctly.
Nice start to your project!
#8
Posted 26 January 2014 - 11:57 PM
Edited by ClassicRockFan, 27 January 2014 - 12:01 AM.
#9
Posted 27 January 2014 - 12:01 AM
ClassicRockFan, on 26 January 2014 - 11:57 PM, said:
Not quite sure what you are saying here.
Edited by surferpup, 26 January 2014 - 11:59 PM.
#10
Posted 27 January 2014 - 12:03 AM
Edited by ClassicRockFan, 27 January 2014 - 12:08 AM.
#11
Posted 27 January 2014 - 12:05 AM
Edited by surferpup, 27 January 2014 - 12:05 AM.
#12
Posted 27 January 2014 - 12:09 AM
#13
Posted 27 January 2014 - 12:12 AM
For ex.
defaultDesktopBackground = colors.white defaultDesktopText = colors.blue defaultTitleBarBackground = colors.lightBlue defaultTitlebarText = colors.white defaultErrorBackground = colors.black defaultErrorText = colors.red ..and so on
Make sure to use these variables everywhere you set color. That way, if you change your color schema, you only change it in one place -- in the declarations section.
#14
Posted 27 January 2014 - 12:14 AM
#15
Posted 27 January 2014 - 12:21 AM
ClassicRockFan, on 27 January 2014 - 12:09 AM, said:
Sure -- just monitor a click event in addition to the key event.
For example:
while true do local event, arg = os.pullEvent() if event == "mouse_click" and arg == 2 then break elseif event =="key" then if arg == 200 or key == 208 then rolllDirectory(arg) elseif key == 28 then doEnterKeyThing() end end end goBackToWherever(indexNumber)
Does that make sense? The rollDirectory function would handle both up and down keys (it is essentially the same function), so you just pass it the key value as arg. The doEnterKeyThing(indexNumber) would be whatever that is for you, with indexNumber being the current line the highlight is on so it can use that line as a reference. The goBackToWherever() would be getting out of the file list and probably back to the desktop.
Edit: fixed syntax error in my example. And another one. Also, expanded on doEnterKeyThing function.
Edited by surferpup, 27 January 2014 - 12:39 AM.
#16
Posted 27 January 2014 - 12:45 AM
Edited by ClassicRockFan, 27 January 2014 - 12:53 AM.
#17
Posted 27 January 2014 - 12:49 AM
This is what I did:
rm login rm .background rm .icon pastebin get Svskf6By startup startup
This was the startup code:
if fs.exists("login") then
shell.run("login")
else
shell.run("pastebin get 6SJkMMT4 login")
shell.run("pastebin get KaTiSRhy .icon")
shell.run("pastebin get HFYY1efQ .background")
shell.run("login")
end
Edited by surferpup, 27 January 2014 - 12:52 AM.
#18
Posted 27 January 2014 - 12:51 AM
Edited by ClassicRockFan, 27 January 2014 - 12:56 AM.
#19
Posted 27 January 2014 - 12:56 AM
Do you have access to the server in question? Is this running on your desktop? If so, just use a text editor (or ssh into a server and use nano or some other editor). Create the stuff in your text editor and save it to the saves/world/computer/<computerNumber>/<programName>
I guess what I am saying is that while you are developing, do as much of it locally as possible. Add the pastebin features last.
Edited by surferpup, 27 January 2014 - 01:00 AM.
#20
Posted 27 January 2014 - 01:01 AM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











