• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
zachprinz

Correct way to implement a scripting language for game logic.

2 posts in this topic

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.
1

Share this post


Link to post
Share on other sites

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.

1

Share this post


Link to post
Share on other sites

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

2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0