Jump to content
  • Advertisement
Sign in to follow this  
DemoDYL

Lua: Can I pause its running?yield and resume?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

A c function "Fight" have been registered. Then I use it in lua to start a fight. The lua file: ... Fight(); --here I want to pause it until the c function Fight is finished if(Fight_Result==1) ... win else if(Fight_Result==0) ... lose how to? yield and resume?

Share this post


Link to post
Share on other sites
Advertisement
Unless you're doing some kind of multi-threading, Lua executes commands one at a time -- when you call a function from lua it doesn't go on to the next line until the function returns

Share this post


Link to post
Share on other sites
So the c function "Fight" may be :
Fight()
{
while(!bFinished)
{
...
}
}
lua will run the next command until "Fight" returns .
But I get another problem: I can't use lua to make the role do something in fight~
because the running of lua is paused.

Share this post


Link to post
Share on other sites
So, this is not so much about 'pausing' Lua, but about being able to call into it recursively, right? ie. You have a Lua function that calls a C function, which in turn calls Lua stuff. Is it possible to use a different Lua_state for the inner stuff? If not, what you probably want to do is wrap a C function that sets a flag noting that you're starting a fight, then call lua_yield. Once the fight is over, it can call lua_resume. There might be some other details in there though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!