fumanshoo Posted December 27, 2012 Share Posted December 27, 2012 ok, so forgive me if this is the ****tiest script you have ever witnessed, but this is my first time scripting within the Editor and I am very ****ing confused. So what I am trying to do is make a simple third person camera around my character, "steamPunk". I am putting this script in the GameScript Path and I get a message "EXCEPTION_ACCESS_VIOLATION" and then the Editor closes. If this is completely off, it's most likely because I don't understand the "class.lua" file worth ****. If it has nothing to do with the class.lua" file, please explain what I am doing wrong here. controller = CreateController(1.8,0.45,0.25,45) controller:SetCollisionType(COLLISION_CHARACTER) controller:SetMass(10) controller:Move(Vec3(0,1,0)) pivot = CreatePivot(steampunk) camera = fw.main.camera camera:SetPosition(Vec3(3,2,-10)) camera:SetParent(pivot) HideMouse() while KeyHit (KEY_ESCAPE)==0 do MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2) camRotation = Vec3(0) dx = 0.0 dy = 0.0 mx=Curve(MouseX()- GraphicsWidth()/2,3.0/AppSpeed()) my=Curve(MouseY()- GraphicsHeight()/2,3.0/AppSpeed()) MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2) camRotation.x = camRotation.x + my / 8 camRotation.y = camRotation.y - mx / 8 camRotation.x = math.min(camRotation.x, 45) camRotation.x = math.max(camRotation.x, -15) move = Curve( (KeyDown(KEY_W)-KeyDown(KEY_S)) * 5, move , 3 ) strafe = Curve( (KeyDown(KEY_D)-KeyDown(KEY_A)) * 5, strafe , 3 ) fw:Update() pivot:SetRotation(camRotation,1) fw:Render() Flip(0) end ShowMouse() oh, and so far, it does create a controller, but the camera stays stationary and the character is not loaded... or do I need to load the character? I already have it loaded in the editor, so I suspected that it would automatically rotate along the character... Quote Link to comment Share on other sites More sharing options...
fumanshoo Posted December 27, 2012 Author Share Posted December 27, 2012 ok, so I was wrong, I do need to load the character, but I still don't understand why I can't move and why my camera is not rotating around the controller. Quote Link to comment Share on other sites More sharing options...
fumanshoo Posted December 27, 2012 Author Share Posted December 27, 2012 Nevermind everything I just said... except the "EXCEPTION_ACCESS_VIOLATION" part. Every time I press escape, it pulls up that message and leaves the Editor.... this is my script... require("Scripts/math/math") controller = CreateController(1.8,0.45,0.25,45) controller:SetCollisionType(COLLISION_CHARACTER) controller:SetMass(10) controller:Move(Vec3(0,1,0)) character = LoadModel("abstract::steampunk.gmf") character:SetParent(controller) character:SetRotation(Vec3(0,180,0)) pivot = CreatePivot(steampunk) pivot:SetParent(controller) camera = fw.main.camera camera:SetPosition(Vec3(3,2,-10)) camera:SetParent(pivot) move = 0 strafe = 0 MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2) camRotation = Vec3(0) dx = 0.0 dy = 0.0 HideMouse() while KeyHit (KEY_ESCAPE)==0 do if KeyDown(KEY_LSHIFT)==1 then camera:SetPosition(Vec3(.5,1.35,-1)) controller:Crouch(1) cameraHeight = 0.3 moveSpeed = 3 strafeSpeed = 3 else camera:SetPosition(Vec3(0,1.35,-2)) controller:Crouch(0) cameraHeight = .5 moveSpeed = 1 strafeSpeed = 1 end mx=Curve(MouseX()- GraphicsWidth()/2,3.0/AppSpeed()) my=Curve(MouseY()- GraphicsHeight()/2,3.0/AppSpeed()) MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2) camRotation.x = camRotation.x + my / 8 camRotation.y = camRotation.y - mx / 8 camRotation.x = math.min(camRotation.x, 45) camRotation.x = math.max(camRotation.x, -15) move = Curve( (KeyDown(KEY_W)-KeyDown(KEY_S)) * 5, move , 3 ) strafe = Curve( (KeyDown(KEY_D)-KeyDown(KEY_A)) * 5, strafe , 3 ) controller:Update(camRotation.y, move * moveSpeed, strafe * strafeSpeed, jump, 25, 10, KeyDown(KEY_LSHIFT)) fw:Update() pivot:SetRotation(camRotation,1) fw:Render() Flip(0) end ShowMouse() Quote Link to comment Share on other sites More sharing options...
macklebee Posted December 27, 2012 Share Posted December 27, 2012 havent tried it but just looking at the following line would seem to cause an issue: pivot = CreatePivot(steampunk) as 'steampunk' should be either the controller/character... 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...
fumanshoo Posted December 27, 2012 Author Share Posted December 27, 2012 Didn't see that, thanks for pointing it out. Everything works fine other than the fact that when I press escape, it comes up with a message saying "EXCEPTION_ACCESS_VIOLATION" and then the Editor closes. Quote Link to comment Share on other sites More sharing options...
DaDonik Posted December 27, 2012 Share Posted December 27, 2012 Error handling in the LE2 Editor is not really existing. I would highly suggest not to use LUA with LE2 if you are new to programming. Even though i'm quite proficient in C++, i still have problems using LUA scripting. A simple typo will cause that "EXCEPTION_ACCESS_VIOLATION", while any C++ compiler will complain about it. Everything works fine other than the fact that when I press escape, it comes up with a message saying "EXCEPTION_ACCESS_VIOLATION" and then the Editor closes. Normally after the main loop a program closes. At that point the engine is already unloaded. So why are you calling ShowMouse()? =) Quote (Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI) Link to comment Share on other sites More sharing options...
cassius Posted December 27, 2012 Share Posted December 27, 2012 I would use Blitzmax or just plain c rather than lua. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
macklebee Posted December 27, 2012 Share Posted December 27, 2012 well the EAV is caused by the issue with parenting the camera to the pivot... when you press escape to stop the game script, the pivot no longer exists but the framework camera still has it as a parent. also, as far as parenting the pivot to the controller, these two lines are setting the parent to nil then to the controller... pivot = CreatePivot(steampunk) --'steampunk is not an entity so its equal to nil' pivot:SetParent(controller) you could have just written it like this: pivot = CreatePivot(controller) as the only parameter to use is to set the entity parent As far as the EAV, you have to set the camera's parent to nil after the main loop; fw.main.camera:SetParent(nil) 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...
ChrisMAN Posted December 27, 2012 Share Posted December 27, 2012 I don't code in the editor because it is so frustrating to deal with the crashes. Quote Link to comment Share on other sites More sharing options...
macklebee Posted December 27, 2012 Share Posted December 27, 2012 like chrisman suggests, i would use a standalone lua script to load the scene instead of running the game in the editor... it removes a lot of the frustration of forgetting to save your scene and restarting the editor all the time. lua is fine to program with as long as you are willing to troubleshoot errors by constantly checking the engine.log 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...
ChrisMAN Posted December 27, 2012 Share Posted December 27, 2012 i run my game from the terminal instead of checking the logs, but yes that is my workflow. I have considered writing blender -> scene exporter. I wouldn't mind an excuse to learn python. Quote Link to comment Share on other sites More sharing options...
fumanshoo Posted December 27, 2012 Author Share Posted December 27, 2012 @DaDoink: I added ShowMouse() simply because in the "driver" lua file, shows mouse is at the end, so I suspected that I needed that in order to have the mouse back in the editor. Thank you for all the responses thgough! For now, I think I will stick with the stand alone Lua script simply because I am VERY new to programming and so far, it is the easiest in my opinion to use. I have heavily considered learning C++ even though it confused the hell out of me. I really want to learn C++ but for now, I think I will stick with Lua until I perfect it. Quote 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.