Phodex Games Posted April 28, 2018 Share Posted April 28, 2018 When I exported my project and started the exe file, just nothing happned, window doesnt even pop up. I nailed down the issue to some "dofile" commands I am calling inside my main. The error does not seam to be within the files I am calling. It seems to be "dofile" in general. Running in Admin mode did NOT solve the issue by the way. So I fear this does not work due to lua sandbox is enabled after exporting is it? It would greatly help me if there would be a way to avoid this, otherwise I have to re-design all my code so it does not need "dofile", which could get hard, especially with my save/load system. Quote Link to comment Share on other sites More sharing options...
Gonan Posted April 28, 2018 Share Posted April 28, 2018 Have you tried turning off lua sandbox mode? Then are you getting the same results? Quote Link to comment Share on other sites More sharing options...
reepblue Posted April 28, 2018 Share Posted April 28, 2018 With LE4, dofile isn't exposed. To call the lua script, you need to use "import" instead. This will run the lua script and put all the functions and variables in memory. 1 Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Phodex Games Posted April 28, 2018 Author Share Posted April 28, 2018 @reepblue Thanks thats the information I needed :), but the problem now is that for some reason import does only work with pure string not put into a variable. But within my system I often used "dofile" to load self made data files, like sound profiles for various objects, which paths are stored in variables to be flexible. Is there any way you could do this? Otherwise I have some trouble Quote Link to comment Share on other sites More sharing options...
reepblue Posted April 29, 2018 Share Posted April 29, 2018 22 hours ago, Phodex Games said: @reepblue Thanks thats the information I needed :), but the problem now is that for some reason import does only work with pure string not put into a variable. But within my system I often used "dofile" to load self made data files, like sound profiles for various objects, which paths are stored in variables to be flexible. Is there any way you could do this? Otherwise I have some trouble Please show an example of how you wish to do something. You might need to find another way of your implementation. 1 Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Solution macklebee Posted April 29, 2018 Solution Share Posted April 29, 2018 On 4/28/2018 at 10:54 AM, reepblue said: With LE4, dofile isn't exposed. To call the lua script, you need to use "import" instead. This will run the lua script and put all the functions and variables in memory. The lua function dofile is exposed in LE4. It works in editing mode with lua sandbox turned ON or OFF. The reason dofile is failing is due to how the file path is changed when everything is placed inside data.zip within the game directory. For example, prior to publishing myscript.lua is in the "MyGame/Scripts" folder, and after exporting myscript.lua is now in the "Scripts" folder inside the data.zip file located in the "MyGame" folder. Dofile will work if the path from the executable's root folder to the file in question has not changed. So this means you can create a folder called "Scripts" within the root folder and put myscript.lua in there. But this means your files are exposed.... On 4/28/2018 at 11:37 AM, Phodex Games said: @reepblue Thanks thats the information I needed :), but the problem now is that for some reason import does only work with pure string not put into a variable. But within my system I often used "dofile" to load self made data files, like sound profiles for various objects, which paths are stored in variables to be flexible. Is there any way you could do this? Otherwise I have some trouble While import does work - it will only load the file once. So if you are using import to set variables by loading multiple scripts, it will only let you set it once with that file. So the LE sandbox version of dofile is 'Interpreter:Executefile("luascript.lua")'. Also, since it is an inherent command in LE, it works when published from the data.zip without having to worry about paths being changed. Example: Files, myfile1 & myfile2, contain the variables A, B, & C set to various values. window = Window:Create("example",0,0,400,300,Window.Titlebar+Window.Center) context = Context:Create(window) world = World:Create() camera = Camera:Create() gui = GUI:Create(context) base = gui:GetBase() x=140 y=110 local sep=30 button1 = Widget:Button("Dofile 1",x,y,100,25,base) y=y+sep button2 = Widget:Button("Dofile 2",x,y,100,25,base) A = 0 B = 0 C = 0 D = 0 while not window:KeyHit(Key.Escape) do if window:Closed() then return false end while EventQueue:Peek() do local event = EventQueue:Wait() if event.source == button1 then filetodo = "Scripts/myfile1.lua" elseif event.source == button2 then filetodo = "Scripts/myfile2.lua" end Interpreter:ExecuteFile(filetodo) end D = A + B - C Time:Update() world:Update() world:Render() context:SetBlendMode(Blend.Alpha) context:DrawText("D = "..D,2,2) context:SetBlendMode(Blend.Solid) context:Sync() end 2 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Phodex Games Posted April 29, 2018 Author Share Posted April 29, 2018 @macklebee Well that comes a litte bit too late , spend the whole last day and today to translate my whole system so it only uses import instead of dofile. Well fortunatley I could improve some stuff by doing that, but especially my save/load system suffered from not beeing able to load specific files. Still this information is very helpful thanks a lot Quote Link to comment Share on other sites More sharing options...
macklebee Posted April 29, 2018 Share Posted April 29, 2018 Nothing special required for sandbox mode being turned off - just know that it has loaded lua modules or LE sandbox-disabled specific commands that someone could attempt to do nefarious things with.., which is why lua sandbox enabled was the only option for games uploaded to the game launcher. In any case, don't use dofile due to the path issue with an exported game- use Interpreter:Executefile() or import depending on how you are using the loaded file. Both will work with sandbox mode enabled or disabled and will work with data.zip. EDIT - updated to point out that dofile works with sandbox enabled. The problem is due to the file path changing once everything is exported to a data.zip folder. 1 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
reepblue Posted April 30, 2018 Share Posted April 30, 2018 Thanks for the insight Mack, I recall trying to use dofile without sandboxing and it wouldn't work. But your advice is much better than mine, cheers! 1 Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.