1

I am trying to implement the same kind of design as anyone who has successfully scripted a game without using lua as a config/callback file. I would like the functionality as follows:

in "EventIncountered.lua"

1    moveToPoint(500, 500)
2    --returns here when moving is done.
3
4    dance()
5    --return here when done dancing etc...

In the player class of my game I would like to have these functions update the fields that the player's position, animation etc... is a adjusted by every update frame. Then, when the desired state of the player is reached, the lua file should continue where it left off. I know it can be done and similar questions have been asked;however, all I have learned from them is how to use lua as a configuration file to read and call callback functions from on certain events(I even know of one question in which the person asking the question knew how to do this but was asking a higher level question about it). I know there is someone out there there who would be willing to share this well guarded secret.

rationalcoder
  • 1,587
  • 1
  • 15
  • 29
  • That sounds like you want to run each script as a coroutine and have those functions yield internally and then they can get resumed and return when "finished" but I don't know if that's actually a good idea or not. – Etan Reisner Sep 12 '14 at 03:57
  • you would call a specific function in the script, update for instance, which runs every frame and performs the lua actions. What ypur example shows is typically evaluated at load time and transcribed into native language code - meaning the script itself doesn't execute repeatedly and simply acts like a config file – CodeSmile Sep 12 '14 at 07:03

1 Answers1

0

I found a decent solution to the problem that uses an idea found in Game Coding Complete Fourth Edition

It describes a ProccessManager class that allows queuing of processes that are tended to each frame until that process is complete. The Process object that is queued would have some way of signaling that it is complete and a function pointer that would be called to tend to that process for that frame.

Although I do not actually want this functionality any more because I have learned a lot more about how scripting works in game engines, it is possible to expose functions to lua that enable your scripts to create and queue processes.

In the creation of these processes, a method of tending to that process(a function in a different script or something similar), a way to determine if that process has finished, and dependencies on other processes being finished can be specified.

The script would end up looking something like this:

-----queue_processes.lua-----

-- queueProcess(fileName, functionName, dependencies)
-- the lua function that corresponds to these processes would then 
-- need to return a special value to signal that it is done.

queueProcess("basic_processes.lua", "moveToRock", 0)
queueProcess("basic_processes.lua", "waitTenSeconds", moveToRock)
queueProcess("basic_processes.lua", "sayHi", waitTenSeconds)

-- the cool part about doing things this way is that
-- it wouldn't be hard to add logic to this file
-- and just keep queuing processes when others 
-- finish or certain conditions have been met.

You can use this idea to accomplish a lot of cool things with scripting. I hope this helps anyone that was in my position when I asked the question.

EDIT : This is a good answer to the question that took a few paragraphs. As such, it should not have been closed. At least I was able to leave this here so someone with a similar issues can find an answer.

rationalcoder
  • 1,587
  • 1
  • 15
  • 29