First Game Load config.ini settings

  • #1, by atrusMonday, 25. December 2017, 20:42 10 months ago
    Merry Xmas to all! Wishing all the best for you and your families!

    Have the following question regarding config.ini files:

    I have found the way to write/read from config.ini files thanks to documentation (and AFRLme).

    Now the issue is during the FIRST run on the game: VS creates its own config file in C:\Users\*user name*\AppData\Local\*company name*\*game name* (talking about Windows 10 here), so, how can i preset any settings in my own config.ini file?

    For example, i want to preset the music,sfx,speech volumes. Any help is appreciated.

    Forum Fan

    237 Posts


  • #2, by AFRLmeMonday, 25. December 2017, 21:16 10 months ago
    By default when you export the game it will automatically create a config.ini file in the game root folder which contains some basic things & will be used on the first game launch. However the script reads from the one in the appdata folder if it exists. What you could do is create an execute a script action part in the at begin start following action on the game settings section of the editor & query if the config.ini file exists. If it doesn't then you could call a called by other action or something that contains a bunch of settings you want to initialize such as the volume, language & so on.

    Imperator

    6280 Posts

  • #3, by atrusMonday, 25. December 2017, 21:34 10 months ago
    Thanks for the reply, yes i thought so, well not the best approach by the engine but it should work yes.

    I wonder why the below simple solution is not implemented:

    -> After building a game you overwrite the engine's config.ini with your own custom ini in the build folder
    -> Then, when running the game for the first time VS will copy this custom config.ini to C:\Users\*user name*\AppData\Local\*company name*\*game name*

    And all is set.

    Forum Fan

    237 Posts

  • #4, by AFRLmeMonday, 25. December 2017, 23:28 10 months ago
    You could probably do that yourself. If config.ini doesn't exist in the appdata place, store each line in the root folder ini file inside of a table, then create the config.ini & write the new data to it. Should be possible, but don't ask me how off the top of my head.

    Imperator

    6280 Posts

  • #5, by atrusTuesday, 26. December 2017, 09:17 10 months ago
    Achieved it with a small modification of the Read/Write Config.ini script
    function read_ini()
     local fr = io.open(localAppDir .. fn, "r") -- read from config.ini
     -- * --
     if fr then -- if file exists then...

    ** code to read from the ini in here **

     else
      print(fn .. " does not exist. Setting defaults")
      setVolume(eMusicVolume, 50)
      setVolume(eSoundVolume, 70)
      setVolume(eSpeechVolume, 70)
      write_ini() -- creating new config.ini
      end
    end
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16

    At the Start Action of the game just have an Execute Action with read_ini()

    So:

    1. Game Starts for 1st time.
    2. config.ini is not found, the default values are set (in the above example the volume settings)
    3. A new config.ini is created immediately.

    Forum Fan

    237 Posts

Write post