Yeilding from C functions

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
gregi
Posts: 2
Joined: Fri Oct 14, 2005 12:25 am

Yeilding from C functions

Post by gregi »

I've only been learning Lua for just over a day so bear with me. I'm looking to use Lua to implement game scripts which can take some time to run through.

e.g. This is a crude example...

Walk(Fred,House)
LookAt(Fred,Door)
Say("Is Anybody Home")

Commands such as Walk() would be implemented in C. When they are first called it would make the character start walking. However, I do not want the script to advance onto the next function LookAt() until Fred has arrived at House.

From the game side of things this would be a script which the character is updating every frame. In some cases you might want the whole of the script to execute in a single update call, but in this case I want the script to stop, and then restart the next frame on the same command, until that command is happy it has completed.

I have been looking at using the yield functionality in coroutines. So the first call would cause the character to make a path to his target location then yield, subsequent calls would continue to yield until the character had arrived, or failed. However, on initial inspection it seems I am not allowed to call yield from within the C functions such as Walk(), LookAt() etc.

Does anyone have any better ideas on how I can use Lua to do this? I've noticed a patch called ImprovedCoroutinesPatch which sound like it might solve my problem, but I'm still playing around with it.

Thanks.
flattspott
Posts: 22
Joined: Mon Aug 22, 2005 4:06 am

Post by flattspott »

How about

atHouse = false
while not atHouse do
Walk(Fred,House)
if Fred_spot == House_Spot then atHouse = true end
end
LookAt(Fred,Door)
gregi
Posts: 2
Joined: Fri Oct 14, 2005 12:25 am

Post by gregi »

Thanks, however the idea is to create scripts which are fairly simple to read and can hopefully be written by people with limited programming ability. I want to avoid too much branching. I know the approach can work as I have done it in custom scripting languages I have written myself for other games. I'm just curious as to if its possible with Lua.
Post Reply