IrrScript: Request for Suggestions

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
AutoDMC
Posts: 104
Joined: Sat Sep 18, 2004 3:44 pm

IrrScript: Request for Suggestions

Post by AutoDMC »

Ok, guys.

I'm working on a few projects, trying to figger out what order I want to do them (which ones will be useful to the other ones, that kind of thing). It's also helped that my computer is not working right... it means I have plenty of time to (GASP!) plan before I code. It's done wonders for my error/warning count!

Anyway, one of the projects I've been working on is IrrScript. It's a BASIC-like scripting language for Games which use Irrlicht. (I thought of calling it Yet Another BASIC Based Scripting Language Using Irrlicht, but calling the project YABBSLUI (Yab-slooey?) just didn't appeal! )

I want some comments on syntax and implementation. I know there are a few BASIC coders here, some Visual Basic coders, and a few people who have asked if there was a BASIC version of Irrlicht. I also know there are a few ports of Irrlicht to BASICs of many varieties. So there should be at least a FEW comments... I hope.

Anyway, forgive me if this is a little wierd... it's 11:00PM and I've been up way too long to be typing... but I'll forget if I don't :D

1) [IMPLEMENTATION] Virtual Machine or Interpreter?

I thought of making a "Irrlicht Virtual Machine" which I named "Luigi." "Luigi" code would have instructions for general programming (ADD, MUL, DIV, SHIFTR, etc), Irrlicht Stuff (ADDMESH, TRANSLATE, DELETENODE, etc), Sound (PLAYSOUND, PLAYDITTY, PAUSESOUND, UNLOADSOUND, etc), etc.

I would then write a IrrSkript->Luigi Compiler.

I would also write a runtime IrrSkript->Luigi Interpreter.

I could then write a VM using a "switch," or if I wanted to be really snazzy, a STL LIST of LuigiCommand objects which then have decendants? with overloaded Virtual DoInstruction commands.


It would be easier, I think, to simply write a IrrSkript interpreter which directly runs the IrrSkript commands. However, I've been told that this would be slower than the IrrSkript->Compiler->Luigi route because I would just call DoInstruction on everything in the command list (IS->Comp->Luigi), instead of having to parse the file otherwise (IS only).

Questions? Comments? Suggestions?

(I'd like to have "multitasking" with the scripts. Would this be easier by having all the "interpreters" simply pass operations after each line to a different script, or would it be more efficient by having each interpreter/source file put out a pool of command which the "Luigi" processor would perform multitasking? If that doesn't make sense, ask :D)


2) [SYNTAX] To BASIC or not to BASIC?

I wanted to make the IrrScript syntax BASIC like, because "non-programmers" seem to like it better. But would that be combersome (sp?) for Current Irrlicht Programmers would would like to add the scripting ability to their applications?

I'm too tired to come up with a real example, so I'll just sketch out the syntax:

Each line looks something like this:

COMMAND PARAMETER_1, PARAMETER_2, PARAMETER_3....

If COMMAND is a built-in command, the parameters are pushed on a stack, and passed to the command handler.

If COMMAND is NOT a built-in command, it looks to see if "COMMAND" is SUBROUTINE. If so, PARAMETERS are pushed on a stack, and passed to the subroutine.

If COMMAND is NOT a built-in command or a subroutine, IrrSkript assumes it's a VARIABLE. It then checks to see if the next token is a "=". If so, it checks to see if COMMAND is in the symbol table. If not, it makes it a new variable, otherwise, it assigns the solution of the expression to the variable.

VARIABLES can either be (1) any "non-reserved" word, without a postfix symbol, which becomes an "anytype" variable (ala BASIC), or (2) any word with a postfix symbol.

Type 1 variables are more flexible, but it's type changes throughout operation, which means all that "what the heck type this is" stuff for the interpreter.

Type 2 variable can have these postfix symbols:

variable$ ($) = String
variable# (#) = u8
variable% (%) = u16
variable! (!) = u32
variable^ (^) = resourceHandle (meshes, sounds, bitmaps, etc).

