Sign in to follow this  
bartek_sc

How to make engine independent from Lua scripts?

Recommended Posts

bartek_sc    122
Hello. I'm working on game based on Lua scripts, they control robots (simple AI). But when script is writen badly like that: while a=1 then do something end and it is endless loop, all my game hangs out. How to prevent bugs like this?

Share this post


Link to post
Share on other sites
DakeDesu    100
Have the ai robot have a single function that gets called from the main program. That function will check what it should do at that instant. In the main program loop though the different robot functions.

thanks to the marvels of psuedocode I can show you:



// Robot file
subroutine exist(arRs) {
walk on peg leg
say are
}
// nother robot file
subroutine exist(squack) {
be a pretty birdy
eat the seed
}

// main program

for(EVER) {
get_input();
scripting(robot1).exist;
scripting(robot2).exist;
display_screen();
}



I wrote this in psuedocode because I do not feel the striking urge to debug a lue application, when pseudocode will help more.

Again the idea is to peeak into the character, have them make their choice, then go back to the rest of the look.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
read about lua coroutines.

so you could present your game logic as sequence of actions like

with coroutines it could look like this

movetodestination
if(yield)
playanim
if(yield)
movetodestination
if(yield)



coroutines it's not threads but close enough, so you call movetodestination, core changes their state and after you call yield another coroutine takes everything what's need to be done to reach destination. when destination reached movement algorithm resumes logic coroutine with some param (meaning of this param can be all you can imagine, but this time it can be "was destination reached or it can't be reached").

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