Jump to content

lua dofile prevents exported game from starting


Phodex Games
 Share

Go to solution Solved by macklebee,

Recommended Posts

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.

Link to comment
Share on other sites

@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 :rolleyes:

Link to comment
Share on other sites

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 :rolleyes:

Please show an example of how you wish to do something. You might need to find another way of your implementation.

  • Like 1

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

  • Solution
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 :rolleyes:

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

 

  • Like 2

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

@macklebee Well that comes a litte bit too late :D, 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 :)

Link to comment
Share on other sites

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.

  • Like 1

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...