Type 2 variables allow you to speed up interpretation (no type checking), and know what type is in there, and catch logic errors (attempting to put a number in a string, for example).


Did all that make sense? Do you think it'll work? Is it BASIC enough to be BASIC, or am I making it too complex? Should I use a C syntax, or maybe Pascal, ProLog, LISP?

Anyway, that's where I'm going. However IrrSkript works, it'll allow you to operate Irrlich stuff from a scripting language, while allowing the C++ code to modify said stuff.

I'm tired, but some of my best ideas have come from too much Mountain Dew at 2 AM, so I'm not sure.

Questions? Comments? Please???[/code]
Guest

Post by Guest »

at the risk misunderstanding what you plan on doing. I looked into this scripting library when I was at the planning stages of my pet project. It might help you or it might not?


http://www.angelcode.com/angelscript/
AutoDMC
Posts: 104
Joined: Sat Sep 18, 2004 3:44 pm

Post by AutoDMC »

Similar to AngelCode, yes, but not quite.

I really wanted to use the BASIC syntax, specifically because C/C++ based scripting languages seem to look scary to non programmers. My ultimate goal is to make something like this:

LOADCARTRIDGE supermarioworld
ADDLEVELMESH supermarioworld^
PLAYSOUND supermariotheme^
ADDCHARACTER mario*, mariomesh^, STANDARD_COLLIDER

And ideally this would make something similar to a first person shooter (sans shooting, of course). But the idea is that 4 lines of script would replace 15-20 lines of C++!

But I did want some comments/suggestions... any would be helpful.
Shlangton

Post by Shlangton »

For a BASIC like syntax, you should check out FreeBasic which is located at:

http://www.freebasic.net/

Or how about a wrapper for a pascal like language as well?

http://www.freepascal.org/

But my problem I can find with Irrlicht having BASIC like syntaxs, game developer gurus want to expect beginners to program games in C++. I also heard someone say that Irrlicht + BASIC = putting commercial efforts(Like darkbasic, blizbasic, etc) out of business.
AutoDMC
Posts: 104
Joined: Sat Sep 18, 2004 3:44 pm

Post by AutoDMC »

I've looked at most BASIC solutions, but most of them are either bulky or hard to customize. Also, most of them would access Irrlicht with a DLL, which means that you still have to do all the initialization and stuff by hand, just in another language.

What I want is an actual scripting language for easy development of games.

I seriously don't think IrrScript would be a real contender for "commercial" game systems... mainly because the commercial systems are mature (or mostly so), and have large user bases. And, anyway, the backbone of the US economy is COMPETITION (or LEGISLATION, depending on how many lawyers youy have).
MikeR
Posts: 767
Joined: Sun Dec 26, 2004 4:03 pm
Location: Northern California USA
Contact:

Post by MikeR »

I don't know any scripting languages, but can tell you from a "non programmers" point of view, that it would have to be simple. To the point, and easy to figure out.
I really don't know how you could write a language that would make things simple enough.
If it exists in the real world, it can be created in 3d

Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

AutoDMC

take a look to this basic language

http://groups.yahoo.com/group/bcx/

i am using it with Irrlicht in easy and simple way.

it is so powerfull,it allow you to write you basic program then
it translate it to C/C++ code which could be compiled by many
C++ compiler.

here is the simple Hello World tutorial written in BCX language

Code: Select all

$Cpp
$Library "Irrlicht.lib"

$Header
#include "irrlicht.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
$Header

Global irrDevice as IrrlichtDevice ptr
irrDevice = createDevice(EDT_DIRECTX9, _
                 dimension2d<s32>(640,480),32,false,false,false,0)

irrDevice->setWindowCaption(L"Hello World! - Irrlicht Engine Demo")

Global irrVideo as IVideoDriver ptr
irrVideo = irrDevice->getVideoDriver()

Global irrSceneMgr as ISceneManager ptr
irrSceneMgr = irrDevice->getSceneManager()

