Jump to content

LUA Load Scene


Meldrion
 Share

Recommended Posts

Hello everyone

I am still very new to Leadwerk Engine ( just got it yesterday ) and i have some sort of trouble with LUA.

Well mainly I am a Pascal/Delphi Programmer ( but the Pascal Header doesnt work with my Delphi 7 ( trouble with the inline command ) so i do learn LUA kind of fast.

My Problem is now that i want to load a Scene with LUA.

 

Actually I try to do it with

scene=LoadScene("abstract::Test.sbx")

.

 

The LUA Editor doesnt give me an Error and i can start my Game. But then nothing happens. The Game just closes and that it.

No Error, nothing.

 

And YES there is a GameLoop in my Source

 

Well, i hope someone can help me with this.

 

Meldrion

Link to comment
Share on other sites

require("scripts/hooks")
require("scripts/constants/keycodes")

--Register abstract path
RegisterAbstractPath("")

--Set graphics mode
if Graphics(1024,768,0,60,0)==0 then
Notify("Failed to set graphics mode.",1)
return
end

-- Custom shutDown Variable
ShutDown= false

--Create framewerk object and set it to a global object so other scripts can access it
fw=CreateFramework()
if fw==nil then
Notify("Failed to initialize engine.",1)
return
end
SetGlobalObject("framewerk",fw)

scene=LoadScene("abstract::Test.sbx")
--camera=fw.main.camera
camera=Scene.camera
camera:SetPositionf(0,0,-2)
camera:SetRotationf(45,0,0)

--light=CreateSpotLight(10)
--light:SetRotationf(45,55,0)
--light:SetPositionf(5,1,-5)


--material=LoadMaterial("abstract::cobblestones.mat")


--mesh=CreateCube()

--mesh:Paint(material)


--ground=CreateCube()
--ground:SetScalef(10.0,5.0,10.0)
--ground:SetPositionf(0.0,-2.0,0.0)
--ground:Paint(material)

--light=CreateDirectionalLight()
--light:SetRotationf(45,45,45)

function DrawOverlay() 
 SetBlend(1) 
 SetColor(Vec4(1,0,0,0.25)) 
 DrawRect(100,100,GraphicsWidth()-200,GraphicsHeight()-200) 
 SetColor(Vec4(1,1,1,1)) 
 SetBlend(0) 
end

function ControlCamera()
      if KeyDown (KEY_W)==1 then  MoveEntity (camera, Vec3(0,0,0.1)) end 
      if KeyDown (KEY_S)==1 then  MoveEntity (camera, Vec3(0,0,-0.1)) end
      if KeyDown(KEY_ESCAPE)==1 then ShutDown=true end
end

--AddHook("Flip",DrawOverlay)

while AppTerminate()==0 and ShutDown == false do
--mesh:Turnf(AppSpeed()*0.5,AppSpeed()*0.5,AppSpeed()*0.5)       
       --fw:Update()
       --fw:Render()
       Scene:Update()
       Scene:Render()
       ControlCamera()
       Flip(0)
end

 

EDIT: The Engine loads the Scene ( because the Console tells me that the Scene Files are getting loaded )

But after loading the last Scene Asset it just terminates. Kind of Strange.

Link to comment
Share on other sites

You are trying to use invalid fields/methods for your objects. The scene variable does not have a camera. The previous line was correct: camera=fw.main.camera. You are also doing the same thing with the Update and Render methods. You should be using fw:Update() and fw:Render(). Also remember that LUA is a case sensitive language, so "Scene" is not the same variable as "scene".

require("scripts/constants/keycodes")

--Register abstract path
RegisterAbstractPath("")

--Set graphics mode
if Graphics(1024,768,0,60,0)==0 then
       Notify("Failed to set graphics mode.",1)
       return
end

-- Custom shutDown Variable
ShutDown= false

--Create framewerk object and set it to a global object so other scripts can access it
fw=CreateFramework()
if fw==nil then
       Notify("Failed to initialize engine.",1)
       return
end
SetGlobalObject("framewerk",fw)

scene=LoadScene("abstract::Test.sbx")
camera=fw.main.camera
camera:SetPositionf(0,2,-2)

function ControlCamera()
      if KeyDown (KEY_W)==1 then  MoveEntity (camera, Vec3(0,0,0.1)) end 
      if KeyDown (KEY_S)==1 then  MoveEntity (camera, Vec3(0,0,-0.1)) end
      if KeyDown(KEY_ESCAPE)==1 then ShutDown=true end
end


while AppTerminate()==0 and ShutDown == false do
       fw:Update()
       fw:Render()
       ControlCamera()
       Flip(0)
end

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

You are trying to use invalid methods for your objects. The scene variable does not have a camera. The previous line was correct: camera=fw.main.camera. You are also doing the same thing with the Update and Render methods. You should be using fw:Update() and fw:Render(). Also remember that LUA is a case sensitive language, so "Scene" is not the same variable as "scene".

require("scripts/constants/keycodes")

--Register abstract path
RegisterAbstractPath("")

--Set graphics mode
if Graphics(1024,768,0,60,0)==0 then
       Notify("Failed to set graphics mode.",1)
       return
end

-- Custom shutDown Variable
ShutDown= false

--Create framewerk object and set it to a global object so other scripts can access it
fw=CreateFramework()
if fw==nil then
       Notify("Failed to initialize engine.",1)
       return
end
SetGlobalObject("framewerk",fw)

scene=LoadScene("abstract::AndyTest.sbx")
camera=fw.main.camera
camera:SetPositionf(0,2,-2)

function ControlCamera()
      if KeyDown (KEY_W)==1 then  MoveEntity (camera, Vec3(0,0,0.1)) end 
      if KeyDown (KEY_S)==1 then  MoveEntity (camera, Vec3(0,0,-0.1)) end
      if KeyDown(KEY_ESCAPE)==1 then ShutDown=true end
end


while AppTerminate()==0 and ShutDown == false do
       fw:Update()
       fw:Render()
       ControlCamera()
       Flip(0)
end

 

 

Well my first version was like yours. But since i didnt worked for me i started to try out some stuff.

I assume the code u posted worked for you ? Since i just copy pasted it into the edtior ( changed the Scene back to test.sbx ) and ran my script.

But still, it does the same as it did before...

 

I´m using Win7 x64 ( maybe thats the problem ? ) but so far i didnt have any sort of trouble with the OS and the Engine.

 

Meldrion

Link to comment
Share on other sites

where are you trying to run this from? Inside the editor?

 

There are basically three types of lua scripts for LE:

1) object scripts - look at the firepit.lua or environment_atmosphere.lua for examples of these scripts that set up properties for the models

