Lua
Posted: Wed Jul 21, 2010 3:47 am
Lua scripting is working!
Let me explain how it woks:
Each "Dynamic Object" can have an lua script that runs a lua "step" function at each frame, this "step" can see a lot of C++ pre-maded methods (like walk, turn, faceToPlayer, showDialog, etc) and of course you can define functions in lua to create the dynamic object behavior.
A dynamic object can also have a "onClick" and a "onAttacked" function, this will be called when the player clicks or attack the object, this way you can define a routine to decrease enemy life when he is attacked by player for example (and counter-attack the player, hehe).
Each object has his own lua_state, that means his functions and variables are LOCAL, and one object cannot interfere in another object. To share data between objects you need to set an global variable (by calling a function like setGlobalVar("playerMoney", 20) ) , this is made by my LuaGlobalCaller class, this class stores and manipulates all global vars. Global vars also will be used to save the game during gameplay.
The use of globals are interesting to manage the in-game quests, for example:
Imagine the following quest: Player needs to kill 10 wolves to get access to a misterious house.
-> you can create an global named "Key" and another "WolvesCounter";
-> you increase WolvesCount global each time on wolve die;
-> when WolvesCount >= 10 the global Key becames true and the Player has access to the house.
I've posted two images of the IRB Lua Editor. check it at the screenshots section: http://irrrpgbuilder.sourceforge.net/
Let me explain how it woks:
Each "Dynamic Object" can have an lua script that runs a lua "step" function at each frame, this "step" can see a lot of C++ pre-maded methods (like walk, turn, faceToPlayer, showDialog, etc) and of course you can define functions in lua to create the dynamic object behavior.
A dynamic object can also have a "onClick" and a "onAttacked" function, this will be called when the player clicks or attack the object, this way you can define a routine to decrease enemy life when he is attacked by player for example (and counter-attack the player, hehe).
Each object has his own lua_state, that means his functions and variables are LOCAL, and one object cannot interfere in another object. To share data between objects you need to set an global variable (by calling a function like setGlobalVar("playerMoney", 20) ) , this is made by my LuaGlobalCaller class, this class stores and manipulates all global vars. Global vars also will be used to save the game during gameplay.
The use of globals are interesting to manage the in-game quests, for example:
Imagine the following quest: Player needs to kill 10 wolves to get access to a misterious house.
-> you can create an global named "Key" and another "WolvesCounter";
-> you increase WolvesCount global each time on wolve die;
-> when WolvesCount >= 10 the global Key becames true and the Player has access to the house.
I've posted two images of the IRB Lua Editor. check it at the screenshots section: http://irrrpgbuilder.sourceforge.net/