Global irrGUIEnv as IGUIEnvironment ptr
irrGUIEnv = irrDevice->getGUIEnvironment()

irrGUIEnv->addStaticText(L"Hello World! This is the Irrlicht software engine!" _
              , rect<int>(10,10,200,30), true, true, 0, -1)

dim mesh as IAnimatedMesh ptr                       
mesh = irrSceneMgr->getMesh("media/sydney.md2")                         
Global node as IAnimatedMeshSceneNode ptr
node = irrSceneMgr->addAnimatedMeshSceneNode( mesh )

node->setMaterialFlag(EMF_LIGHTING, false)
node->setFrameLoop(0, 310)
node->setMaterialTexture( 0, irrVideo->getTexture("media/sydney.bmp"))

irrSceneMgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0))

While  irrDevice->run()
       irrVideo->beginScene(true, true, SColor(0,200,200,200))
                  irrSceneMgr->drawAll()
                  irrGUIEnv->drawAll()  
       irrVideo->endScene() 
Wend     
irrDevice->drop()                     

i have converted alomst all demos.
Other
Posts: 85
Joined: Fri Dec 03, 2004 5:41 pm
Contact:

Re: IrrScript: Request for Suggestions

Post by Other »

1. If u want to make it easy for non-programmers
- you must make it graphical.

OK, u think - you can make all 3D-things (like loading 3D-mesh)
graphical, but everything other things (like behavior) must
be scripted? But if you have Physic-Engine + motors and
sensors - there is no need to script anything:
Example:
- just graphically add of a terrain, car and wheels;
- graphically attach the joints to wheels and to car;
- graphically attach the motors to wheels
- graphically attach the keys to motors
... and you have a car, controlling by specified keys...

- graphically add the sensor on start and control points
... and u know how many laps u are through

I know somebody - he wants to write a graphical editor for
my Irrlicht-ODE-based engine - MyWorld.
Perhaps it would be helpfull to cooperate?
Think about it... there is really no need for scripts..

In the Reallity there are no scripts - there are just
objects, having a behavior. Later I plan to implement AI,
Sound, Video to MyWorld and it would be complete.

2. Or u could do it in XML at first. You can really
easielly convert XML to C++ or Java, just writing
a simple XSLT, and then compile it

- its much faster, then interpreting
My Irrlicht&ODE-Project: http://www.lofing.de/myworld/
AutoDMC
Posts: 104
Joined: Sat Sep 18, 2004 3:44 pm

Post by AutoDMC »

Emil_halim wrote:AutoDMC

take a look to this basic language

http://groups.yahoo.com/group/bcx/

i am using it with Irrlicht in easy and simple way.
It looks neat... but it looks EXACTLY LIKE IRRLICHT C++. Everything looks like a sligthly modified C++ syntax, which is expressly what I'm wishing to avoid. I'm not just trying to find a way to script Irrlicht (there's litterally 500 ways to do THAT, I know, I've looked at most of them), I want a way to make a easy to expand basic language that you can modify to your application, based on BASIC.

IrrScript will contain, for example, a way to have variables, control commands (if, when, for, etc.), BASIC input and output (print, input, errorout), but NOTHING ELSE. You register commands to the language (registerCommand("ADDNODE"); ) which are then passed to your game's engine when they are encountered.

That's phase 1.

Phase 2 is to build a game engine (IrrConsole) which uses IrrScript along with IrrPak, a graphical resource program, to build real games.

(P.S., I hope I don't sound like I'm shooting down advice... I actually appreciate all this advice... I've been doing most of this single handed for about 6 months now, and am actually able to "announce" what I'm doing now because I have a basic idea. It doesn't help also that I'm always checking this board either late late at night or early early in the morning, when I havn't drunk my tact out of my Dr Pepper yet :D. I appreciate all the comments!)
Other
Posts: 85
Joined: Fri Dec 03, 2004 5:41 pm
Contact:

Post by Other »

AutoDMC wrote: It looks neat... but it looks EXACTLY LIKE IRRLICHT C++.
You are right ;-)

