forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Yeilding from C functions

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
gregi



Joined: 14 Oct 2005
Posts: 2

PostPosted: Fri Oct 14, 2005 1:26 am    Post subject: Yeilding from C functions Reply with quote

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.
Back to top
View user's profile Send private message
flattspott



Joined: 22 Aug 2005
Posts: 22

PostPosted: Fri Oct 14, 2005 11:44 am    Post subject: Reply with quote

How about

atHouse = false
while not atHouse do
Walk(Fred,House)
if Fred_spot == House_Spot then atHouse = true end
end
LookAt(Fred,Door)
Back to top
View user's profile Send private message
gregi



Joined: 14 Oct 2005
Posts: 2

PostPosted: Fri Oct 14, 2005 6:34 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group