Including Functions within Input files.

I'm writing a data driven program for a text adventure game- basically creating an engine for a universal text adventure game. The game will take in input files and add various locations etc to vectors. I'm having problems understanding how to take in a file of verbs. I.e. "Go", "Take" etc. These will obviously call different functions- movement function, a push_back into the players' items vectors for the take. This is where the problems lies- ideally I want the input file to tell the program what to do, other than just pass in strings of the verbs- and not hardcode functions into the program as obviously different games have different actions.

So basically- is there a way to code functions into a text file and pass it into a program?

Thanks
you want to map verbs to functions?
I basically want the function created in the input files rather than having the functions in the programs code.

The input files will be something along the lines of:

Verbs.txt

Go
Examine
Take
Drop
Help


Then these verbs will be passed into an array or vector to be checked if what the user inputs is a valid verb for the game in hand.

However, because I want my program to be completely data driven and used for other games via different input files, I was wondering if the functions for the verbs (go, use etc) can be made in the input file instead of in the program itself.

Along the lines of

Verbs.txt

Go
void movementFunction(){ blah blah; }

Take
void addToPlayersItemsFunction() {blah blah; }


Is this in anyway possible?
There's a short answer and a long answer to that.

The short answer is no. You need to implement the code for your verbs in your program.

The long answer is yes, but it's a lot of work. You could take the "code" from the text file and pass it to a compiler and build a DLL. Then load the DLL. You'd still have to link your verbs to the compiled functions in the DLL. A problem with this approach is accessibility and knowledge of data structures in your program and assumptions about the calling sequences of the functions in the DLL.

Most "universal" game engines implement a scripting language that is somewhere between the two approaches.
Last edited on
Thanks, that saves a ton of time.
Topic archived. No new replies allowed.