Page 1 of 1

running lua function before textures are loaded?

PostPosted: Wed May 28, 2014 22:09
by dgm5555
My question is: How is it possible to get a lua function run prior to the textures being loaded?
I have a function which uses an externally (python) generated texture which is named after the current world.
This causes warnings on initially entering the world if the texture hasn't been generated (presumably as the texture is used as the face of a node). Worse yet, it causes a fatal error if attempting to use the texture in a formspec.

I can use lua to check for existance and if absent copy an alternative texture to provide one with the needed name. However this will still cause warnings about lack of the texture on loading the world if the script is run only when player requests the formspec. Therefore ideally I'd like to be able to run a script, before the texture is loaded (but I don't know how, thus my question).

For the relevant code see: https://github.com/dgm3333/mapit/blob/master/init.lua

Re: running lua function before textures are loaded?

PostPosted: Mon Jun 02, 2014 21:32
by dgm5555
For anyone else with the same problem: The solution was to call the relevant lua function from the core code rather than from within another subsequently called function.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
function file_exists(name)
   local f=io.open(name,"r")
   if f~=nil then io.close(f) return true else return false end
end

function file_copy(source, target)
   local infile = io.open(source, "r")
   local instr = infile:read("*a")
   infile:close()

   local outfile = io.open(target, "w")
   outfile:write(instr)
   outfile:close()
end

local checktex = function()

   local file1,file2="foo","bar"
   if not file_exists(file1) then file_copy(file2, file1) end

   return "checktex: file copy done"
end

print(checktex())  -- call the function from here (and print to debug.txt when done)