Hello guys,
im trying to do a typical scenario with a config.ini file: changing fullscreen to window mode (with specific resolution in window mode) and some other options like music,sound,speech volume.
I tried to follow the steps discribed by AFRLme in the wiki, trimmed the shown lua script down to the values in need and tested the preferences out.
For me to understand the script first i focused on the "read_ini()" stuff.
I implemented the read_ini() function in the start script as an execute script action part at the very first position.
When starting the game via Visionaire (directly run the game, not a builded game), i can see in the log (via "print log")
the first lines printed by the read_ini() function:
print(fn .. " exists")
print("loading data from " .. fn)
after that the whole stuff regarding resolution is skipped and the next lines are handling the music-volume: 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("speechvolume =") then print("speech volume = " .. getVolume(eSpeechVolume)) end
The volume showing up in the game is not the values i set in the config.ini but some kind of default(?) values...
I don't know what i made wrong here. It seems to just doesn't set some config.ini-stuff correctly when i change e.g. Fullscreen = No and Resolution = 1280x720. I expected now that when i start the game form the editor via F9 that it starts in 1280x720 window mode. instead its fullscreen , auto.Maybe is it because of the "settings" done for the Player in Visionaire which override the config.ini from the game?
Here is the lua-script i used so far:
--[[
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.
--]]
-- * local variables * --
local fn = "config.ini" -- store filename
-- * --
local wm = getObject("Conditions[cfg_wm]") -- window mode [fullscreen/windowed]
local res = getObject("Values[cfg_res]") -- resolution [fullscreen mode only]
-- * fallback * --
local lglvl = "Error" -- default value for log level
local df = "Data.vis" -- filename should reflect exported .vis file
game:setValue(VGameSpeechLanguage, game:getLink(VGameStandardLanguage)) -- default speech language to stndard language
-- * tables * --
local t_res = {"Auto","Desktop","1280x720"} -- add available resolutions here
local t_lang = game:getLinks(VGameLanguages) -- store all available languages into a table
-- * function used to read data from the config.ini file * --
function read_ini()
local fr = io.open(localAppDir .. fn, "r") -- read from config.ini
-- * --
if fr then -- if file exists then...
lines = fr:read() -- read currently selected line
print(fn .. " exists")
print("loading data from " .. fn)
for lines in io.lines(localAppDir .. fn) do
line = string.lower(lines) -- convert all line content to lowercase
if not line:find("#") then -- skip all lines containing "#"
if line:find("file =") then df = string.sub(lines, 8); print("file is currently linked to " .. df) end
-- * window mode * --
if line == "fullscreen = no" then wm:setValue(VConditionValue, false); print("window mode is currently set to Windowed") end
if line == "fullscreen = yes" then wm:setValue(VConditionValue, true); print("window mode is currently set to Fullscreen") end
-- * resolution * --
for i = 1, table.maxn(t_res) do if line == ("resolution = " .. string.lower( t_res[i] )) then res:setValue(VValueString, t_res[i]); res:setValue(VValueInt, i); print("resolution is currently set to " .. res:getStr(VValueString)) end end
-- * log level * --
if line == "loglevel = error" then lglvl = "Error"; print("log level is currently set to Error") end
if line == "loglevel = warning" then lglvl = "Warning"; print("log level is currently set to Warning") end
if line == "loglevel = info" then lglvl = "Info"; print("log level is currently set to Info") end
-- * sound levels * --
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("speechvolume =") then print("speech volume = " .. getVolume(eSpeechVolume)) end
end
end
fr:close()
print("successfully retrieved settings from " .. fn)
else
print(fn .. " does not exist")
end
end
config.ini looks like this:
File = mysuperawesomegame.ved
# Fullscreen = {Yes|No}
# Yes - starts the game in fullscreen
# No - starts the game in a window
Fullscreen = No
#
# Resolution = {Auto|Desktop|Custom}
# Auto - wide-screen support is activated if a wide-screen display is detected
# Desktop - current desktop resolution is used when game is started in full screen mode
# Custom - enter a custom value eg: Resolution = 1920x1080
Resolution = Auto
#
# LogLevel = {Info|Warning|Error}
LogLevel = Info
#
# MusicVolume|SoundVolume|SpeechVolume = int value {0-100}
MusicVolume = 80
SoundVolume = 80
SpeechVolume = 100
As i said it only contains the read_ini() function yet, but thats what i only do right now.
print log shows this:
(also the log is cutted on the bottom but this seems to be another bug ^^)
Hope someone can help me out here
kind regards
Sebastian