Help with your scripting

Directories with json

Directories with json

Postby epsilonion » 02 Sep 2017, 22:57

I have found some time to get my head in Skyline in preparation for V1.. whoop whoop..
I am writing a basic script that loads at the beginning of the game to load renderer settings and set them if they have been set in the settings menu at the point when the first scene is loaded up.

I am wondering if I am using the folder correctly to dump a table to a file named "Config.xml"?

Code: Select all
File_Folder = sky.getDir_ProjectOrGameFolder()

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


Below I load the file name that has been passed to a function to be read... again I wonder if I am using the folder variable properly here?

Code: Select all
function readfile(filename)
renderData = rapidjson.load(File_Folder .. filename);
end


Another question is would I have to set the settings for every scene or just once and it carries over to the next scene and so on?

Getting excited for V1.0 :) can ot wait.. :)
User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: Directories with json

Postby SolarPortal » 02 Sep 2017, 23:46

if the renderer settings are stored in lua, then they will need to be edited.

otherwise if the renderer settings are the main window settings e.g. FXAA, V-Sync, etc... then these are best edited in the options screen as the game will sometimes need to restart to see the changes.
Also note: we have a new game menu coming soon courtesy of planetX which will replace the current options screen. Just got to find some time to fit it in :)

Json does not save xml files, it saves json, although the name extension being xml should not be wrong.

rapidjson.load(File_Folder .. filename);

Have you printed File_Folder to check whether it has a slash afterwards

Code: Select all
lprint( File_Folder ); -- does the string look right
lprint( filename )  -- is the filename correct.

-- if its missing the slash, then add the slash in.
File_Folder .. "/"..filename


yes, you must define the json_obj, looking at the script, apart from that, i dont see why it wouldnt work.

p.s. This versions is seriously taking some doing, it has such major changes it feels new lol :P ( ... it still looks the same though ... :P) v1.0 will be skyline's best form yet.

JSON Script Example:
Code: Select all
-- | Requires the 0.9.7 preview version of skyline or later.

obj = 0;
function onInit(objID)
   obj = objID;
end

function onKeyDown( key )

   -- | on key one, we will serialize the table to file.
   if(key == "1")then
      lprint("#&127,127,127:Saving table to JSON...")
   
      -- | First Lets create a lua table and fill in some data to test with.
      local tempTable = {};
      tempTable["playername"] = "Joe";
      tempTable["lastName"] = "Bloggs";
      tempTable[0] = { ["a"]="Hello", [3]=200};
      tempTable[1] = "World";
     
      -- | Second: create a json object based on the table, this contains the correct
      -- | metatable for the code to write the JSON data properly.
      jsonObj = rapidjson.object(tempTable)
     
      -- | Third; Lets dump the new object into a json file.
      -- |    > The pretty at the end is to create more readable lines. Setting false will write into one line.
      -- |    > For a specific location on a Hard drive e.g. E:/myFile.json
      -- |    > You can name the extension to whatever you want ... *.tableData, *.player etc...
      rapidjson.dump(jsonObj, "myfile.json", {pretty=true});
     
      lprint("#&127,255,127:Saving table to JSON Complete!");
   end
   
   -- | on key two, we will load the files data into a table and print the data.
   if(key == "2")then
      lprint("#&127,127,127:Loading table to JSON...")
   
      -- | Load the json file into a table.
      myData = rapidjson.load("E:/myfile.json");
     
      -- | Print the data to the in game screen.
      sprint("playername = "..myData["playername"]);
      sprint("lastName = "..myData["lastName"]);
      sprint("0 = "..myData[tostring(0)]["a"]);
      sprint("0 = "..myData[tostring(0)][tostring(3)]);
      sprint("1 = "..myData[tostring(1)]);
     
      lprint("#&127,255,127:Loading table to JSON Complete!");
   end
end
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Directories with json

Postby epsilonion » 03 Sep 2017, 01:39

I am having issues lol..

nothing working in the script after this command

Code: Select all
File_Folder = sky.getDir_ProjectOrGameFolder(); -- project Or Game assets folder


I have made a project and saved the scene within that project, I put a trace before and after this command and the one before is only showing... strange.. :)
User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: Directories with json

Postby Shando » 03 Sep 2017, 01:51

Hey buddy,

Has that command been released yet? AFAIK it was slated for the next release, but not 100% sure that there has been one since the end of July (my version is 0.9.8.13 which was released in June)??

I could, of course, be totally wrong ( wouldn't be the first time :D )

Shando
Ryzen 7 4800H 16GB GTX1650 Win 11 64
Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: Directories with json

Postby epsilonion » 03 Sep 2017, 01:59

Ah maybe..
I have version 0.9.7.9 so you must have a release that newer than mine lol...
Just done a fresh install and update.

lol i am a idiot didnt install the gen2 alpha build lol
User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: Directories with json

Postby SolarPortal » 03 Sep 2017, 11:25

lol :P silly mistake lol :P

If you hang fire installing skyline because the new release today/tomoz will be a full install as the entire asset library has changed and is looking more like a RC1 version of skyline for v1.0 than anything we had before, the command should then work also.
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Directories with json

Postby epsilonion » 04 Sep 2017, 02:22

Wow this new version is great mate, one hell of an update mate :)

BTW got it working it reads and writes a config file.. :) happy days..
User avatar
epsilonion
Skyline Lead Moderator
Skyline Lead Moderator
 
Posts: 874
Joined: 26 Feb 2015, 11:51
Location: Hull, East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: Directories with json

Postby SolarPortal » 04 Sep 2017, 08:57

excellent that its working! :)

Good job on getting the config file reading/writing.

Would be great if you could join us on discord and help some of our newer users :) They are having troubles getting this version working and believe it is more unstable than the last.
Skyline Game Engine - Lead Dev.
Please provide as much info as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 4770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860

Twitter: @SolarPortal
Instagram: @SolarPortal
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 4 guests