1. I suggest u to decide before begin wich syntaxis u use:

either with "(", ")" or without - because it was allways a problem
for me (by programming some basics) to remember if I need one or know.

(sorry for my eng. ;-))

2. To simplify the interface you could also write a wrapper...
My Irrlicht&ODE-Project: http://www.lofing.de/myworld/
insolence
Posts: 21
Joined: Mon Aug 30, 2004 1:15 am

Post by insolence »

PLEASE make the syntax Javascript like!

You also may want to check out ANTLR/etc. to make the grammar/such.
Other
Posts: 85
Joined: Fri Dec 03, 2004 5:41 pm
Contact:

Post by Other »

insolence wrote:PLEASE make the syntax Javascript like!

You also may want to check out ANTLR/etc. to make the grammar/such.
I find Javascript better too. However.. even if u still whant to use BASIC I suggest u not to discover a new syntaxis but use existing one - so u have more users and have not to write a docu "how to program basic" ;-)

I suggest u to begin with ur VM and yet not to think about the language. Write a good VM and somebody will write a good language - if not u do it then.

Best regards, Other ;-)
My Irrlicht&ODE-Project: http://www.lofing.de/myworld/
AutoDMC
Posts: 104
Joined: Sat Sep 18, 2004 3:44 pm

Post by AutoDMC »

The actual scripting part that has the BASIC syntax doesn't need any fancy-pants parsers (the reason I picked BASIC, actually.)

It takes the first word off the string.

If it's an internal command, it shoves all the other words of the string on a parameter stack, and hands it over to the handling function.

If it's a external command (one you register), it shoves all the other words of the string on a parameter stack, and hands it to the registered function.

If it's a variable, it checks to see if the token after it is "=". If so, it shoves the rest of the string into the smarty-pants expression evaluator I got online, then assigns the resulting value to the variable.

If it's a variable, and it's not followed by "=", it checks to see if it's followed by ".". If so, it detects that you are using "class" style format. It checks to see if the word after "." is a function. If it is, it pushes the word before the "." as the first parameter onto the parameter stack, followed by all the other words. It then calls the correct handler.


So, the parser understands that:

PRINT "I am a coding fool!"

is of the first type...

ADDMESH "Sydney"

is of the second type...

x = m * x + b

is of the third type, and...

Sydney.ROTATEMESH 50, X

is of the last type.


I hope that made sense. Maybe I might add support for Javascript in the future... I don't know :D
Other
Posts: 85
Joined: Fri Dec 03, 2004 5:41 pm
Contact:

Post by Other »

Whats about

Sydney.ROTATEMESH a+b/c, x = m * x + b

or

ADDMESH "Sydney" + IntToStr(abs(w-d))

?

I suggest u to go a common way, writing
a lexer and a parser, using common methods for it
- don't do a job ones more discovering a wheel.

... and just before u start u need a grammatic for example
in (E)BNF or a graph, then u can post it here and
we discuss about it...

good luck ;-)

PS: I don't understand what u mislike on freebasic -
u could at last change it, since its an open src.
My Irrlicht&ODE-Project: http://www.lofing.de/myworld/
Guest

Post by Guest »

Allright, I'm going to be the devil's advocate here but you might find these comments useful anyway.

Did you ever write a scripting engine before ? It's really not a trivial task :?
You'll have to design your grammar very carefully and then write a lexical analyser, a syntax analyser and then a code generator. It's quite a BIG endeavor. After a lot of studying about finite state automatas and BNF grammars and a BUNCH of other stuff you'll be able to do it but still, it might take much longer than you think.

If you are interested in compiling techniques then write a scripting engine for fun, it's quite an exhilarating experience (done it myself for schoolwork).

If your goal is to have a scripting engine and move on with your game then checkout these :

http://www.lua.org
http://www.python.org

They are powerful and fully embeddable languages, LUA is used in tons of top quality industrial games so you might want to give it a try.

Sorry to burst your bubble :D
Post Reply