Jump to content

Lua Error.


gordonramp
 Share

Recommended Posts

Here is the complete working script.. It changes the Scene. Paste this into the Script Editor, Save it and close the Script Editor then double-click the saved file to run it. It runs Ok but when I move to another scene by pushing (F) then exiting, the Error occurs.

 

require("Scripts/constants/collision_const")
require("Scripts/constants/engine_const")
require("Scripts/LinkedList")
require("Scripts/filesystem")
require("Scripts/math/math")

function round(num, idp)        
return tonumber(string.format("%." .. (idp or 0) .. "f", num))
end

function playercreation() --Function to create a player controller and set camera variables
controller=CreateController(1.8,0.45,0.25,45)
controller:SetCollisionType(COLLISION_CHARACTER,0)
controller:SetMass(10)
if standalone==1 then        
controller:SetPosition(Vec3(-20,1,-5))
else        
controller:SetPosition(fw.main.camera.position)
end
camerapitch=fw.main.camera.rotation.x
camerayaw=fw.main.camera.rotation.y-110
camera = fw.main.camera
end

BLEND_NONE=0
BLEND_ALPHA=1

if fw==nil then --we are not in Editor        
RegisterAbstractPath("")        
Graphics(1680,1050)        
fw=CreateFramework()        
scene=LoadScene("Maps/terrain_base.sbx")        
scene:SetCollisionType(COLLISION_SCENE)        
TFilter(1)        
AFilter(4)        
standalone=1
end

dx=0.0
dy=0.0
camerapitch=0.0
camerayaw=0.0
move=0.0
strafe=0.0

playercreation()--Call the controller function

HideMouse()
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)

--position
function DrawHUD(contr)        
SetBlend(BLEND_ALPHA)        
DrawText("position: "..round(contr.position.x,1)..","..round(contr.position.y,1)..","..round(contr.position.z,1),1,FontHeight()*1)        
--DrawText("rot: "..round(contr.rotation.x,3)..","..round(contr.rotation.y,3)..","..round(contr.rotation.z,3),1,FontHeight()*6)        
SetBlend(BLEND_NONE)
end

--main function
while KeyHit(KEY_ESCAPE)==0 do        
jump=KeyHit(KEY_SPACE)*6.0        
if controller:IsAirborne()==1 then jump=0 end        
local time = AppTime()/3200.0        
local frame = time*(179.0-96.0)+96.0        
frame=Clamp( frame, 96, 179 )        

--Camera look        
gx=Round(GraphicsWidth()/2)        
gy=Round(GraphicsHeight()/2)        
dx=Curve((MouseX()-gx)/4.0,dx,3.0/AppSpeed())        
dy=Curve((MouseY()-gy)/4.0,dy,3.0/AppSpeed())        
MoveMouse(gx,gy)        
camerapitch=camerapitch+dy        
camerayaw=camerayaw-dx        
camerapitch=math.min(camerapitch,90)        
camerapitch=math.max(camerapitch,-89.99)       
fw.main.camera:SetRotationf(camerapitch,camerayaw,0,1)        
movespeed=4        
movesmoothing=10        
if controller:IsAirborne()==1 then                
movesmoothing=200        
end 

--Player movement        
move=Curve( (KeyDown(KEY_W)-KeyDown(KEY_S))*movespeed,move,movesmoothing)        
strafe=Curve( (KeyDown(KEY_D)-KeyDown(KEY_A))*movespeed,strafe,movesmoothing)        

--Update controller        
controller:Update(camerayaw,move,strafe,jump,40,10)        
fw:Update()        

--Position camera        
camera:SetPositionf(controller.position.x,controller.position.y+0.8,controller.position.z,1)        
time=AppTime()        

fw:Render()

DrawHUD(controller) 

--new Framework---------------------------------------------------------------------------------------------------

if KeyHit(KEY_F)==1 then 
FreeFramework(fw)
fw=CreateFramework()
SetGlobalObject("fw",fw)        
scene=LoadScene("Maps/terrain_base2.sbx")
playercreation()-- call the controller function again to create new controller and camera variables
end

------------------------------------------------------------------------------------------------------------------
Flip(0)
end
controller:Free()

ShowMouse()

AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64.

Link to comment
Share on other sites

Look in your atmosphere lua file and look for the word renderer. Where is it in there? I'm at work so I don't have the files but it might help point you in the right direction as to what's happening. Maybe in the Free method of the atmosphere something is incorrect?

Link to comment
Share on other sites

are you saying this code causes that error?

 

in any case, that error is telling you exactly where the problem is: the environment_atmosphere lua script on line 42.

 

fw.renderer:SetBackgroundMode(1)

 

not familiar with the backgroundmode... but now the framework commands are built into lua... so any of the commands in the atmosphere file that use the 'fw.renderer' could be removed and just replaced with the command itself...

 

