Sign in to follow this  
AlexanderSchittler

Using LUA with XNA as events

Recommended Posts

So, I've been watching some tutorials on XNA and it's general structure (components and such stuff) and I think I'm ready to plan out my first "game". I choose something that seemed to be fairly easy - a visual novel. So basically just displaying text and predefined sprites with litte to no movement. As the script of the actual "happening" I wanted to use LuaInterface (just because Lua is so easy to use), but I've ran into a problem I just can't find a solution for: If I want to do my whole event logic in a LUA file, I can't break out from a script and thereforce would break the game loop, but on the other hand I can't just read the file line by line (which would break if's and such). I'm looking for a way to suspend the execution of a lua script and step back in whenever Update() is called.

Opening another thread seems like a dirty solution to me, right?

Share this post


Link to post
Share on other sites
Since no one else is replying to this, I'll give you what i know :)

You will need to load a special library for this. A good resource to start doing this is:

www.godpatterns.com/2006/05/scripting-with-lua-in-c.html

I have never fully encorporates a scripting panguage into Csharp, but it can be done. It takes a bit of work and learning though.

Share this post


Link to post
Share on other sites
[quote name='Morley' timestamp='1318618149' post='4872627']
Since no one else is replying to this, I'll give you what i know :)

You will need to load a special library for this. A good resource to start doing this is:

www.godpatterns.com/2006/05/scripting-with-lua-in-c.html

I have never fully encorporates a scripting panguage into Csharp, but it can be done. It takes a bit of work and learning though.
[/quote]

This isn't my problem, I do have a lua library (the same you've linked me to) and I do know how to use it, but I'm looking for a way to script events, to have a script running "semi-asyncronous" without starting a new thread (by "suspending" the execution of the script)

Share this post


Link to post
Share on other sites
Could you give an example of such a method of execution (i.e another game/engine that does this)?

I have only seen scripting through the creation of new threads, really.

EDIT: [b]Take arbitus's example[/b]. I believe also that that is what your looking for :)

Share this post


Link to post
Share on other sites
[quote name='Morley' timestamp='1318881460' post='4873602']
Could you give an example of such a method of execution (i.e another game/engine that does this)?

I have only seen scripting through the creation of new threads, really.

EDIT: [b]Take arbitus's example[/b]. I believe also that that is what your looking for :)
[/quote]

I'll look into it, I'd like to have a lua script like this:
[code]

//setup "scene", like starting a typewriter effect

while (condition) { //condition = "scene" is animating
suspend() //return to game loop, on the next update() it will step in here
}[/code]

I just want the script to be linear (RPG Maker style) without neccessarily sacrifcing the precision of just one thread.

Share this post


Link to post
Share on other sites
[quote name='X3N' timestamp='1318947449' post='4873920']
I'll look into it, I'd like to have a lua script like this:
[code]

//setup "scene", like starting a typewriter effect

while (condition) { //condition = "scene" is animating
suspend() //return to game loop, on the next update() it will step in here
}[/code]

I just want the script to be linear (RPG Maker style) without neccessarily sacrifcing the precision of just one thread.
[/quote]

Yes, you are describing coroutines, almost exactly. Note since you are already using XNA that you can create a sort of coroutine in .NET using Enumerators. Unity does this, and I am toying with the concept myself. Since you are already working in .NET, you might want to just investigate scripting via C#/.NET.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this