Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- directory="/3ds/"
- files = System.listDirectory(directory)
- pad = Controls.read()
- oldpad=pad
- --To make oldpad~=nil
- selected=1
- while true do
- Screen.waitVblankStart()
- Screen.refresh()
- Screen.clear(TOP_SCREEN)
- pad = Controls.read()
- -- The 3ds's top screen is 400x240. 240/16 is 15. If we try and display some text below 240 then we'll get an
- -- error. If #files was 18 or something, the program would try and display some text too low.
- -- With this if statement, we make it so that can't happen.
- if #files<16 then
- --Use Screen.debugPrint to display the name of each file. Uses a for loop so it happens
- --once for each file.
- for i=1, #files do
- -- We need to subtract 16 from i*16 because i starts out at 1 and 1*16 is 16 so the first file would be displayed
- -- one place to low. (Although, we could not subtract 16 and instead write something like "Select a file" at the top)
- Screen.debugPrint(0, i*16-16, files[i].name, Color.new(255,255,255), TOP_SCREEN)
- end
- else
- for i=1, 15 do
- Screen.debugPrint(0, i*16-16, files[i].name, Color.new(255,255,255), TOP_SCREEN)
- end
- end
- --Write the name of the file in green if it's the currently selected file.
- --We also need to do -16 for the y position because the selected variable starts at 1.
- Screen.debugPrint(0, selected*16-16, files[selected].name, Color.new(0,255,0), TOP_SCREEN)
- if pad~=oldpad then
- if Controls.check(pad, KEY_DUP) then
- selected=selected-1
- -- Check if the number for the selected file isn't a valid number.
- -- We need to do this to prevent an error when we do files[selected].name
- if selected>#files or selected<1 then
- selected=1
- end
- elseif Controls.check(pad, KEY_DDOWN) then
- selected=selected+1
- if selected>#files or selected<1 then
- selected=1
- end
- elseif Controls.check(pad,KEY_A) then
- -- Break out of the while loop.
- break
- end
- end
- oldpad=pad
- Screen.flip()
- end
- while true do
- Screen.waitVblankStart()
- Screen.refresh()
- Screen.clear(TOP_SCREEN)
- Screen.debugPrint(0, 0, "The selected file is...", Color.new(255,255,255), TOP_SCREEN)
- Screen.debugPrint(0, 16, (directory .. files[selected].name), Color.new(255,255,255), TOP_SCREEN)
- Screen.flip()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement