   "Programming Role-Playing Games with ... " Book - Question about scripting
  Hi! I did enjoy this book very much, since the author manages to give a detailed descriptiion on how to do all the important things a game needs. My question concerned hie MadLib Script System. For my game, I''d have to expand the Iiventory system and the script system. In the book, the author defines a MIL (Master Item List) and then the types MapICS and CharICS, where every object in the game is just defined by a value, an index on the MIL. On page 623 there is a bit about "attaching scripts to objects" In my game, I wanted just to do that: Attach a script to an objekt, then let teh script do whatever will be necessary when e.g. the object is used. Let''s think about an example: A healing potion. There would be a speciela value in the sItem structure, mabae an int, whichi holds the amount of the healing potion. Every time you use it, this value has to be decreased a bit. So the first thing to do: You can''t save the value of the amount in the MIL, because if you''d have multiple healing potions, they''d all have the same amount, since you''d refer to the MIL forevery object. So far, I put some of the data I nedd in the sItem structure itself. Let''s come to the scripts. Then using a script, and it comes that someting of the world has to be manipulated, the scriptsystem does someting like "App->CharController.addRoutePoint(0,1)" or so. In fact, you determine by an index number, which object, character, map, trigger etc has to be manipulated. The first parameter of method addRoutePoint is this parameter, so in this case, the player with index 0 would be manipualted. Now -finally- the big question: How can the script system get the information, whichi object to handle, when it should alter the object which called the script? Normally, it''s hardcoded in the script file: script #1 says: play music#1, then kill monster #5 But what if you want to do a script that kills just the mosnter it was attached to? So: Do not kill monster #5, but that monster who "called" the script. For the item stuff i talked about it''s the same: Since the values (conten amount e.g.) of a health poition isn''t sotred in the MIL anymore you can''t just do a script :"decrease amount from MIL-Item #2 by #20" It merley had to look like :"decrease amount from item #this by #20" I hope my concern was understandable, it''s not easy to explain what I intended, I guess  thanks, so far! 
  You''re talking about a pretty major expansion of the MLS system.  Remember what the author says about that system, that it is designed to be a simple system to demonstrate the principles of scripting.  So I guess the short answer to your question is that based on the way the MLS is written now, you can''t do what you want to do.The way I see it, you basically have two options:1)  Modify the source code of the MLS system so that it can store a pointer to (or index of) the object calling the script and manipulate that object.  You''d also have to modify the code so that any time you call an MLS function, it would pass the index of the object that call''s it.2)  Abandon the MLS and implement a scripting system using a language like Lua or Python.  This was my choice for my game, simply because I needed a full-featured scripting system that allowed a high level of manipulation and logic.  Of course, you''re going to spend a little more time learning the new system, but in my opinion, it would be time well spent.  Lua and Python are both robust high-level languages very suitible for scripting, and will give you better performance than something like the MLS, both in terms of speed and flexibility.  A book I would highly recommend on this subject is "Game Scripting Mastery" by Alex Varanese.  This book gives a introductory look at Lua, Python, and TCL, all of which are viable scripting systems that integrate easily with C++.  Furthermore, if you''re really feeling ambitious, he shows you how to create a scripting language of your own from scratch.  Check it out here:http://www.amazon.com/exec/obidos/tg/detail/-/1931841578/qid=1076962041/sr=1-1/ref=sr_1_1/002-2198566-0151253?v=glance&s=booksOption one is probably going to be faster and less work, but option two will give you more options in the long run.  It''s a decision you''ll have to make. ;  "Game Scripting Mastery" is the next on my list! ;  Hi!It really sounded too god and I got a possibilty of getting the game script book quite cheap - so I just bought it ;-pI woner now what you can do with a complete scripting system?e.g. in-game cutscenes, conversations with NPCs, compelx object manipulation (like when you press switch A, in Room 4 the floor is lowered, a NPC spots this and summons 50 orcs *g*)ok. thanks ;  All of the above and more.  You are limited only by your imagination (and programming skills  ).  Basically, languages like Lua and Python are complete high-level programming languages, although considerably simpler than something like C++.  But they do have a full range of data types, operators and functions.  The real power, as far as scripting goes, is that they have an API that allows them to interface with C++ programs.  You can allow your scripts written in these languages access to functions, objects, or variables in your C++ program, and they can then use them in any way you see fit in your programs.  Likewise, your C++ program can retrieve variables and call functions from your scripts.  The big advantage of this system is that you can modify your scripts to change the behavior of objects, NPCs, etc., without having to recompile your C++ program.Here''s an example.  Say you are writting an RPG, and you want to script the weapons in the game.  You could write your C++ program so that each weapon would have a script attached to it that got run every time the weapon was used.  This way, you could devise weapons that could do just about anything imaginable.  Say you want a bow that has a special visual effect and exploding arrows.  You would write functions that draw an effect on the screen, one that creates a new projectile, one that retrieves a list of enemies within a distance of a certain point, and one that does damage to an enemy.  Then you would expose all these functions to the scripting system so that your scripts could call them.  The psuedocode for your script could look something like this: const EXPLOSIONRANGE 5const EXPLOSIONDAMAGE 10On Fire Weapon:   CreateProjectile(GetPlayerPosition());   DrawEffect(SpecialArrow);On Weapon Hit:   DrawEffect(Explosion);   for each enemy in GetEnemiesWithin(GetWeaponPosition(), EXPLOSIONRANGE) DoDamageToEnemy(enemy, EXPLOSIONDAMAGE);Then, say you decide that 10 is too powerful for this particular weapon.  Simply go into the script and lower the constant.  Presto!  Run your program again (without having to recompile) and the weapon will behave in the new fashion.I think you will find that book immensely helpful.  I know I did. 