Script Reading
Does anyone know how to create a script parser for a game which enables you to make text files with data in which in turn can be read and then data allocated to the appropriate variables according to the words read in. NOT SCRIPTING LANGUAGES a SCRIPT PARSER
Not a scripting engine eh? haha. well try using flex and bison to get and parse token. and then store them in a tree. sounds like a scripting engine. but without the virtual machine, ''tis just a parser go get ''em
flex is a lexical analyzer generator. you describe tokens and it will go through a stream and get them. Bison is a parser generator. It will go through your code like so:
( 3 = if while ) <- not a legal C++ statement, but all the tokens are valid
if will look for errors like that. you want game variables.
you''d parse tokens like
GameResX = 640;
just break it into tokens. and find acceptable forms.
( 3 = if while ) <- not a legal C++ statement, but all the tokens are valid
if will look for errors like that. you want game variables.
you''d parse tokens like
GameResX = 640;
just break it into tokens. and find acceptable forms.
I still don''t thinkn that this is it. I want something that could say parse a script and if it gets a word like say "CAR" it would to something like :
Car *car = new Car;
Then if the next world was "TYPE" it would read in the name eg.
car->name = script->nextWord();
See?
Car *car = new Car;
Then if the next world was "TYPE" it would read in the name eg.
car->name = script->nextWord();
See?
if you want it to actually DO stuff (like assign values to variables and whatnot) you''ll need a whole script engine, as a script parser would just cut up the files but not do anything with it... the engine is what would take those pieces of data and put them in the right spots...
what exactly are you trying to do? i get the impression you want to load stuff into structs/classes from a data file; you don''t really need a parser and scripting engine for this, unless you are trying to be REALLY REALLY general about the types of things to load. if, for example, you are always loading only a few different types of data (cars, drivers, and tracks), you can just make up a file format for each type, and load the data in using the standard file i/o stuff...
of course, that is just my opinion based on what i guess...
--- krez (krezisback@aol.com)
what exactly are you trying to do? i get the impression you want to load stuff into structs/classes from a data file; you don''t really need a parser and scripting engine for this, unless you are trying to be REALLY REALLY general about the types of things to load. if, for example, you are always loading only a few different types of data (cars, drivers, and tracks), you can just make up a file format for each type, and load the data in using the standard file i/o stuff...
of course, that is just my opinion based on what i guess...
--- krez (krezisback@aol.com)
I want to keep it as generic as possible as I want to be able to use it to get data for almost anything in the game eg people, cars, particles, sound etc.
Simply put i want to be able to say something like this:
Script:arseScript("scriptname.txt");
and the Script class will open the file, read it, call the functions required then close the file.
Simply put i want to be able to say something like this:
Script:arseScript("scriptname.txt");
and the Script class will open the file, read it, call the functions required then close the file.
So why not use a script engine?
It sounds like you know what you need it to do.
switch string1
{
case "CAR"
// do something
break;
case "DOG"
// do something
break;
}
What is wrong with using that?
-------------------------
(Gorgeous graphics)+(beautiful sound effects)+(symphonic music)+(no gameplay) != Good game
It sounds like you know what you need it to do.
switch string1
{
case "CAR"
// do something
break;
case "DOG"
// do something
break;
}
What is wrong with using that?
-------------------------
(Gorgeous graphics)+(beautiful sound effects)+(symphonic music)+(no gameplay) != Good game
what you need to do is make an enum, and do a switch on that.
enum COMMANDS {e_POP= 1, e_PUSH }char command = *_ip++;switch (command){case e_POP:case e_PUSH:case e_MY_SUPER_DUPER_SCRIPTED_FUNCTION:}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement