Jump to content

debug char. script please.


VicToMeyeZR
 Share

Recommended Posts

Can someone give me an idea what I got wrong here.

 

I can put the model in the editor, but as soon as I set the values for the idle animation I get Exception violation, and it crashes.

 

Thanks

require("scripts/class")

local class=CreateClass(...)


function class:InitDialog(grid)
self.super:InitDialog(grid)
group = grid:AddGroup("Animations")
group:AddProperty("idle_start", PROPERTY_INTEGER, "Idle Start Frame")
group:AddProperty("idle_end", PROPERTY_INTEGER, "Idle End Frame")
group:AddProperty("walk_start", PROPERTY_INTEGER, "Walk Start Frame")
group:AddProperty("walk_end", PROPERTY_INTEGER, "Walk End Frame")
group:AddProperty("run_start", PROPERTY_INTEGER, "Run Start Frame")
group:AddProperty("run_end", PROPERTY_INTEGER, "Run End Frame")
group:AddProperty("jump_start", PROPERTY_INTEGER, "Jump Start Frame")
group:AddProperty("jump_end", PROPERTY_INTEGER, "Jump End Frame")
group:AddProperty("crouch_start", PROPERTY_INTEGER, "Crouch Start Frame")
group:AddProperty("crouch_start", PROPERTY_INTEGER, "Crouch End Frame")
group:AddProperty("strafeleft_begin", PROPERTY_INTEGER, "Left Start Frame")
group:AddProperty("strafeleft_end", PROPERTY_INTEGER, "Left End Frame")
group:AddProperty("straferight_begin", PROPERTY_INTEGER, "Right Start Frame")
group:AddProperty("straferight_end", PROPERTY_INTEGER, "Right End Frame")
group:Expand(1)
end

function class:CreateObject(model)

local object = self.super:CreateObject(model)
object.model = model
object.framestart = tonumber(object:GetKey("idle_start"))
object.frameend = tonumber(object:GetKey("idle_end"))

Notify(object.framestart)

function object:SetKey(key,value)
	if key=="idle_start" then
		self.idle_start = tonumber(value)
	elseif key=="idle_end" then
		self.idle_end = tonumber(value)
	elseif key=="walk_start" then
		self.walk_start = tonumber(value)
	elseif key=="walk_end" then
		self.walk_end = tonumber(value)
	elseif key=="run_start" then
		self.run_start = tonumber(value)
	elseif key=="run_end" then
		self.run_end = tonumber(value)
	elseif key=="jump_start" then
		self.jump_start = tonumber(value)
	elseif key=="jump_end" then
		self.jump_end = tonumber(value)
	elseif key=="crouch_start" then
		self.crouch_start = tonumber(value)
	elseif key=="crouch_end" then
		self.crouch_end = tonumber(value)
	elseif key=="strafeleft_start" then
		self.strafeleft_start = tonumber(value)
	elseif key=="strafeleft_end" then
		self.strafeleft_end = tonumber(value)
	elseif key=="straferight_start" then
		self.straferight_start = tonumber(value)
	elseif key=="straferight_end" then
		self.straferight_end = tonumber(value)
	else
		return self.super:SetKey(key,value)
	end
	return 1
end

function object:GetKey(key,value)
	if key=="idle_start" then
		return self.idle_start
	elseif key=="idle_end" then
		return self.idle_start
	elseif key=="walk_start" then
		return self.walk_start
	elseif key=="walk_end" then
		return self.walk_end
	elseif key=="run_start" then
		return self.run_start
	elseif key=="run_end" then
		return self.run_end
	elseif key=="jump_start" then
		return self.jump_start
	elseif key=="jump_end" then
		return self.jump_end
	elseif key=="crouch_start" then
		return self.crouch_start
	elseif key=="crouch_end" then
		return self.crouch_end
	elseif key=="strafeleft_start" then
		return self.strafeleft_start
	elseif key=="strafeleft_end" then
		return self.strafeleft_end
	elseif key=="straferight_start" then
		return self.straferight_start
	elseif key=="straferight_end" then
		return self.straferight_end
	else
		return self.super:GetKey(key,value)
	end
	return value
end

       function object:StartAnimations(movement)
               object.framestart = object:GetKey(movement .. "_start")
               return object.framestart
       end

       function object:EndAnimations(movement)
               object.frameend = object:GetKey(movement .. "_end")
               return object.frameend
       end

function object:LockKeys(model)

	self.super:LockKeys()
end

function object:UnlockKeys(model)

	self.super:UnlockKeys()
end

function object:UpdateMatrix()

end

function object:Reset()

end

function object:SetTarget(target,index)

end

function object:Collision(entity,position,normal,force,speed)

end

function object:ReceiveMessage(message,extra)
	if message=="forward" then
--[[		elseif message=="reverse" then
	elseif message=="mleft" then
	elseif message=="mright" then
	elseif message=="tleft" then
	elseif message=="tright" then
	elseif message=="crouch" then
	elseif message=="jump" then
	elseif message=="attack" then ]]--
	else
		self.super:ReceiveMessage(message,extra)
	end
end

function object:Render()

	object.framestart = object:StartAnimations("idle")
	object.frameend = object:EndAnimations("idle")

	if object.frameend ~= nil and object.frameend ~= 0 or object.framestart ~= nil then
		object.frame = math.fmod(AppTime()/35, object.framestart - object.frameend) + object.framestart
		Animate(object.model, object.frame, 0.5, 0, true)
	end

end

function object:Free(model)

	self.super:Free()
end

end

function class:Free()

self.super:Free()
end

AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD

76561197984667096.png

Link to comment
Share on other sites

You know what we should play around with for storing character animations. Instead of storing them in settings to the model which is limiting, we should store them in an xml file OR sqlite file. We could make a setting that points to the xml file/sqlite to use. This would be so much more dynamic.

Link to comment
Share on other sites

VicToMeyeZR, are you going to pursue this idea then? If so could you do the XML route and I could take the sqlite route. I'd like to have both options for people. If you come up with a structure I'll make a sqlite file that has a table with the same fields. Then in the setkey section we can fill out a lua table that holds all the animation information from the file they selected.

Link to comment
Share on other sites

forgive my ignorance but what exactly is the advantage over a .ini ?

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

xml is just a little more structured and standard than an ini file these days.

 

 

M'kay so no real benefit then, I was wondering why write the XML then load an XML parser in Lua to read it to store the info in the lua properties.. when a .ini would simply fill in the blanks on load, the .ini would simply be something like:

 

idle_start=210
idle_end=234
walk_start=235
walk_end=259

ect ect ....

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

To be honest when I suggested using an xml file I was more thinking that you could assign an xml file for each instance of the model and it would have the animation information for that instance. I wasn't thinking that they would all share the same names and number of animations. With indie developers getting models from all over the place they most likely won't have the same number of animations at the same frames so each different character model would needs it's own animation information file, which would be custom to that instance of the character object.

 

 

VicToMeyeZR was thinking slightly differently than I was. In the example he put together then yes using the ini would make sense. In the way I was thinking an ini wouldn't work the same way.

Link to comment
Share on other sites

I wasn't thinking that they would all share the same names and number of animations. With indie developers getting models from all over the place they most likely won't have the same number of animations at the same frames so each different character model would needs it's own animation information file

 

 

Which is true, but you'd just write a new .ini file as you would have to write the new animation info in XML .. the outcome remains the same?

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

You'd have to parse the ini file yourself then though. The way this Thingoid is setup is that it's just one generic Thingoid in the editor. You place it in your scene and it creates a character controller. Via a setting is where you assign what mesh you want to use. That mesh would have it's own animation information which could be different from another mesh.

 

The reason I do characters this way instead of the way Josh was thinking, which would be that you actually place each model into your scene from the tree view on the right in the editor, is because characters all share common code they need to do. So instead of copying and pasting that code into each character model lua file, I have 1 lua file that runs the character code and I select which mesh to assign it to. It's kind of like an object oriented way of thinking. If I was programming this in an OOP language I would make a Character class. That class holds all the code and it has properties. One of the properties would be what mesh to use for this character, and another would be that meshes animation information.

 

The ini file system he has setup will be auto populated for that model. In this case the model that's being used when I drag my character thingoid into the scene is a circle model. The only purpose of it is to allow me to move the position of the controller and the mesh I assinged to it in the editor. The real model being used in the game is the mesh you assign via a property.

 

So given that information you have to parse out a file that has stored data, if it's ini or xml or some other protocol you come up with. Xml is just very common and there are tons of already premade libraries and code out there that allows you to easily parse complex xml files.

Link to comment
Share on other sites

ok I see, I did not realise it was for a hemorrhoid thingy, so this is for apps predominantly or exclusively written in lua?

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

Mostly yes. I know VicToMeyeZR started the topic but he's playing off the character thingoid I made and improving on it, and all I'm doing these days is lua based. My goal is to make a bunch of different useful thingoids so a full game can be made. My current platform game that I'm making will be lua based with a possible dll loaded from lua for anything that is very speed sensitive. But ultimately it's ran from lua.

 

Basically my goal is to prove that with some modifications to how some lua stuff is done, it's possible to make an entire game from lua using LE.

Link to comment
Share on other sites

Are there any concerns (speedwise that is) to using lua for controllers?

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 haven't seen any. Speedwise it runs great. The one big catch with doing this, which reminds me I should create a request for this, is that currently bodies that you create via lua code, you have no way of getting a collision function called on them. They will collide and act on physics, but you can't link to a callback on them to do certain things when something collides.

 

An example with this is creating area/volume triggers. I have a thingoid that is just a physics body. You can change the size of it by the settings and it recreates a new physics body when you do, because you can't scale physics bodies and have them work correctly. This works create, because it's much faster to do it in the editor where you can size things up and resize on the fly to create any size body where you want it. The issue is when something hits it, say like the player, there is no way to know that because you can't get a function called in lua. Currently that only works when you drag an actual model into your scene, then that lua classes collision method is called.

Link to comment
Share on other sites

Probably not. All they do is call engine code so the only real overhead is the function calling overhead and the binding code. Since it's only run once per frame or physics update and it's not doing any of the heavy lifting itself, then it's probably negligible.

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

Probably not. All they do is call engine code so the only real overhead is the function calling overhead and the binding code. Since it's only run once per frame or physics update and it's not doing any of the heavy lifting itself, then it's probably negligible.

 

 

ok, makes sense.

 

I think people are scared to start using lua because they are so worried about the speed. It's honestly not bad. For me the rapid development I get from seeing my code changes instantly far out weighs the few drops in FPS.

 

 

Not really a "fear of it" with me its just I have not gotten around to it yet so am currently trying to get a feel for pro's and con's.

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

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