A place where the topic is related to content creation.

Load or create files at game run time

Load or create files at game run time

Postby epsilonion » 01 Oct 2017, 18:26

Wasn't sure where to put this.

Heres a little script that looks for a config file when a scene loads it none is found it creates one and if one is found it loads the file from disk and applies the data in the read files.

Skyline does this automatically for the render settings upon run but this shows the basics to get your game data driven, allowing the user of your game to mod files to create the content that they want in your game.

The most basic way of making your game modable is to have your character settings such as health, damage, weapon damage all editable in a file like this even player money can be saved with the player settings and stats.

Well its a starting place for those not used to lua or new to coding.


Code: Select all
obj = 0;
function onInit(objID)
   obj = objID;
   File_Folder = sky.getDir_ProjectOrGameFolder() -- project Or Game assets folder
      
   -- Look to see if the settings file exists
   local find_settings_file=io.open(File_Folder .. config.xml, "r");
      if find_settings_file==nil then
         Create_File(config.xml)
      else
         Read_File(config.xml)
      end
 
end

function Create_File( filename )

   if filename=="config.xml" then                     -- Explained below
      
      currFSAA = render.getFSAA();
      fullscr = render.getFullScreen();
      currQual = render.getQuality();
      currRes = render.getResolution();
      rendStats = render.getShowStats();
      vsync = render.getVsync();
      
      local ConfigTable = {};
         ConfigTable["Fullscreen"] = fullscr;
         ConfigTable["FSAA"] = currFSAA;
         ConfigTable["Resolution"] = currRes;
         ConfigTable["Quality"] = currQual;
         ConfigTable["Vsync"] = vsync;
         ConfigTable["Show_Stats"] = rendStats;

      jsonObj = rapidjson.object(ConfigTable);
      rapidjson.dump(jsonObj, File_Folder .. "Config.xml", {pretty=true});
      
   
   return
         
end

function Read_File( filename )

   if filename=="config.xml" then                     -- Explained below
   
      renderData = rapidjson.load(File_Folder .. filename);

      render.setFSAA(renderData["FSAA"]);
      render.setFullScreen(renderData["Fullscreen"]);
      render.setQuality(renderData["Quality"]);
      render.setResolution(renderData["Resolution"]);
      render.setShowStats(renderData["Show_Stats"]);
      render.setVsync(renderData["Vsync"]);

   end

   return
end


end


I used the if filename=="config.xml" then because you may want to load up other files at run time and you can use this if statement to separate the files that you are processing.

When opening other files you pass the file name to the create or read functions and preform your tasks within them functions.
User avatar
epsilonion
Skyline Moderator
Skyline Moderator
 
Posts: 818
Joined: 26 Feb 2015, 11:51
Location: East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: Load or create files at game run time

Postby SolarPortal » 02 Oct 2017, 09:56

Skyline automatically makes 2 files when a player boots for settings to be displayed for renderer and graphics:
* CustomSettings.ini - handles resolution, graphics etc..
* SkylineSettings.ini - handles GPU and renderer

Your code will be useful for other users that need to be able to have their own custom settings for their game though, so a definite handy bit of code :)
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3100
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Load or create files at game run time

Postby epsilonion » 02 Oct 2017, 12:20

Yeah. I though put renderer settinhs in there and people can see how it works (easiest thing I could think of and can adapt it to save/load player data or something.

It's a start for them in the right direction
User avatar
epsilonion
Skyline Moderator
Skyline Moderator
 
Posts: 818
Joined: 26 Feb 2015, 11:51
Location: East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: Load or create files at game run time

Postby Shando » 04 Oct 2018, 01:37

Hi SP,

Skyline automatically makes 2 files when a player boots for settings to be displayed for renderer and graphics:
* CustomSettings.ini - handles resolution, graphics etc..
* SkylineSettings.ini - handles GPU and renderer


A couple of questions:

1) If any of the values stored in the above files are changed during "runtime" do these files get updated when the engine quits?
2) If not, what is the best way to update these files, so any user selected settings are saved on exit?

Thanks in advance

Shando
Alienware 17 (i7-4700MQ 2.4GHz 16GB GTX770M Win 10 64)

Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 480
Joined: 06 Mar 2013, 22:35
Location: Kings Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: Load or create files at game run time

Postby SolarPortal » 04 Oct 2018, 21:41

If this is for the end game, then i believe they are updated when the render.function() is used. Thats also what the code says it does. Otherwise they are not used by the Editor itself; only player and end game.
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3100
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Load or create files at game run time

Postby Shando » 10 Oct 2018, 01:26

Hi SP,

If this is for the end game, then i believe they are updated when the render.function() is used. Thats also what the code says it does. Otherwise they are not used by the Editor itself; only player and end game.


That's exactly what I needed to know :)

Thanks

Shando
Alienware 17 (i7-4700MQ 2.4GHz 16GB GTX770M Win 10 64)

Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 480
Joined: 06 Mar 2013, 22:35
Location: Kings Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: Load or create files at game run time

Postby SolarPortal » 10 Oct 2018, 15:33

cool :)
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3100
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer


Return to Content Creation

Who is online

Users browsing this forum: No registered users and 1 guest