How to make engine independent from Lua scripts?

Started by
1 comment, last by GameDev.net 18 years, 1 month ago
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?
Advertisement
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 filesubroutine exist(arRs) {   walk on peg leg   say are}// nother robot filesubroutine exist(squack) {   be a pretty birdy   eat the seed}// main programfor(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.
[ Six Hour Game Contest | ( Thread | Blog | Wiki | 6hour Bio ) ][ Website | (Blog | Gallery ) ]
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").

This topic is closed to new replies.

Advertisement