Using LUA with XNA as events

Started by
5 comments, last by arbitus 12 years, 6 months ago
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?
Advertisement
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.
Morley

Aspiring programmer, modeler and game designer.

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.


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)
It sounds like you want to use coroutines.
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: Take arbitus's example. I believe also that that is what your looking for :)
Morley

Aspiring programmer, modeler and game designer.

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: Take arbitus's example. I believe also that that is what your looking for :)


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


//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
}


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

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


//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
}


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


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.

This topic is closed to new replies.

Advertisement