Aye simple enough...
It's Lua script, not java or python or whatever. Semi-colons; are not the same as end. The only reason I use them (rarely) is for defining split sections when I code multiple things on the same line...
print(x + y); print(a + b); if x + y == a + b then print("true") end
Here... (obviously I can't test if it's working or not).
--[[
Read/Write Config.ini [v2] (02/03/2014)
Written by AFRLme [Lee Clarke]
-- + --
alternatingfrequencies@hotmail.com | skype @ AFRLme
-- + --
This script is donation optional. In game credit is non-negotiable.
You are free to: ¹ use it in your game(s). ² modify the script.
Do not remove - or edit - this comment block.
--]]
-- DEFAULT VALUES AS VARIABLES --
local log_level = "Error" -- Writes errors to log-file, other options: Warning & Info
-- FILE NAME VARIABLES --
local filename_of_config_file = "config.ini"
local vis_file_name = "Bunker.vis"
-- OPTION VARIABLES --
local option_is_fullscreen = getObject("Conditions[Fullscreen?]")
local option_sound_volume = getObject("Values[Sfx_volume]")
local option_music_volume = getObject("Values[Music_volume]")
local option_language = game:getLinks(VGameLanguages) -- Puts languages in a table
-- FUNCTION FOR READING INI-FILE --
function read_ini()
local config_file_exist = io.open(localAppDir .. filename_of_config_file, "r") -- true if file was found
if config_file_exist then
-- Prints --
print(filename_of_config_file .. " was found!")
print(filename_of_config_file .. " is now loaded")
-- Read every line on config.ini and change corresponding variable in game to match --
for lines in io.lines(localAppDir .. filename_of_config_file) do
line = string.lower(lines) -- make all lines have only lowercase characters, eliminating problems that might arise with casesensitivity
if not line:find("#") then --incase there is no #-symbol on this line for-sentence may proceed to the next part --
-- Next lines change each variable found from game to match with what is written in config.ini
-- Fullscreen?--
if line == "fullscreen = no" then option_is_fullscreen:setValue(VConditionValue, false) end
if line == "fullscreen = yes" then option_is_fullscreen:setValue(VConditionValue, true) end
-- Define language and change it --
for i = 1, table.maxn(option_language) do if line == ("language = " .. string.lower( option_language[i]:getName() )) then game:setValue(VGameStandardLanguage, option_language[i]); print("Language is set to " .. game:getLink(VGameStandardLanguage):getName()) end end
-- Read & print sound volumes --
if line:find("musicvolume =") then print("music volume = " .. getVolume(eMusicVolume)) end
if line:find("soundvolume =") then print("sound volume = " .. getVolume(eSoundVolume)) end
if line:find("globalvolume =") then print("global volume = " .. getVolume(eGlobalVolume)) end
end
end
config_file_exist:close()
print(filename_of_config_file .. "'s settings were succesfully retrieved")
else
-- Prints --
print("There is no " .. filename_of_config_file .. " at game's root folder!")
print("To fix this, please make an empty text file with name: " .. filename_of_config_file .. " and place it to game's root folder.")
end
end
-- FUNCTION FOR WRITING INI-FILE --
function write_ini()
local file_to_write = io.open(localAppDir .. filename_of_config_file, "w") --OPEN--
-- *************************Stuff you write to the ini*********************** --
--file_to_write:write("" .. .. "\n") --
file_to_write:write("File = " .. vis_file_name .. "\n")
file_to_write:write("Fullscreen = ")
if option_is_fullscreen:getBool(VConditionValue) then file_to_write:write("Yes\n") else file_to_write:write("No\n") end
file_to_write:write("Language = " .. game:getLink(VGameStandardLanguage):getName() .. "\n")
file_to_write:write("LogLevel = " .. log_level .. "\n")
--file_to_write:write("MusicVolume = " .. getVolume(eMusicVolume) .. "\n")
--file_to_write:write("SoundVolume = " .. getVolume(eSoundVolume) .. "\n")
-- ************************************************************************** --
print("Settings succesfully written to " .. filename_of_config_file)
file_to_write:close() --After you are done: CLOSE--
end
... You should use smaller variable names & less whitespace - nesting is also a good idea, as it makes it easier to determine what is what. Also I don't recommend having ? marks in the object names. & final note: you don't need to add the volume stuff as it automatically gets written to the config.ini each time it's updated - don't ask me why as I don't know.
Quick tip: write your scripts inside of a text editor like sublime text or atom. As it makes life much easier. Both of them have multi-line editing. Multi-line / word search & replace. Auto-completion, theme & color syntax. I recommend sublime text though as it's still better than atom (at the minute) as it remembers all tabs & their content when you close the app regardless of whether or not you saved.