Jump to content

Lua and loading maps question


YouGroove
 Share

Recommended Posts

I have a question on how works Lua and maps.

 

When i have a map under the editor if i run it clikcing on run button, this map is loaded and played.

If i change the map name under App.lua , it has no effect ? Why ?

 

Same thing when we compile in C++ Leadwerks.exe to be able to use Lua, it has a default name map in the C++ code, but this is not what prevents to load a new map ?

 

To make it simple :

How to switch maps in Lua ? Must we run App.lua outside of the editor ?

Stop toying and make games

Link to comment
Share on other sites

It has no effect because start.map is loaded in the code. I made a post some time ago about how it should be the current map, but Josh was trying to make it easy on the newcomer to LE. I still think it should be the loaded map by default. The editor should be passing in the current map to the exe as a command line argument and then that gets loaded. If no command line argument (which would be the case when launched by the player) then it falls back to the "startup" map that we define in code.

 

To switch when you are developing you must change it in App.lua. Switching while playing the same is different and require a little more work.

  • Upvote 1
Link to comment
Share on other sites

I understand some work is needed to make map loading a variable in Leadwerks.exe.

A standard solution would be to have a map panel in project Manager to reference all maps you use and add new ones to a selected project. At final you would call simple function to load a map by it's name could it be you use Lua or C++.

Stop toying and make games

Link to comment
Share on other sites

I tried that script attached to a pivot using Flowgraph.

 

function Script:Rotate()--in
rotation.y = rotation.y + 10
self.entity:SetRotation(rotation);
--App.world = World:Create()
local mapfile = System:GetProperty("map","Maps/start.map")
Map:Load(mapfile)

end

 

Unfortunatelly it crashes when the code is fired by another Flowgraph component.

 

If someone have a "simple" working Lua example without needing to change C++ code it would be great.

Stop toying and make games

Link to comment
Share on other sites

From what I remember you can't change maps from within code that's running via the map. Basically this means App.lua needs to be the code that actually calls Map:Load(). So in your scripts you set the new map name variable and in App.lua you check to see if that variable is different then the last time or set some kind of flag to tell App.lua it should load a new map.

  • Upvote 1
Link to comment
Share on other sites

Thanks.

Actually i'm a bit stuck, i don't understand why App.lua has no influence when i laucnh it by run button on editor ?

I changed :

function App:Start()
self.title="test change level"

Even the title remains is not changed and remains the one of Leadwerks.exe (compiled exe) ?

Did i done something wrong ?

 

I even commented world update and world run in App.lua and they have no impact if i launch clicking on run button of the editor ?

Should i run App.lua form some external program or tool instead ?

 

function App:Loop()

....
....
--Update the world
--self.world:Update()

--Render the world
--self.world:Render()

--Refresh the screen
self.context:Sync()

--Returning true tells the main program to keep looping
return true
end

 

Must i install Lua and launch App.lua using somme MS DOS command like :

lua App.lua

(I'm a bit confused ?)

Stop toying and make games

Link to comment
Share on other sites

Post the autogenerated C++ main file. The fact that you have App.lua would suggest it's a Lua project and not a C++ project but showing us your main or maybe App.cpp file would help us determine that. When you made this project you did select it as a Lua project right?

Link to comment
Share on other sites

Something interesting, if i put a non existing map name in start function in App.lua, it will automatically load the map i have on the editor.

 

 

function App:Start()

--Set the application title
self.title="luaTest8"

--Create a window
self.window=Window:Create(self.title)
self.window:HideMouse()

--Create the graphics context
self.context=Context:Create(self.window,0)
if self.context==nil then return false end

--Create a world
self.world=World:Create()

--Load a map
local mapfile = System:GetProperty("map","Maps/nonexistingmap.map")
if Map:Load(mapfile)==false then return false end

return true
end

 

 

So What to do then ? What is a simple working solution with Lua ?

Stop toying and make games

Link to comment
Share on other sites

Last test :

If i put complete map name with good separators, the engine find the file this time, but the laoding command has no effect ?

 

 

function App:Loop()

Map:Load("E:/Leadwerks/Projects/luaTest/Maps/start.map")
loaded = 2
...
...

Stop toying and make games

Link to comment
Share on other sites

I really think you don't understand what getProperty does.

Just read http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/system/systemgetproperty-r538

 

and you understand that it reads the parameter map when it is attached to the command-line.

The Editor does attach the map parameter with the currently in the editor loaded map so you can actually debug the loaded map when you press "Run". if the "map" parameter is not attached it loads the default map that is the second parameter in the getProperty method.

 

If you don't want to have the editor map loaded automatically you can just replace getProperty with your actual path.

 

so replace the line:

local mapfile = System:GetProperty("map","start.map")

with

local mapfile = "start.map"

 

 

also do not use absolute paths. That will surely give you issues sooner or later.

 

Also it seems you don't have Leadwerks installed in the default path. I am not sure how that affects everything but i think it was mentioned that it will make trouble at least when you try to develop for mobile.

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...