2) game scripts - look at fpscontroller.lua or driver.lua as examples of scripts that can be ran inside the editor in conjunction with an editor's scene

3) standalone scripts (which is what I consider the above script) that should be saved in the LE SDK's root directory and ran from the ScriptEditor.exe that is in the root directory. See example01.lua and example02.lua. These scripts can also be ran by dragging and dropping the file ontop of the engine.exe file inside windows explorer.

 

So save the example above into your LE SDK root folder and then run it from the ScriptEditor.exe (not from inside the Editor) and it should work.

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

Ok, I made more tests and i found something out >.<

Actually I CAN load some Scenes with this code... But only some.

 

The tunnels.spx example does work. The train.spx also... So does the deserthighway.sbx example.

But the terrain_arctic.sbx does the same kind of strange stuff as my Test.sbx did ?

 

Now I am really confused... o.O

 

Meldrion

Link to comment
Share on other sites

When you say strange what do you mean? Are you saying it crashes? More than likely your camera is below the terrain for the arctic SBX file, so it will look strange.

 

EDIT--ah... the terrain_arctic SBX has protected asset files so you will not be able to load that scene anywhere else except for inside the Editor.

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

where are you trying to run this from? Inside the editor?

 

There are basically three types of lua scripts for LE:

1) object scripts - look at the firepit.lua or environment_atmosphere.lua for examples of these scripts that set up properties for the models

2) game scripts - look at fpscontroller.lua or driver.lua as examples of scripts that can be ran inside the editor in conjunction with an editor's scene

3) standalone scripts (which is what I consider the above script) that should be saved in the LE SDK's root directory and ran from the ScriptEditor.exe that is in the root directory. See example01.lua and example02.lua. These scripts can also be ran by dragging and dropping the file ontop of the engine.exe file inside windows explorer.

 

So save the example above into your LE SDK root folder and then run it from the ScriptEditor.exe (not from inside the Editor) and it should work.

 

 

Actually i do use the Script Editor.exe that is included with the Engine.

The Leadworks Editor itself is not open.

 

sorry for double posting ^^

 

 

Edit:

When you say strange what do you mean? Are you saying it crashes? More than likely your camera is below the terrain for the arctic SBX file, so it will look strange. 

 

Strange means for me that it simply crashed without giving an Access Violation or some other sort of Error.

 

 

Edit2: How to i enable or disable this ? I cant remember that i protected my own Test.sbx Scene

Link to comment
Share on other sites

Also for more debugging info when using the ScriptEditor, run the program using the debug build (the ladybug next to the green run arrow). This will help give helpful hints where your problems might lie...

 

 

Ok thank you very much for your help B)

I finally made it to load my Scene.

The problem was that the Standart Trees ( vegetation_tree_spruce_2.gmf )

is a proteced file. I didnt know that ^^

 

Anyway thanks again for your help and have a nice day.

 

Meldrion

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