Advertisement
AFRLme

Read from config.ini [VS] (works)

Nov 4th, 2012
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.89 KB | None | 0 0
  1. -- * globals * -- (used by read_ini and delete_ini)
  2. local iniFilename = 'config.ini'
  3. local iniFile = io.open(iniFilename, 'r')
  4.  
  5. -- * retrieves game settings from config.ini + sets condit‭ions | values appropriately! * --
  6. function read_ini()
  7.  
  8. -- * locals * --
  9. local r_fullscreen = getObject('Scenes[Options_Menu].SceneConditions[fullscreen?]')
  10. local r_subtitles = getObject('Scenes[Options_Menu].SceneConditions[subtitles?]')
  11. local r_resolution = getObject('Scenes[Options_Menu].SceneValues[resolution?]')
  12. local r_language = getObject('Scenes[Options_Menu].SceneValues[language?]')
  13.  
  14. -- * script * --
  15.  if iniFile then
  16.  local line = iniFile:read()
  17.  print(iniFilename .. ' exists!')
  18.  print('retrieving settings from ' .. iniFilename .. '!')
  19.  for line in io.lines(iniFilename) do
  20. -- * begin if else * --
  21.   if line == 'Fullscreen = No' then
  22.    r_fullscreen:setValue(VConditionValue, false)
  23.    print('fullscreen mode is off!')
  24.   else
  25.   if line == 'Fullscreen = Yes' then
  26.    r_fullscreen:setValue(VConditionValue, true)
  27.    print('fullscreen mode is on!')
  28.   end end
  29. -- * --
  30.   if line == 'Resolution = Auto' then
  31.    r_resolution:setValue(VValueInt, 0)
  32.    print('resolution is set to auto!')
  33.   else
  34.   if line == 'Resolution = 1920x1080' then
  35.    r_resolution:setValue(VValueInt, 4)
  36.    print('resolution is currently set at 1920x1080!')
  37.   else
  38.   if line == 'Resolution = 1680x1050' then
  39.    r_resolution:setValue(VValueInt, 3)
  40.    print('resolution is currently set at 1680x1050!')
  41.   else
  42.   if line == 'Resolution = 1280x1024' then
  43.    r_resolution:setValue(VValueInt, 2)
  44.    print('resolution is currently set at 1280x1024!')
  45.   else
  46.   if line == 'Resolution = 1024x768' then
  47.    r_resolution:setValue(VValueInt, 1)
  48.    print('resolution is currently set at 1024x768!')
  49.   end end end end end
  50. -- * --
  51.   if line == 'Subtitles = No' then
  52.    r_subtitles:setValue(VConditionValue, false)
  53.    print('subtitles are currently set to off!')
  54.   else
  55.   if line == 'Subtitles = Yes' then
  56.    r_subtitles:setValue(VConditionValue, true)
  57.    print('subtitles are currently set to on!')
  58.   end end
  59. -- * --
  60.   if line == 'Language = English' then
  61.    r_language:setValue(VValueInt, 0)
  62.    print('Language is currently set to English!')
  63.   else
  64.   if line == 'Language = German' then
  65.    r_language:setValue(VValueInt, 1)
  66.    print('Language is currently set to German!')
  67.   else
  68.   if line == 'Language = Spanish' then
  69.    r_language:setValue(VValueInt, 2)
  70.    print('Language is currently set to Spanish!')
  71.   end end end
  72. -- * --
  73.   end
  74.    iniFile:close()
  75.    print('successfully retrieved settings from ' .. iniFilename .. '!')
  76. -- * end if else * --
  77.  else
  78.   print(iniFilename  .. ' does not exist!')
  79.  end
  80. end
  81.  
  82. -- * removes the config.ini file so we can replace it with the temporary file! (only called if we have edited any of the settings) * --
  83. function delete_ini()
  84. if iniFile then
  85.  os.remove(iniFilename)
  86. else
  87. end
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement