Jump to content
  • Advertisement
Sign in to follow this  
Califer

object methods with Lua

This topic is 3252 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm writing an XNA game with Lua scripts. I'm getting the basics of Lua, but I've run into a problem now that I'm setting up abilities to have scripts. I have two dynamic lists, one for the party and one for enemies. Enemies can come and go during battles so the list can't be static. The problem is, how can I connect the lua script with member variables? If I have a function on an entity (the party and the enemies are all entities) how can I call that on the entity who is currently running the ability? The only options I seem to have are lua.dostring and lua.dofile. For example, say there is an ability that cures the user of blindness. I want both the player and the enemy to have the same ability but still have it work only on the caster. The combat is time based, so when I run the script for the ability the caster is current. Also, and ideas on how I can get it to affect all enemies/allies?

Share this post


Link to post
Share on other sites
Advertisement
I'm not too clear with the lua binding libraries for C# or .Net languages in general; but this is how I do it in C++.

I create an overall interface that both the player and enemy will implement - something like IGameEntity. This interface controls status conditions, energy, health, and a host of things that lua might want to modify.

Abilities can then be made by simply creating a function that takes a pointer to an entity as an argument.

sight_beyond_sight =
{
on_cast = function( casterEntity )
casterEntity:cure_status( Status.Blind );
end
}


or something like that.

You'll have to look into your binding library to see how to bind classes, member functions and other shenannigans; though.

Share this post


Link to post
Share on other sites
pointer is a bad name for that, since that implies a pointer to an address in memory, and in C# and Lua there is no such thing.

Anyways, my question to you is can you set an integer in C# and pass it to / see it in lua? If so this means you have lua bindings for C#.

If not, Google LuaInterface and download and install it to your project.

Not sure if XNA allows you to link .dlls and libs, but hopefully it does.

you should be able to define an object in C#, give it to lua, and refer to the functions of that object using either the . operator or the : operator, depending on how you have it set up, but again, if you cant answer the above question you need to get that going first.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!