Resuming execution of a LUA script???

Started by
2 comments, last by enygmyx 20 years, 11 months ago
hello ppl, i am working on a 3D game engine and i wanted to add scripting support to it. i have chosen LUA as the scripting language and have done some basic work.( still i am a comlepte noob in terms of LUA .....) wat i basically want to do is like this : for example a patrol script .... that wud enable an NPC to patrol between waypoint 5 and 6. MOVE(WP5) IDLE() MOVE(WP6) IDLE() i know the basics like exporting functions to LUA and stuff the problem that i am facing is that for that above script to work i need to stop further execution of the script once the move function is called ...... and resume execution (once the bot has moved to the given location .... ) from the next statement i.e. IDLE() well one of the reasons that i want this to happen this way is that the script is called(executed) at every frame to determine the bots behaviour. anybody has any ideas on this one ..... is there sumthin that i am doing wrong??? urgent help is needed. sorry for my poor english but i hope that i have expressed myself clearly .... enygmyx.
Advertisement
Hey there,

I''m having a similar problem as you. I''m thinking that an easy solution might be to read in the file, tokenize it around the pauses (Idle()) you want, and then use lua_dostring as warranted. I''m sure someone will post a better solution though.

-stilltjack
With the advent of Lua 5, there is a much better solution, involving Lua threads. If you look in the reference manual section 3.20, you'll see the functions lua_yield and lua_resume - I suggest you read this section thoroughly, as it provides exactly what you need.

What you will have to do, is make your MOVE function yield/pause the thread, and then call lua_resume when you want the script to start executing again.

John B

[edited by - JohnBSmall on May 15, 2003 7:46:38 PM]
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
One possibilty is to have the script called back when the action is completed or when/if something caused the action to fail. For example, in your script you tell the program to move your object to a certain way-point and if the object encounters resistance, then the script would then be called to take whatever action you wish. Also you should have the script set up a time interval for the script to be called for any bot logic that you might want it to do along the way. An example: you could have the script set up a 3 second callback timer when the bot is moving to waypoints. This way, you could have the bot check if any enemy are in range and if so, it can take another action like "attack enemy".

This topic is closed to new replies.

Advertisement