Resolution settings in config.ini

  • #1, by pinsWednesday, 13. May 2015, 16:16 10 years ago
    Hey!
    I've been following the wise examples of AFRLme to get a proper menu working, but I'm stuck.
    This is the script:
    http://wiki.visionaire-tracker.net/wiki/Read/Write_Config.in...
    The windowed/fullscreen choice works perfectly fine, but I seem to be unable to get the write function to set the resolution.
    Here's how it goes, according to my 2 days old experience with Lua:
    First, I get the ingame value of the resolution choice, from 0 = auto to 4 = 1920*1080 :
    local resolution = getObject("Values[resolution?]")
    

    Then it gets sorted (I suppose) in a table...
    local t_res = {"Auto", "1024x768","1280x1024","1680x1050","1920x1080"}
    

    ...which gets read...
     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
    

    ...but when it's time to shine:
     fw:write("Resolution = " .. res:getStr(VValueString) .. "\n")
    


    I get nothing, and the config.ini remains unedited.

    Where did I mess up? Any help would be greatly appreciated!

    Newbie

    66 Posts


  • #2, by afrlmeWednesday, 13. May 2015, 16:31 10 years ago
    You're using 2 different variables for resolution.

    local resolution = getObject("Values[Resolution?]")
    

    & ...
    res
    

    Seeing as the rest of the script is using res: change local resolution to local res.

    P.S: please try to refrain from adding special symbols to your object names. Sometimes it can cause issues. Instead of Resolution? for your values name, just use resolution.

    P.P.S: resolution actually only affects window size when fullscreen is false, but to have that work now, you need to include a new parameter in your config.ini file: RESIZEABLE = Yes.

    Imperator

    7285 Posts

  • #3, by pinsWednesday, 13. May 2015, 16:36 10 years ago
    Oh, right! I got rid of this, now I only use res. I also deleted some remaining "?" in other values and booleans.
    Unfortunately, still nothing on the config.ini end.

    Newbie

    66 Posts

  • #4, by afrlmeWednesday, 13. May 2015, 16:55 10 years ago
    No errors listed in the log?

    By the way you can find out where the localAppDir folder for your game is located by opening up the developers console (TAB) & then by typing...
    exec print(localAppDir)
    

    ... then press enter & type...
    print log
    

    ... press enter again & look through the log data for the line containing something like: c/users/... & that will be where the config.ini, your log files & save game files etc are being stored. Also you should set loglevel to info inside of VS options window under the player tab. If you are on windows then options is found under extras via the menu bar.

    As for the issue you are having... it's probably something you have accidentally messed up on your end. Maybe a typo or an incorrectly named object or variable or maybe an if query you've forgotten to close off. It doesn't take much to break a script with Lua. One broken thing & it will terminate the rest of the script by ending at the line the issue was found.

    Imperator

    7285 Posts

  • #5, by pinsWednesday, 13. May 2015, 17:03 10 years ago
    Thanks you for your reply!
    I've been looking for typos for the past hour, for anything that might explain why it doesn't work... I honestly can't find anything.
    Can it be related to the fullscreen mode? Does it have to be on, or off?

    Here's the full script I'm using, just in case :
    --[[
    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[fullscreen]") -- window mode [fullscreen/windowed]
    local res = getObject("Values[res]") -- resolution [fullscreen mode only]
    
    -- local subs = getObject("Conditions[cfg_subs]") -- subtitles [on/off]
    --local fx = getObject("Values[cfg_fx]") -- fx level [low/medium/high] (controls which animations will be displayed)
    --local cbm = getObject("Conditions[cfg_cbm]") -- color blind mode [on/off]
     
    -- * fallback * --
    local lglvl = "Info" -- 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", "1024x768","1280x1024","1680x1050","1920x1080"} -- 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("-- * --")
      print(fn .. " exists")
      print("retrieving settings 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
        -- * subtitles * --
       -- if line == "subtitles = no" then subs:setValue(VConditionValue, false); print("subtitles are currently set to Off") end
       -- if line == "subtitles = yes" then subs:setValue(VConditionValue, true); print("subtitles are currently set to On") end
        -- * text language * --
       -- for i = 1, table.maxn(t_lang) do if line == ("textlanguage = " .. string.lower( t_lang[i]:getName() )) then game:setValue(VGameStandardLanguage, t_lang[i]); print("text language is currently set to " .. game:getLink(VGameStandardLanguage):getName()) end end
        -- * speech language * --
       -- for i = 1, table.maxn(t_lang) do if line == ("speechlanguage = " .. string.lower( t_lang[i]:getName() )) then game:setValue(VGameSpeechLanguage, t_lang[i]); print("spoken language is currently set to " .. game:getLink(VGameSpeechLanguage):getName()) end end
        -- * fx quality * --
        --if line == "fxquality = low" then fx:setValue(VValueString, "Low"); fx:setValue(VValueInt, 1); print("fx quality is currently set to " .. fx:getStr(VValueString)) end
        --if line == "fxquality = medium" then fx:setValue(VValueString, "Medium"); fx:setValue(VValueInt, 2); print("fx quality is currently set to " .. fx:getStr(VValueString)) end
        --if line == "fxquality = high" then fx:setValue(VValueString, "High"); fx:setValue(VValueInt, 3); print("fx quality is currently set to " .. fx:getStr(VValueString)) end
        -- * color blind mode * ---
        --if line == "colorblindmode = no" then cbm:setValue(VConditionValue, false); print("color blind mode is currently set to Off") end
        --if line == "colorblindmode = yes" then cbm:setValue(VConditionValue, true); print("color blind mode is currently set to On") 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
        if line:find("movievolume =") then print("movie volume = " .. getVolume(eMovieVolume)) end
        if line:find("globalvolume =") then print("global volume = " .. getVolume(eGlobalVolume)) end
       end
      end
      fr:close()
      print("successfully retrieved settings from " .. fn)
     else
      print(fn  .. " does not exist")
     end
    end
     
    -- * function used to write data to the config.ini file * --
    function write_ini()
    
     local fw = io.open(localAppDir .. fn, "w") -- write to config.ini
     print("-- * --")
     print("writing new settings to " .. fn)
     -- * data file * --
     fw:write("File = " .. df .. "\n")
     -- * window mode * --
     fw:write("#\n")
     fw:write("# Fullscreen = {Yes|No}\n")
     fw:write("# Yes: starts the game in fullscreen\n")
     fw:write("# No: starts the game in a window\n")
     fw:write("Fullscreen = ")
     if wm:getBool(VConditionValue) then fw:write("Yes\n") else fw:write("No\n") end
     -- * resolution * --
     fw:write("#\n")
     fw:write("# Resolution = {Auto|Desktop|Custom}\n")
     fw:write("# Auto: wide-screen support is activated if a wide-screen display is detected\n")
     fw:write("# Desktop: current desktop resolution is used when game is started in full screen mode\n")
     fw:write("# Custom: enter a custom value eg: Resolution = 1920x1080\n")
     fw:write("Resolution = " .. res:getStr(VValueString) .. "\n")
    
     -- * subtitles * --
     fw:write("#\n")
     fw:write("# Subtitles = {Yes|No}\n")
     fw:write("# Yes: show subtitles during the game, cut scenes & videos\n")
     fw:write("# No: do not show subtitles during the game, cut scenes or videos\n")
     fw:write("Subtitles = ")
     if subs:getBool(VConditionValue) then fw:write("Yes\n") else fw:write("No\n") end
     -- * text language * --
     fw:write("#\n")
     fw:write("# TextLanguage = {English|French|German|Spanish}\n")
     fw:write("# this will display subtitles in the specified language\n")
     fw:write("TextLanguage = " .. game:getLink(VGameStandardLanguage):getName() .. "\n")
     -- * speech language * --
     fw:write("#\n")
     fw:write("# SpeechLanguage = {English|French|German|Spanish}\n")
     fw:write("# this will play speech files linked to the specified language\n")
     fw:write("# if no speech language is provided then the speech language will default to the standard language\n")
     fw:write("SpeechLanguage = " .. game:getLink(VGameSpeechLanguage):getName() .. "\n")
     -- * fx quality * --
     fw:write("#\n")
     fw:write("# FxQuality = {Low|Medium|High}\n")
     fw:write("# allows user to change animation/particle fx modes (for players on lower end machines)\n")
     fw:write("# Low: only show the basic required game animations/particle fx\n")
     fw:write("# Medium: only show certain animations/particle fx &/or animations containing less frames\n")
     fw:write("# High: show all animations, in all their glory\n")
     fw:write("FxQuality = " .. fx:getStr(VValueString) .. "\n")
     -- * color blind mode * --
     fw:write("#\n")
     fw:write("# ColorBlindMode = {Yes|No}\n")
     fw:write("# Yes: enable color blind support (graphic replacement, on screen indicators etc)\n")
     fw:write("# No: show the game as it's meant to be played\n")
     fw:write("ColorBlindMode = ")
     if cbm:getBool(VConditionValue) then fw:write("Yes\n") else fw:write("No\n") end
     -- * log level * --
     fw:write("#\n")
     fw:write("# LogLevel = {Info|Warning|Error}\n")
     fw:write("LogLevel = " .. lglvl .. "\n")
     -- * volume settings * --
     fw:write("#\n")
     fw:write("# MusicVolume|SoundVolume|SpeechVolume|MovieVolume|GlobalVolume = int value {0-100}\n")
     fw:write("MusicVolume = " .. getVolume(eMusicVolume) .. "\n")
     fw:write("SoundVolume = " .. getVolume(eSoundVolume) .. "\n")
     fw:write("SpeechVolume = " .. getVolume(eSpeechVolume) .. "\n")
     fw:write("MovieVolume = " .. getVolume(eMovieVolume) .. "\n")
     fw:write("GlobalVolume = " .. getVolume(eGlobalVolume) .. "\n")
     print("new settings successfully written to " .. fn)
     fw:close()
    end
    

    Newbie

    66 Posts

  • #6, by pinsWednesday, 13. May 2015, 17:35 10 years ago
    Well here's something new. When I add a string to the value, as such:
    http://i.imgur.com/qmiG86Y.jpg
    Here's what the .ini shows :

    # 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 = resolution

    Newbie

    66 Posts

  • #7, by afrlmeWednesday, 13. May 2015, 17:45 10 years ago
    indeed. You can only define the initial value of a values string via the editor when creating the value. To update or access the string part of a value afterwards requires Lua script - don't ask me why as I have no idea why the devs bothered creating it that way.

    It's displaying that because you've written resolution.

    I can't really tell the issue from here. If you want, you could send me your .ved & resources so I can quickly debug it?

    Imperator

    7285 Posts

  • #8, by pinsWednesday, 13. May 2015, 17:56 10 years ago
    Ah, well, I really thought that would lead me to the light. It has been a long afternoon grin
    I'm going to send you the files in a minute, via PM. Thank you so much.

    Newbie

    66 Posts

  • #9, by qamilloWednesday, 13. July 2016, 21:19 8 years ago
    Sorry for bumping the topic, but I'm at dead end. I analized Read/Write script line by line, contacted pins (thanks mate!) and tried to reach AFRLme (seems like your Visionaire profile is gone) - nothing helped.

    So, it seems like I have the same problem as pins. I used script (without any alternations, except resolution table) from Vis Wiki. Fullscreen on/off works great, but resolution always give me empty entry in config.ini. I tried to follow config.ini and .log changes, here is how it looks:

    1) Fresh build creates config.ini with volume settings only - read part of the script works fine!
    2) After write operation whole config.ini is changed as in the script code, but it don't write strings from value & res table - in config.ini it looks like that "Resolution = "
    3) After reboot and another read operation I have "Warning: Invalid value for parameter Resolution in config file" and I don't get any "resolution is currently set to ", because this line is just empty in the file.

    Any ideas? roll

    PS. I also get "0(13) : warning C7563: assignment to uniform color", but I'm almost sure, that this is some font issue (again).

    Newbie

    21 Posts

  • #10, by sebastianWednesday, 13. July 2016, 22:06 8 years ago
    can you post your config.ini script?

    Thread Captain

    2346 Posts

  • #11, by qamilloWednesday, 13. July 2016, 22:26 8 years ago

    Newbie

    21 Posts