Jump to content

  • Log In with Google      Sign In   
  • Create Account


Correct way to implement a scripting language for game logic.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 zachprinz   Members   -  Reputation: 120

Like
1Likes
Like

Posted 17 August 2013 - 11:36 AM

I'm about to start scripting Lua for my current project. I'll be using Luabind to bind it to c++. But before I started scripting I wanted to make sure I understood how this is typically done, and what things it's typically done for. 

 

My understanding of it as it stands is that I will create a scripts folder in my project folder and put a few more folders in that specifying the type of scripts inside for organization. Inside those I'll make short .lua scripts for each type of enemy/item/etc. These scripts will contain a few methods like OnCreate() to set up the values of the c++ instance of "Enemy"

 

RPGProject
  --scripts
     --enemies
       --man.lua
       --goblin.lua
     --items
       --potion.lua
       --food.lua
 
When I start the game it will load the map (I'm using .tmx files for loading maps) and through reading the map it will find say an enemy on tile (16,12) with a name value of "man." It will create an instance of "Enemy.cpp" and in the constructor of "Enemy.cpp" it will take the name value and find "scripts/enemies/man.lua" and call the OnCreate() method of that .lua file which will set up the values that go along with the "man" enemy.
 
I also plan to have an Update() method that will keep track of AI and that particular enemies behavior. The Update() method will be called every time the enemy finished the last task provided by the Update() method.
 
I also plan to make similar scripts for abilities and actions/spells (like attacks or teleports) as well as quests (although those will be implemented fairly differently.)
 
I just want to make sure I'm on the right path with this as I haven't been able to find to many examples.
 
Thanks.


Sponsor:

#2 Krohm   Crossbones+   -  Reputation: 2748

Like
1Likes
Like

Posted 19 August 2013 - 02:07 AM

Without elaborating your design, it could be ok or not. So let me check if we are on the same mind set. Let's do that easily by considering items first.

Suppose we have:

  1. food - decreases hunger attribute by F
  2. potion - increases health attribute by P

This does not need scripting. Data-oriented design is sufficient.

Enemies are a thougher call. In general, enemies need to have a set of skills which is where scripting comes into play. Personally I would never allow a script to fully define an enemy: there must be a basic set of properties about them. I'd rather allow script callbacks to evaluate its attack logic or skill use.

In my experience, having a generic Update() call to be shared across all entities is a bit fragile in concept. Better to have things such as RunEnemyLogic() or Tick(time) if everything fails. I don't have an Update() call in my system - distributing script processing is left to the script itself.

So the enemies might be:

  1. man { model: "man.mdl";  skillSet="humanSkills.lua";  skillList="hide, evade, attack"; };
  2. goblin { model: "goblin.mdl";  skillSet="gobSkills.lua";  skillList="attack, fury, resistance"; };

Of course in this case you'd have to figure out a way to maintain, for each "skill" loaded and bound to each actor, a way to maintain its state and design all the proper interfaces. Allowing to "just do everything" might make sense but I'm not quite sold on it.



#3 L. Spiro   Crossbones+   -  Reputation: 9733

Like
2Likes
Like

Posted 19 August 2013 - 11:18 AM

In addition to what was just said, scripts are most-often used to respond to events, such as taking damage.

In many games a lot of the events sent to scripts are related to physics to allow them to override the default engine way of handling their collision with things.  For example, a ball may hit a wall but with script override it simply bounces off via the engine’s physics implementation.  An enemy brute may hit a wall and decide to stop, turn, and start pounding on it to break through.

 

Scripts can also be used inside triggers, which are bounding boxes that, when touched by the player, cause some event to happen.  A cut-scene for example, or the spawning of a bunch of enemies.

 

For the most part, thinking of a script as “the logic for an event” will keep you fairly safe, as long as you have a good understanding of what needs to be an event and what should not.

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS