Scripting

Started by
5 comments, last by Khatharr 11 years, 3 months ago

I am having an issue with scripting. Im writing a Text Based RPG Game in C++ but I have a question about scripting. What would the best method be for writing out the story without directly writing every line in my C++ program?

Advertisement

By 'scripting' do mean mean the story script / NPC chat? Or do you mean a scripting language?

You can load data from files (which is very important). Use the data loaded from files to create the content of your game.

You can use scripting languages to even load logic from files, but for a text-based RPG that's probably not needed (unless that's what you're looking for).

My only experience with scripted RPGs was TES3: Morrowind.

It was a surprisingly painful experience as everything was essentially text-based and going through a rather buggish compiler/interpreter combo.

In general the part of the story I've looked at was just a set of if(...) switches based on conditional events.

There's of course a lot of advantages from not having those conditions in the engine code.

The higher amount of abstraction made it fairly easier to build complex entity relationships and I liked the idea of having a single scripting language to do everything from story to entity scripting.

Years ago I collaborated with a friend of mine in writing a text-based single-player MUD (it was supposed to be a real MUD someday).

The story was similarly based, with conditions to be set to true to evolve the world from a state to the other. It never satisfied me, but the whole thing was a akin to a quick hack rather than something serious so it was ok.

Looking back, I'd try to model a state machine using an appropriate language for story while dialogue and entity scripting would probably use yet another system.

Previously "Krohm"

Similar to Krohm, I've written single and multi-player text MUDs (multi-user-dungeons), in both java and c++ and was heavily involved in working on our implementation of an lpmud at Plymouth University more years ago than I can remember.

I would recommend doing a google for 'lpmud', you can still download the drivers for it and get it up and running fairly painlessly on both Linux and windows.

The general idea behind it was that it was an extended version of C that added object orientation. It's main core was an interpreter which read files in this hybrid of C and 'LPC' (named after its creator Lara Pensj, sp??) and turned them into game objects with specialised and generic functionality.

If you do google it, you will no doubt find example files showing you how it looks and it will give you lots of ideas. Unless you want to use someone else's MUD engine, you may need to either write your own interpreter (gets pretty complicated but very addictive) or look at using an existing scripting engine (Lua?). I don't have any experience with Lua but I believe you might be able to put something together using that, c++ and some form of data modelling (XML?).

It's a really interesting and unfortunately somewhat-forgotten genre and one that holds many great memories for me so if you need any further help, don't hesitate to ask, it's great to hear people still wanting to investigate it.

Good luck

I have just finished embedding Google v8 JavaScript engine in my game. The API is simple and flexible and quite easy (once you get past the basic concepts, such as contexts and Local/Persistent handles). The point is that JSON is a subset of JavaScript so you can employ the same v8 engine for data description (JSON) and scripting (JavaScript).

Writing your own scripting language and interpreter in the year of 2013 is just silly. You would be surprised how complicated modern-day scripting virtual machines are. For example, v8 does not interpret anything - it compiles the script directly to machine code. Furthermore, it patches the code on-the-fly optimizing it even further. Theoretically your v8 JavaScript code can run faster than C++.

[quote name='Servant of the Lord' timestamp='1357096118' post='5016546']
You can load data from files (which is very important). Use the data loaded from files to create the content of your game.
[/quote]

I'm just going to restate this one for simplicity, given that some responses are getting into much more complex territory. I apologize if this is missing the mark, but your post sounds fairly new to game programming, given that you're dealing with a C++-based text-based game. You'd be best-served in that instance just writing your various text data to text files, and having your code read from those files to get the text you want in-console. Look for a tutorial or resource on file I/O in C++ and that should get you most of the way there.

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

The general idea behind it was that it was an extended version of C that added object orientation. It's main core was an interpreter which read files in this hybrid of C and 'LPC' (named after its creator Lara Pensj, sp??) and turned them into game objects with specialised and generic functionality.

Lars Pensjo. He's an active community member here and he's awesome. biggrin.png
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

This topic is closed to new replies.

Advertisement