for example:

fw.renderer.SetSkybox(nil)

would become:

SetSkybox(nil)

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

gordonramp's code works fine, and I can switch between 2 maps.

The error comes from the sbx file itself, which comes also when you load it first.

 

The sbx file which causes this error is using some old model scripts which need to be adjusted to work with the latest LE 2.3.

 

I think I will write a LE 2.3 fix pack 1, which fixes all model scripts and missing properties and all kinds of stuff which Josh forgot to do, or didn't have time. He doesn't want them as bug reports either :P

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Lumooga,

You may be correct but if I use the 2.3 'train' and 'tunnels' .sbx maps then the same thing occurs. The code has to be run from outside of the Scripting Editor for the Error to occur. As it would in a Game situation. :P

AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64.

Link to comment
Share on other sites

I made a simple flat terrain one texture no atmosphere and used the train.sbx all works fine the app changes map and no error when exiting.

 

Add an atmophere to the blank map and the error occurs.

 

This was done outside of the editor. So there is a problem.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

I should say done outside of the 2.3 Editor, oddly running the script from the Lua Editor seems to not produce the error, but draging the script onto the Engine.exe does.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Yeah, it must be a bug in engine.exe, if it works from Editor. There shouldn't be any difference how Lua scripts works in both.

 

 

Thats what I thought, maybe Gordon can try it and see if his error goes and its not just a fluke for me and the maps I am using? :D

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Yeah, it must be a bug in engine.exe, if it works from Editor. There shouldn't be any difference how Lua scripts works in both.

 

 

This is why I think there should only be the editor. There should be a command line switch where you pass your key to turn it into the editor and when that switch is missing it acts as an engine. At least they will never have a chance to get out of sync then.

Link to comment
Share on other sites

i dont think this is a bug. I can get rid of this error just by commenting out one line:

--FreeFramework(fw)

 

my guess is that when you free the framework it will cause issues with items that still exist that use the 'fw'... so i assume you need a way to free all of the scene's entities first before you free the framework.

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

i dont think this is a bug. I can get rid of this error just by commenting out one line:

--FreeFramework(fw)

 

my guess is that when you free the framework it will cause issues with items that still exist that use the 'fw'... so i assume you need a way to free all of the scene's entities first before you free the framework.

 

yep, just tried that and it does get rid of the error.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

actually after looking at the engine.log, when you load a new scene it automatically frees the previous scene's model classes and deletes the gmf's... so i don't know if you necessarily need to free the framework or loop thru the scene entities and remove them

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

I was assuming that FreeFramework() would actually free its worlds first, but perhaps it doesn't do that, so you would need to free the worlds manually before calling FreeFramework(), or maybe there is a fw:Free() method which you can call before actually freeing the fw object itself using FreeFramework().

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

actually after looking at the engine.log, when you load a new scene it automatically frees the previous scene's model classes and deletes the gmf's... so i don't know if you necessarily need to free the framework or loop thru the scene entities and remove them

 

 

Seems to be the case otherwise this shouldn't work should it when commenting out that line? maybe LoadScene() frees everything on initialising?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

I certainly hope that LoadScene() doesn't free anything, since it would break a lot of game logic and possibilies to use cascaded scenes (like a common scene, and differential scene).

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

what about ResetFramework() ?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

I certainly hope that LoadScene() doesn't free anything, since it would break a lot of game logic and possibilies to use cascaded scenes (like a common scene, and differential scene).

 

i can do that right now by commenting out the CreateFramework()... it will load the new scene into the existing scene... so it appears that CreateFramework is freeing everything...

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

i can do that right now by commenting out the CreateFramework()... it will load the new scene into the existing scene... so it appears that CreateFramework is freeing everything...

Macklebee, did you mean.. 'comment out FreeFramework(fw)' because when I do that for the second scene it loads and exits without an error. My only hope is that everything is in fact being deleted by CreateFramework() or Loadscene(), so that there is no performance hit down the track.

 

Update: There appears to be no performance loss when switching from scene to scene apart from the altering size of the scene. On to the next conundrum..Thanks :D

AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64.

Link to comment
Share on other sites

Macklebee, did you mean.. 'comment out FreeFramework(fw)' because when I do that for the second scene it loads and exits without an error. My only hope is that everything is in fact being deleted by CreateFramework() or Loadscene(), so that there is no performance hit down the track.

 

Update: There appears to be no performance loss when switching from scene to scene apart from the altering size of the scene. On to the next conundrum..Thanks :)

 

Yes, it appears that FreeFramework was the cause of the error. If you look at the engine.log, it appears when the second CreateFramework is called it frees/deletes the entities in the other scene. I guess if you wanted to use FreeFramework you would need to 'manually' loop thru all of the scene entities and free them, then free the framework to avoid that error.

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