Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- * creates a temporary file to store edited settings which is renamed once the original config.ini file has been removed! * --
- function save_ini()
- -- * locals * --
- local newIniFilename = 'config.ini.bak'
- local newIniFile = io.open(newIniFilename, 'w')
- local fullscreen = getObject('Conditions[fullscreen?]'):getBool(VConditionValue)
- local subtitles = getObject('Conditions[subtitles?]'):getBool(VConditionValue)
- local resolution = getObject('Values[resolution?]'):getInt(VValueInt)
- local language = getObject('Values[language?]'):getInt(VValueInt)
- -- * convert resolution integer into a string * --
- local res_str = 0
- if resolution == 1 then res_str = '1024x768'
- else
- if resolution == 2 then res_str = '1280x1024'
- else
- if resolution == 3 then res_str = '1680x1050'
- else
- if resolution == 4 then res_str = '1920x1080'
- end end end end
- -- * convert language integer into a string * --
- local lang_str = 0
- if language == 0 then lang_str = 'English'
- else
- if language == 1 then lang_str = 'German'
- else
- if language == 2 then lang_str = 'Spanish'
- end end end
- -- * write the data file * --
- newIniFile:write('File = config_ini_v5.ved\n')
- -- * write the comments for fullscreen section! * --
- newIniFile:write('# Fullscreen = {Yes|No}\n')
- newIniFile:write('# Yes - starts the game in fullscreen\n')
- newIniFile:write('# No - starts the game in a window\n')
- if fullscreen then
- newIniFile:write('Fullscreen = Yes\n')
- -- * write comments for the resolution section! * --
- newIniFile:write('#\n')
- newIniFile:write('# Resolution = {Auto|Desktop|Custom}\n')
- newIniFile:write('# Auto - wide-screen support is activated if a wide-screen display is detected\n')
- newIniFile:write('# Desktop - current desktop resolution is used when game is started in full screen mode\n')
- newIniFile:write('# Custom - enter a custom value eg: Resolution = 1920x1080\n')
- newIniFile:write('Resolution = Auto\n')
- else
- newIniFile:write('Fullscreen = No\n')
- -- * write comments for the resolution section! * --
- newIniFile:write('#\n')
- newIniFile:write('# Resolution = {Auto|Desktop|Custom}\n')
- newIniFile:write('# Auto - wide-screen support is activated if a wide-screen display is detected\n')
- newIniFile:write('# Desktop - current desktop resolution is used when game is started in full screen mode\n')
- newIniFile:write('# Custom - enter a custom value eg: Resolution = 1920x1080\n')
- newIniFile:write('Resolution = ' .. res_str .. '\n')
- end
- -- * write comments for the subtitles section! * --
- newIniFile:write('#\n')
- newIniFile:write('# Subtitles = {Yes|No}\n')
- newIniFile:write('# Yes - show subtitles during the game and videos\n')
- newIniFile:write('# No - don\'t show subtitles during the game and videos\n')
- if subtitles then
- newIniFile:write('Subtitles = Yes\n')
- else
- newIniFile:write('Subtitles = No\n')
- end
- -- * write comments for the language section! * --
- newIniFile:write('#\n')
- newIniFile:write('# Language = {English|German|Spanish}\n')
- newIniFile:write('# this will display subtitles in the specified language and will play the appropriate voice sample if available\n')
- newIniFile:write('# default voice samples are in English\n')
- newIniFile:write('Language = ' .. lang_str .. '\n')
- -- * write comments for log section! * --
- newIniFile:write('#\n')
- newIniFile:write('# LogLevel = {Info|Warning|Error}\n')
- newIniFile:write('LogLevel = Error\n')
- -- * write comments for volume section! * --
- newIniFile:write('#\n')
- newIniFile:write('# MusicVolume|SoundVolume|SpeechVolume = int value {0-100}\n')
- -- * close the ini file! * --
- newIniFile:close()
- -- * rename config.ini.bak to config.ini! * --
- if os.rename(newIniFilename, 'config.ini') then
- print(newIniFilename .. ' was sucessfully renamed to config.ini!')
- print('saving new settings to config.ini!')
- else
- print('renaming ' .. newIniFilename .. ' to config.ini was unsuccessful!')
- end
- -- * print various statements to the log file! * --
- if fullscreen then
- print('fullscreen has been set to on!')
- print('resolution has been set to auto!')
- else
- print('fullscreen has been set to off!')
- print('resolution has been set to ' .. res_str .. '!')
- end
- if subtitles then
- print('subtitles have been set to on!')
- else
- print('subtitles have been set to off!')
- end
- print('language has been set to ' .. lang_str .. '!')
- print('new settings have successfully been saved to config.ini!')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement