Jump to content

My First Game Path


fumanshoo
 Share

Recommended Posts

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

Link to comment
Share on other sites

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()

Link to comment
Share on other sites

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()? =)

(Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI)

Link to comment
Share on other sites

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)

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

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

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

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

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