Advertisement

Question on scripting engines...

Started by July 14, 2001 04:42 PM
15 comments, last by flareman 23 years, 7 months ago
I''m on the process of designing an iso RPG of my own, and I have decided to make it using a scripting languange of my own. I have a not-so-favorable predisposition against ready scripting languanges (not that it''s something personal, but... well, call this a bad feeling. I wanted to create an engine designed to support specifically the game I''m working on (that means tha I''m not in for reusability - maybe later...). In any case, I have already laid most of the system down, like the parser and all that stuff, but I have a major problem: The game will use scripts written in a simple VB-like manner (I think;pascal or C/C++-like code are probabilities), and will most often have to call THROUGH a scripted action procedures and functions hardcoded in the engine, or even OTHER actions, included in other script files. I know that there is a command in VB6, CallByName that does this job, but, sadly enough, my VB skills suck (plus I can''t afford ver.6), and I don''t know what to do. So, I summarize my question: How can I call a procedure that is written and compiled in the game''s exe via a script action (I already know how to get the procedure''s name and params form the text file that contains the script, it''s just that I can''t write: ... ... ReceiveNextCommand(command, parameters, script); // the proc returns command=''PresentMessage'' command(parameters); ... ... ... procedure PresentMessage(x,y:int;text:string;speed:byte); begin ... ... end; ...or can I? Any help will be gladly appreciated Spyros -----------<<>>----------- Ga1adaN, Primus ante Adein flareman@freemail.gr -----------<<>>------------
-----------<<>>-----------Flareman (a.k.a Ga1adaN)Primus ante Adain[email=flareman@freemail.gr]flareman@freemail.gr[/email]-----------<<>>------------
Well, I''m not the best at this, but there are two ways I know of to do this.
The first:
A big switch statement.

The second:
How I am tackling this problem in my engine, is that all my functions have the same number of inputs, and I preproccess the scripts before I put them in the game, and all the function names are turned into a number. When the game init''s it creates an array of function pointers, the numbers that were assigned to functions in the preproccessing phase correspond to the index in the array in which the pointer to the function resides.
That''ll only work if scripts are preproccessed, and if all the functions that can be called are designed to have the same number of inputs (you can always have the last couple extra parameters in one not matter.) and the same type of inputs.
If you understand my ramblings, and it fits your engine, then try that, otherwise, All I know of is the first (a really really big switch statement... *shudder*)



Drakonite

[Insert Witty Signature Here]
Shoot Pixels Not People
Advertisement
That's really a cool idea! And, I got ia all, save for one detail: how can I preprocess my script files? I mean, what must I do to preprocess them, and what to use them? (man, can I piss people off!)

Thanks again D!

Flare

-----------<<>>-----------
Ga1adaN, Primus ante Adein
flareman@freemail.gr
-----------<<>>------------

Edited by - flareman on July 14, 2001 6:06:40 PM
-----------<<>>-----------Flareman (a.k.a Ga1adaN)Primus ante Adain[email=flareman@freemail.gr]flareman@freemail.gr[/email]-----------<<>>------------
Preprocess ''em? Easy.

Read in a line.
Check if it''s a ''commented'' line or not.
Get rid of spaces, tabs, etc...
Look at the first word (everything up to the first space). Use a switch (*shudder* If/Else, or in VB Select/Case) to turn the word into a number.
Write the number, and all the arguments after it, into a new file.
Repeat.

Drakonite, I doubt that you need to have the same # of arguments for every procedure. Just put in an error handler (either in the compiler, or in the executor) to make sure that the script''s # of arguments matches the # of arguments for the procedure.


RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
Ok, I think I got it...(a little bit more would be nice

Any other ideas?

Flare

-----------<<>>-----------
Ga1adaN, Primus ante Adein
flareman@freemail.gr
-----------<<>>------------
-----------<<>>-----------Flareman (a.k.a Ga1adaN)Primus ante Adain[email=flareman@freemail.gr]flareman@freemail.gr[/email]-----------<<>>------------
Well, let me explain how my preproccessing works:
As soon as the scripts are made they are ran through a "compiler" to turn them into the form my program wants. Specifically, mine goes through, and replaces every function with a number to the index array, and replaces all mentions of variables to what they should be, and any other changes, and then saves it as basically just a bunch of numbers that my scripting engine loads in as just a set of instructions. Everything is preparsed and ready, the engine just goes through and runs it. They way mine is setup is very similar to assembly. (as far as I know atleast. I only a know a little assembly...)
Actually, I don''t actually have text parser anywhere. I wrote a script editor that gives the list of functions and commands, and you simply add them to the list, and choose the inputs for them, and when everything is done, you just save it and it saves it in the final form the engine wants.
The big problem with mine, is that there is a set number of inputs a function can have, and everything that needs more than that number has to store the values in variables that the commands and functions will read.

LOL, can you tell I''m proud of my scripting engine It isn''t the fanciest, or easiest to setup, out there, but I designed it for execution, and it does it''s job good.



Drakonite

[Insert Witty Signature Here]
Shoot Pixels Not People
Advertisement
quote:
Original post by Wyrframe
Drakonite, I doubt that you need to have the same # of arguments for every procedure. Just put in an error handler (either in the compiler, or in the executor) to make sure that the script''s # of arguments matches the # of arguments for the procedure.


I''m using an array of pointers to functions that is called generically, so yes, they all have to have the same # of arguments in mine, although it could be done differently.

My way probably isnt'' the best, but I can code it, and it works great for my game.



Drakonite

[Insert Witty Signature Here]
Shoot Pixels Not People

Drakonite:

Just a thought, but instead of that, couldn''t you just make each function take a VOID* to its data? You could pass the address of the next value.

That way each function takes just one parameter, and the function could use as much or as little as it needed. The only problem with that is you''d somehow have to know how far away your next instruction is. Hmmmmm ... perhaps the function could return a skip value ... oh well, maybe it is more work than it is worth after all.










A way around that problem is to store not just the function pointers in your array, but also the number of parameters it takes.

struct Op
{
function_pointer;
number_of_params;
};

Op oparray[100]; // however many ops you have

Then you''d pass the address of the data to the function pointed to by the function_pointer, and skip the appropriate number of steps.

If you want multiple parameters in your function (I''m assuming c++?) then just create a parameters structure...

class CFuncParams{CFuncParams(){};CFuncParams( void** lpParams, word& wCount );virtual ~CFuncParams(){};void** lpParameters; //Pointer to an array of parametersword wParamCount;    //The number of parameters you''ll have}; 


Now that you have a way to pass an infinite amount of parameters just use an array of functions pointers to store you scripting commands.

void (*pFunc)( CFuncParams& ); 


-----------------------------------------------------------
"People who usualy use the word pedantic usualy are pedantic!"-me
-----------------------------------------------------------"People who usualy use the word pedantic usualy are pedantic!"-me

This topic is closed to new replies.

Advertisement