Public Group

# Using LUA with XNA as events

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

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

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 on other sites
It sounds like you want to use coroutines.

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

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

##### Share on other sites

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.

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 10
• 11
• 14
• 10
• 25
• ### Forum Statistics

• Total Topics
632652
• Total Posts
3007649
• ### Who's Online (See full list)

There are no registered users currently online

×