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

Help in config files

Started by MailoStudios, 23 January 2014 - 01:15 PM
MailoStudios #1
Posted 23 January 2014 - 02:15 PM
i Need helpi will integrate my config file in my os
the Problem is the config is integrated, but the text in the config is not written in the Programm here the code:

--Function to load APIs + Language Package
os.loadAPI("/Volumes/M_System/System/Components/fLib")
slc = 0
lang = fs.open("/Volumes/M_System/System/Packages/language/de_de.lang", "r")
Rlang = lang.readAll()
lang.close()
term.clear()
function load()
background()
loginui()
end
function background()
term.setBackgroundColor(512)
term.clear()
term.setCursorPos(51,19)
write("M")
end
function shutdownmenu()
term.setBackgroundColor(1)
term.setTextColor(colors.black)
term.setCursorPos(38,17)
print(Rlang.loginshutdownbutton)
term.setCursorPos(38,18)
print("Neustarten     ")
term.setCursorPos(38,19)
write("             M")
slc = 1
end
function loginui()
term.setCursorPos(15,7)
term.setBackgroundColor(colors.gray)
term.setTextColor(colors.white)
print("X | Login Interface")
term.setCursorPos(15,8)
term.setBackgroundColor(1)
term.setTextColor(colors.black)
print("                   ")
term.setCursorPos(15,9)
print(" Benutzername:     ")
term.setCursorPos(15,10)
print("                   ")
term.setCursorPos(15,11)
print(" Passwort:         ")
term.setCursorPos(15,12)
print("                   ")
term.setCursorPos(15,13)
print("                   ")
term.setCursorPos(16,10)
term.setBackgroundColor(128)
print("                ")
term.setCursorPos(16,12)
print("                ")
term.setCursorPos(1,1)
term.setBackgroundColor(512)
term.setTextColor(1)
print("OS Created by MailoStudios | Version 1.0 Pre-Release")
end
load()
while true do
 local event, button, X, Y = os.pullEventRaw()
 if event == "mouse_click" then
  if slc == 0 then
   if X>=16 and X<=31 and Y==10 and button ==1 then
    term.setBackgroundColor(256)
    term.setCursorPos(16,10)
    print("                ")
    term.setCursorPos(16,10)
    input1 = read()
    if input1 == "" then
    term.setCursorPos(16,10)
    print("Falsch!")
    sleep(2)
    load()
    end

    if fs.exists(dont see that) then

    else
    term.setCursorPos(16,10)
    print("Falsch!")
    sleep(2)
    load()
    end
   elseif X>=16 and X<=31 and Y==12 and button ==1 then slc = 0
   term.setBackgroundColor(256)
   term.setCursorPos(16,12)
   print("                ")
   term.setCursorPos(16,12)
   input2 = read("*")
    if input2 == "" then
    term.setCursorPos(16,12)
    print("Falsch!")
    sleep(2)
    load()
    end

    if fs.exists(dont see that) then
    fLib.replaceLine("/Volumes/M_System/System/Desktop.lua",1,'loggeduser = "'..input1..'"')
    shell.run("/Volumes/M_System/System/Desktop.lua")
    else
    term.setCursorPos(16,12)
    print("Falsch!")
    sleep(2)
    load()
    end
   elseif X>=51 and X<=51 and Y==19 and button ==1 then
   shutdownmenu()
   slc = 1
   end
  elseif slc == 1 then
   if X==51 and Y==19 and button==1 then
   load()
   slc = 0
   elseif X>=38 and X<=51 and Y==17 and button==1 then
   term.setBackgroundColor(colors.gray)
   term.setTextColor(1)
   term.setCursorPos(38,17)
   write("Herunterfahren")
   sleep(0.3)
   shell.run("/Volumes/M_System/System/.shutdown")
   elseif X>=38 and X<=51 and Y==18 and button==1 then
   term.setBackgroundColor(colors.gray)
   term.setTextColor(1)
   term.setCursorPos(38,18)
   write("Neustarten    ")
   sleep(0.3)
   shell.run("/Volumes/M_System/System/.reboot")
   end
  end
 end
end
Edited on 23 January 2014 - 01:17 PM
wieselkatze #2
Posted 23 January 2014 - 02:58 PM
I assume your config is written in the textutils.serialize 'style'?
Then you should rewrite line 5, should be
Rlang = textutils.unserialize(lang.readAll())
MailoStudios #3
Posted 23 January 2014 - 03:14 PM
Here is the config file:
--mlogon.lua
loginshutdownbutton = "Herunterfahren"
loginrebootbutton = "Neustarten     "
loginusername = "Benutzername:"
loginpassword = "Passwort:"
--Desktop.lua
programbutton = "Programme"
systembutton = "System"
mshutdown = "Herunterfahren"
mreboot = "Neustarten"
mstandby = "Ruhezustand"
mcraftos = "Craft OS Shell"
programtitle = "Programme"
programsystemtitle = "System Programme"
programsystemsettings = "Einstellungen"
programsystemconfiguration = "Konfiguration"
programsystemstore = "Mailo OS Store"
programsystemrepairmode = "Repair Mode"
programsystemdeleteos = "Delete Mailo OS"
programsystemupdate = "Update Center"
programsystemcraftos = "CraftOS Shell (CC)"
programsupportedtitle = "Unterstützte Programme"
programfirewolf = "Firewolf"
programmsf = "Mouse File Browser"
programmore = "Weitere Programme"
systemsettings = "Einstellungen"
systemconfiguration = "Konfiguration"
systemstore = "MailoOS Store"
systemrepairmode = "Repair Mode"
systemdeleteos = "Delete MailoOS"
Lyqyd #4
Posted 23 January 2014 - 03:18 PM
Rlang = lang.readAll() just puts the entire file contents into the Rlang variable. It's just one big multi-line string.
MailoStudios #5
Posted 23 January 2014 - 03:30 PM
and how do I take a particular line
OReezy #6
Posted 23 January 2014 - 03:45 PM
readLine() will give you the next line in the file.
Edited on 23 January 2014 - 02:45 PM
MailoStudios #7
Posted 23 January 2014 - 04:30 PM
and how can I take a specific value from the config
CometWolf #8
Posted 23 January 2014 - 04:51 PM
use string.match()
The following should do the trick, based on the file you posted. If you're interested in how this works, you can read up on it here.

local value = string.match'^%S+ = "(.+)"'
http://lua-users.org...LibraryTutorial
and here http://lua-users.org...atternsTutorial
Edited on 23 January 2014 - 03:51 PM