I'm working on a RPG in C using Lua for event scripting like NPC behavior. I ran into a design problem.
I have created Lua threads in the C API for each game object which can be a NPC. So this:
function objinteract(o)
if o.id == 1 then
textbox("Hello I'm ",o.name,"!");
yield();
end
end
Is what happens when the player talks to the NPC. But I'm not sure on how to implement walking/wandering.
I could do it like this:
function update(o)
if o.id == 0 then
movewest(o.id,3); -- move NPC three tiles west.
yield();
movenorth(o.id,3); -- move NPC three tiles north.
yield();
moveeast(o.id,3); -- move NPC three tiles east.
yield();
movesouth(o.id,3); -- move NPC three tiles south.
yield();
end
end
Though this is a good solution, if the NPC were to be talked to, the flow of the script would be lost because I'm using one thread for each NPC. Any solutions for this?