|
|
View previous topic - View next topic |
Author |
Message |
Flawe Slightly Deformed Faerie Princess
Joined: 29 Nov 2007 Posts: 32 Location: London
|
Posted: Sun Jun 29, 2008 9:58 am Post subject: Scripting in RPGs |
[quote] |
|
Do people here use scripting languages in their games? I've never used one but I can imagine it would suit perfectly for an rpg in development. You could easily add new items, quests, monsters, statistics, etc.
If anyone has used a scripting language, how did you use it? What things did you put in the scripts and how was that integrated into the code?
I'm currently trying to create a Lua system for my roguelike. What I'm doing now is specifying all the different ground/terrain tiles in Lua and I will have a randomizer in my C++ code that generates terrain. The goal with this is to later have a working game and by simply adding or modifying the tiles in the Lua files, the engine would generate new kind of terrains without actually having its code changed at all.
For this I need to put basically all tile information in the Lua files. Currently I define a tile by its name, description and a set of properties like walkable/obstacle, indoors/outdoors, etc. The description is used to give the player a string when he "examines" his surroundings. For instance a grass tile could have the description "young spring grass" or whatever.
All the other properties would be used partly for game play, to let players walk on the tile for instance, and also for the terrain generator so that it knows what tiles it can put where. You wouldn't want an outdoor tile like grass/dirt inside a house.
|
|
Back to top |
|
|
valderman Mage
Joined: 29 Aug 2002 Posts: 334 Location: Gothenburg, Sweden
|
Posted: Sun Jun 29, 2008 9:07 pm Post subject: |
[quote] |
|
I couldn't imagine creating an RPG of any size without a scripting language; having everything that requires any kind of logic hardcoded into the executable would be the horror to end all horrors. Examples of usage would be item effects, cutscenes, dialogue (whenever you need something more than just text; updating quest state for example,) easy implementation of minigames, generating random terrain, scripting custom brushes in your map editor, etc. _________________ http://www.weeaboo.se
|
|
Back to top |
|
|
Rainer Deyke Demon Hunter
Joined: 05 Jun 2002 Posts: 672
|
Posted: Sun Jun 29, 2008 9:22 pm Post subject: |
[quote] |
|
I don't think it matters if you use a scripting language or not. Or rather, it doesn't matter if your "scripting language" is interpreted at runtime or compiled to native code. What matters is that you can define game logic at a high level.
Personally, I use a custom high-level descriptive language which contains a custom Python-like scripting language as a sub-language.
Sample: Code: |
on start:
log("Starting game...")
game.add_party_member(spawn_character('lina'))
game.party_receive($(abilities.weapons.bow))
game.enter('world', 0)
log("Game started.")
area world:
map_code 0x11:
on enter:
game.enter('world', 2)
map_code 0x12:
on enter:
game.enter('world', 1)
character lina:
name "Lina"
appearance $(anim_maps.creatures.party.lina)
|
The language is still very much a work in progress, but note how it's primarily a data definition language with some executable code mixed in.
|
|
Back to top |
|
|
Hajo Demon Hunter
Joined: 30 Sep 2003 Posts: 779 Location: Between chair and keyboard.
|
Posted: Mon Jun 30, 2008 11:29 am Post subject: |
[quote] |
|
I've been using Lua in my former project. It worked well. For my current project I'm still a bit undecided.
If you use one language, or two different ones seems to be a minor issue to me. Important seems to be to separate the game engine/core, from the games logic and data. Usually this is where scripting languages come into play, to define at least the logic part, some also are used to define the data.
|
|
Back to top |
|
|
RedSlash Mage
Joined: 12 May 2005 Posts: 331
|
Posted: Tue Jul 01, 2008 5:32 pm Post subject: |
[quote] |
|
Scripting makes it easier to separate the core engine code with the game logics. Its helps alot with development since you do not need to compile and link code every time you make a minor change to the script.
|
|
Back to top |
|
|
Nodtveidt Demon Hunter
Joined: 11 Nov 2002 Posts: 786 Location: Camuy, PR
|
Posted: Wed Jul 02, 2008 9:57 pm Post subject: |
[quote] |
|
I've used my own scripting language for years (ETX), because I find it often useless to use an implementation that has way too many features and is usually missing something I need. But recently I decided to retire it and develop a new one in its place. I don't think I'd ever use something like Lua; it would require learning a whole new language, then implementing a system written by someone else that I am not going to ever understand 100%. _________________ If you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows. - wallace
|
|
Back to top |
|
|
Mattias Gustavsson Mage
Joined: 10 Nov 2007 Posts: 457 Location: Royal Leamington Spa, UK
|
Posted: Sat Jul 05, 2008 12:45 pm Post subject: |
[quote] |
|
Yeah, in my experience, a scripting language has limited benefits if it's not custom made for the game.
Actually, I'm not much of a fan of scripting languages for games, to be honest. I much prefer a data-driven approach, where the logic and flow is written in code (C++ in my case) but specific attributes are specified in external data files (XML in my case).
I find it much more productive to debug code in Visual Studio, than to use the primitive means available to debug scripts.
That being said, I wouldn't want to develop a full RPG without a way to externally define data for my different entities, so they can be modified on the fly without restarting the game (that's key for me btw: being able to just hit a button to reload the data definitions. I've seen many examples where scripting have been used in a way where it saves you from recompiling when you change something, but it still requires you to exit the game and run it again. That's pretty useless, IMO; dynamic reload is where it's at). _________________ www.mattiasgustavsson.com - My blog
www.rivtind.com - My Fantasy world and isometric RPG engine
www.pixieuniversity.com - Software 2D Game Engine
|
|
Back to top |
|
|
Hajo Demon Hunter
Joined: 30 Sep 2003 Posts: 779 Location: Between chair and keyboard.
|
Posted: Mon Jul 07, 2008 8:50 am Post subject: |
[quote] |
|
Mattias Gustavsson wrote: |
That being said, I wouldn't want to develop a full RPG without a way to externally define data for my different entities, so they can be modified on the fly without restarting the game (that's key for me btw: being able to just hit a button to reload the data definitions. [...]). |
That's a pretty cool idea :)
Looking at my own project, I see a whole lot of obstacles that prevent dynamically loading of most data, though.
Can you give some design hints, how to set up the project core so that dynamical reloading works?
For example if you want to alter a map, but in the running game there are PC and NPCs on that map, loading it again would definitely screw up everything in my project ...
Even the catalog structures like the beings catalog cannot be reloaded, since there might be being instances already in use by the engine, instances made from old catalog data, and I'm afraid it just won't work smoothly.
Tips will be highly appreciated :)
|
|
Back to top |
|
|
Mattias Gustavsson Mage
Joined: 10 Nov 2007 Posts: 457 Location: Royal Leamington Spa, UK
|
Posted: Mon Jul 07, 2008 1:03 pm Post subject: |
[quote] |
|
Regardless of how it is done, there will be work involved, and a lot of things will have to be resolved on a case by case basis.
I find that a good method is to separate definitions from instances.
For example, I might have these XML files in a Characters folder
Farmer.xml
Fisherman.xml
SirHackalot.xml
SirSlashalot.xml
Robber.xml
InnkeeperBertrolf.xml
which would mean I have 6 different character definitions. In the game, I could have any number of Farmer, Fisherman and Robber instances, but only one each of SirHackalot, SirSlashalot and InnkepperBertrolf.
In any case, I'd have a CharacterDefinition class, and a CharacterInstance class. When the game is loaded, I'd load all files I can find in the Character folder, and for each of them I'd create a CharacterDefinition object, and load all the data from that XML file into the object. In the case of the Farmer/Fisherman/Robber files, the XML would define how values are generated (for example, the hitpoints of a farmer is D6+3, for a robber D10+5 and so on), while for the individual characters, it'd give absolute values (SirHackalot has 15 hitpoints, with no random variation).
When the game creates a character (either spawns a new fisherman/farmer/robber or instantiates a named character), the definition is passed to the constructor of the CharacterInstance class, and is stored, and used to populate the instance values (for the farmer/robber/fisherman, it will generate the "total hitpoints" value based on the formula given by the definition, and set the "current hitpoints" value to the same. In the case of the named character, it will just use the definitions value directly).
Now, when I hit the reload button, I just go through the Character directory again, and if there's already a definition created for a file, I reload all the data for that definition, if it doesn't exist, I create it and load the data.
Then I loop through all the CharacterInstance objects and call a "OnReload" method on them. Each character instance then have to examine each of their values, and compare them with what's in the definition. Here's where you have to decide how you want things to work. In the case of the named characters, it's easy: You just replace the "total hitpoints" value with the new value in the definition, and leave the "current hitpoints" value alone (unless it's higher than the new "total hitpoints value, in which case you clamp it). In the case of the farmer/robber/fisherman characters, you could check if their "total hitpoints" value is between what is possible in the definition (maybe we changed it from D6+3 to D4+2, meaning that a "total hitpoints" value of 8 would have been valid before the reload, but now it isn't). You could then either generate a new "total hitpoints" value, and change "current hitpoints" to match, or you could clamp the value to the new possible range (though that could well mean all currently instantiated fisherman suddenly have the maximum number of total hitpoints possible for a fisherman.) What you do totally depends on your game though, remember that dynamic reloads are supposed to help you when tweaking the game, and base decisions on that.
There's certainly a fair bit of work involved, and affects many parts of the game, and it won't work 100% of the time: once in a while you'll have to restart the game, but it's invaluable when tweaking stuff, and imo the very reason for using external data definitions (or scripts, if you prefer). _________________ www.mattiasgustavsson.com - My blog
www.rivtind.com - My Fantasy world and isometric RPG engine
www.pixieuniversity.com - Software 2D Game Engine
|
|
Back to top |
|
|
Hajo Demon Hunter
Joined: 30 Sep 2003 Posts: 779 Location: Between chair and keyboard.
|
Posted: Mon Jul 07, 2008 1:41 pm Post subject: |
[quote] |
|
I see. I've moved the definitions into structures that I call "catalogs" and from each catalog entry there can be instances. So the being catalog has kind of a schematic for each being, and actual beings are made from these schematics.
While I can reload the catalogs easily, my project misses an easy way to iterate through all instances made from catalog entries and update those.
Thank you for your detailed description :) It showed I'm not too far off with my design and there is hope to improve it.
|
|
Back to top |
|
|
Mattias Gustavsson Mage
Joined: 10 Nov 2007 Posts: 457 Location: Royal Leamington Spa, UK
|
Posted: Mon Jul 07, 2008 2:17 pm Post subject: |
[quote] |
|
Hajo wrote: | I see. I've moved the definitions into structures that I call "catalogs" and from each catalog entry there can be instances. So the being catalog has kind of a schematic for each being, and actual beings are made from these schematics.
|
Yeah, that's exactly like my definitions/instances.
Hajo wrote: | While I can reload the catalogs easily, my project misses an easy way to iterate through all instances made from catalog entries and update those.
|
That'd actually br fairly easy to add, I'd think... when you create a being from a catalog entry, make sure the being stores a pointer to the catalog entry used.
You'd also need a master list of all beings, but I guess you'll have that already... _________________ www.mattiasgustavsson.com - My blog
www.rivtind.com - My Fantasy world and isometric RPG engine
www.pixieuniversity.com - Software 2D Game Engine
|
|
Back to top |
|
|
|
Page 1 of 1 |
All times are GMT
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|