Jump to content
  • Advertisement
Sign in to follow this  
Machlana

Command Based Scripting Language

This topic is 5016 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anybody know of any tutorials for COMMAND BASED SCRIPTING LANGUAGES.... I know Game Scripting Mastery has one in it however i lost the cd for it and well.... The book just shows the scope of the source code not the full source :S..... so if anybody knows of any simple implementations or tutorials i'd very VERY much appreciate it.... After i implement this im going to do a command based language with a compiler then a full scripting language that has a c syntax. But i want to start simple then work my way up, doing it the right way. Btw... Im a C/C++ programmer so i'd appreciate it if there was no VB tutorials and all. and i know about tghe scripting tutorial on this site and flipcode EDIT: I wanna do this for experience, NOT to use instead of a existing one

Share this post


Link to post
Share on other sites
Advertisement
You can probably contact the publisher for a replacement of the cd for a small charge. I'd try it at least.

Also, the language that the scripting language is implemented in shouldn't matter if you're only trying to get a feel as to how it's done. If anything it's better because you can't directly copy anything and must exercise your mind a little in converting the various aspects.

Share this post


Link to post
Share on other sites
Ill do that however i dont know if your familiar with a command based language its a language that really doesnt have a lexer or anything it just opens up a file and parses it and comares it to hardcoded commands example:


print "hello"
print_line
get_key



like that

that way it just compares it to something like this


if(currline == CMD_PRINT)
{
char param = get_params(currline);
print("%s", param);
}


however im not familiar with file io and parsing and such so thats where it gets me

[Edited by - Machlana on December 31, 2004 2:53:25 PM]

Share this post


Link to post
Share on other sites
Is the example that you've given me as complex as your engine gets? If so, it's relatively straightforward.

Read a line in from file.
Parse instruction (assuming that instuction is always first, which seems to be the case).

Here, parsing is a simple as reading until you encounter whitespace or the end of the string. Then simply compare this segment of the string to expected commands. Handle it if it passes, otherwise throw an exception (or whatever you want to handle errors).

If the command has arguments, and you haven't reached the end of the string, parse the next "word", or, in the event of a quotation, read until you encounter end of string (error) or the next quotation and you have the string substring.

I'm not sure, specifically, what else you'd need pointed out. If you can't think it through, then give me a solid example of what you want to do and perhaps I or another can get you moving.

Share this post


Link to post
Share on other sites
Right, lemme explain a little more

a function like
LoadScript()
That will load the script

a function like
RunScript()
That runs the script (like my above example)

a function like
GetCommand()
That gets the next command

a function like
GetParam()
That gets the paramater after the command

I know what i need but my problem is i have NEVER programmed file I/O in my life so im completley confused in it

Share this post


Link to post
Share on other sites
Then do a quick google or msdn search for it. All you need is something to read a line of text.

Here's a good one.

So, learn how to read a line of text into a string. After that it's largely common sense and thinking it out. Grab a line. Break off the first chunk (probably "someFunc("), see if there are parameters to apply, process it.

Share this post


Link to post
Share on other sites
So would i do something like this?


for( int CurrLineIndex = 0;
CurrLineIndex < ScriptSize;
++CurrLineIndex )
{
// Allocate space for the line and a null terminator
strScript[ CurrLineIndex ] = ( char * ) malloc ( MAX_SOURCE_LINE_SIZE + 1 );

// Load the line
fgets( strScript[ CurrLineIndex ], MAX_SOURCE_LINE_SIZE, ScriptFile );
}



Im still so confused what to do after that is there any examples?

Share this post


Link to post
Share on other sites
Try it out. Does it read in lines?

To test it, have it echo the lines out. Or run it through a debugger.

Anyway, next, read characters until you run into a space, end of string or a '('. You then have the first function.

Check the next character, if it's not whitespace or a ')', then you have a parameter. Read it until you encounter a space, a comma, end of string or ')'.

Is it starting to come into focus?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!