Help with your scripting

Script not working [SOLVED]

Script not working [SOLVED]

Postby epsilonion » 19 Feb 2019, 20:58

Hi, I have a script that I had working some time ago, I have found the problem and it is

Code: Select all
local find_file=io.open(File_Folder .. filename, "r");


it used to work thats the problem, the error log in the script editor does not post any errors.

Code: Select all
File_Folder = sky.getDir_ProjectOrGameFolder()    -- project Or Game assets folder
-- find_settings_file = nil;   
musicVol = 1;
effectsVolume = 1;

function onInit(objID)
   obj = objID;
        find_file(render.pml) --pass the filename to the find_file function
end

function find_file( filename )
sky.trace();
   local find_file=io.open(File_Folder .. filename, "r");
      lprint( File_Folder ); -- does the string look right --doesn't get this far now
      lprint( filename );  -- is the filename correct.
      -- =====================================================
      -- = If no file exists then call the Create_File function
      -- = and pass the file name to that function
      -- =====================================================
      if (find_file==nil) then
         elseif (filename=="config.pml") then
            Create_File(filename)
         else
            Read_File(filename)
      
   end
end
      




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: Script not working

Postby StarFire » 20 Feb 2019, 12:08

should work, i am using:

Code: Select all
--note that this code only tests whether the file can be opened for reading
function file_exists(name)
   local f=io.open(name,"r");
   if f~=nil then io.close(f) return true else return false end
end


for checking for a file.
Have you checked the main log file as lua errors only show in the dos log not the sge console.

When you pass the file name to the function it must be in quotes eg.

Code: Select all
find_file("render.pml");
Dream the Journey, Live the Experience!
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer

Re: Script not working

Postby epsilonion » 20 Feb 2019, 16:07

Thank you works swimmingly.

I did however notice the API https://api.aurasoft-skyline.co.uk/classsky.html#ad9b5a9fdfbd32e7c0a08ed0c6e0254a6
for exit sky.exit(); doesnt seem to work but the sky.exitGame(); command does, maybe worth updating the API with that one.
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: Script not working

Postby StarFire » 20 Feb 2019, 16:45

Good that you have got it working :)

Yes there are a some updates to the api needed :roll:
Dream the Journey, Live the Experience!
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 5 guests

cron