First off, here is an example of a script:
Quote:
PrintString Hello World!
PrintNum 2
PrintString I can print strings!
PrintString From StompyScript!
PrintNum 9999
Here is the source code for the program that executes the scripts:
// StompyScript Runner// Runs scripts written in StompyScript// By Joseph Cortes#include #include #include #include #include using namespace std;// Struct for holding a parameterstruct Param{ int num; string s;};// Struct holding one command (one line of code)struct Command{ int com_code; Param param;};// Every line in the codevector lines;bool LoadScriptFile(string filename);void RunScript();int main(){ string filename; // Ask what script to run cout << "What script to execute?" << endl; cin >> filename; if(!LoadScriptFile(filename)) { cout << "Couldn't load script!" << endl; return 0; } RunScript(); return 0;}// Loads a StompyScript file// This function takes in the StompyScript// file and breaks the commands into number codes// PrintString = 0 and PrintNum = 1bool LoadScriptFile(string filename){ ifstream script_file; script_file.open(filename.c_str()); if(!script_file) return false; while(!script_file.eof()) { Command com; string temp; script_file >> temp; // Determine what command is it and act accordingly if(temp == "PrintString") { com.com_code = 0; // Skip a character script_file.get(); // Check what string to print. // end the string if newline is found for(int i = 0; i < 100; i++) { char c = script_file.get(); if(c == '\n') break; else com.param.s += c; } lines.push_back(com); } else if(temp == "PrintNum") { com.com_code = 1; script_file >> com.param.num; lines.push_back(com); } } script_file.close(); return true;}void RunScript(){ for(int i = 0; i < lines.size(); i++) { // Read command and do something switch(lines.com_code) { case 0: cout << lines.param.s << endl; break; case 1: cout << lines.param.num << endl; break; } }}
And here is the result:
Adding some more commands will be easy, but It's going to be kindof hard when variables get involved.
Good luck!