Game Logic: Creating a Scripting Language

Started by
18 comments, last by punkcoders 10 years, 6 months ago

I'm creating my own scripting language for my 3D Game Engine, at first I'm doing lexical scan, then parsing the tokens.

What is your suggestions for creating a powerful scripting language for 3D Game Engines?

For methods, should I create bunches of methods linked to a callback?

I thought I could do something similar to the following:

parser.declareFunction("FunctionName", callback);

So when I execute parser.parse("bool b = true; if (b) { FunctionName(); }"); the callback should be called

Advertisement
 

I'm creating my own scripting language for my 3D Game Engine, at first I'm doing lexical scan, then parsing the tokens.
 
What is your suggestions for creating a powerful scripting language for 3D Game Engines?

Why do you feel the need to invent a new programming language instead of using an existing one? Being busy "parsing the tokens", a long distance from useful scripting, should be a hint that designing and implementing a new language is probably too much effort (or that an acceptable effort can give you only a mediocre and immature language).

Omae Wa Mou Shindeiru

What Lorenzo said. I would only recommend designing a new scripting language if it was truly a desire to learn the intricacies of designing a language. If you're hoping to use it for anything like production, even of a hobby product, you're going to be spending way too many resources getting it to work rather than actually coding your game. The other thing is, the widely available scripting languages will be way more robust and much faster than what you'd be able to accomplish without a large, really large effort.

I won’t get into syntax because there is just so much to discuss and in the end it will be up to you to figure out what you need and don’t need.

I won’t go into using existing languages because too many others already will.

Instead, if you need to make one from scratch, you should (virtually “must”) look into Flex/Bison in order to create a fast, stable, and maintainable set of tokens and grammar rules.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

I wouldn't say specifically Flex/Bison. There are any number of lexer and parser generators that can be used. Many of the new-ish tools, especially those using recursive descent, combine lexer and parser generation.
I'm going to jump on the "don't create your own language" wagon.


Yes, I realize that it's a bit ironic for me to say that, but here's my reasoning: creating a language that is rich enough to save you time is a ton of work. You also give up good debugging tools, good profiling tools, and good compiler diagnostics. In general you lose more than you gain when you roll your own. You will probably spend more time and effort maintaining your language than actually getting things done, which is kind of contrary to the purpose of using a scripting language in the first place.

Note that this primarily applies to general-purpose languages. If you want to create a highly tailored DSL for some specific task, that's one thing; but a general scripting language is almost certainly biting off more than you want to chew.

I also advocate not using a "real" syntax for DSLs, but rather something you can trivially parse with string splitting library functions, or maybe a JSON library or something similar.


TL;DR: don't do that :-P

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Oops...

I have done a lot already including declaring variables, calling methods, arguments, assigning variables, declaring methods...

I think I have done many of what I want already, I don't think I will need a large scripting language for scripting inside the game mission design, the scripting will ONLY be used in the game design, so I think the most important is using "if" statements, declaring variables, calling methods

But, my question is: What should I focus on my own scripting language to create something powerful for mission scripting? What are the general uses of scripting in FPS games?

Example of what I think of scripting:

If the player collided with a trigger box (invisible) then I know that the player reached some point in the game so I can do something like: onTriggerEnter event script: object1.completed();

For game win check scripting I could do something like:

if (objects.allCompleted)

mission_completed();

I wouldn't say specifically Flex/Bison. There are any number of lexer and parser generators that can be used. Many of the new-ish tools, especially those using recursive descent, combine lexer and parser generation.

agreed, though personally I have typically used hand-written recursive descent.

usually IME, the logic that comes after parsing is a lot more work than the parser itself.

my experience here (implementing/using a custom script language):

a lot of work over a lot of years, and all these years later, what I have is, at-best, mediocre...

though, granted, it does basically what I want out of it, so is "mostly good enough".

it does light duty scripting stuff basically ok, but isn't really solid enough to seriously consider as an implementation language.

one sad thing in life is that pretty much anything a person can do, someone else has likely already done better, so it is a choice whether to reuse what others' have done (and try to figure out ultimately what they can do for themselves, *1), or sit around and basically play catch-up.

what merit there is then is mostly in terms of customization or control, or aiming for unconventional use-cases (competing on unconventional metrics, ...).

*1: while pretty much everything has already been done, unless a person does something, they effectively still have nothing.

like, if a person goes and downloads some FOSS game off the internet, everything has already been written, assets created, ... but the person has, themselves, not created anything (and has no natural ownership or control over any of it).

@ApochPiQ: I don't really need to have any debugging tools or compiler, the game is FPS and I'm planning to parse the scripts directly during the game play.

So, what I have is only syntax checking.

It's obviously up to you, but I'd recommend against that, actually. You're in for a lot more pain than you think, unless your scripts are so bone-trivial that they may as well just be code in the first place.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

This topic is closed to new replies.

Advertisement