Feedback, please? (scripting system)
Displaying 1-10 of 10 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
torin

I've been working a scripting layer on top of VergeC for a game I'm making. I think it's pretty cool, but I want to hear your thoughts. It's hard to be objective about how useful something is when you're the only one who's used it.

I'm calling it the Verge Scripting System (VSS) as a working title, but other suggestions would be great. I'm a bit worried that "Verge Scripting System" sounds too official when VSS isn't an official part of VERGE.

The main thing that VSS adds are scripts. Scripts are kind of like functions, but they run semi-concurrently. Every frame, each script that's running gets updated. Scripts automatically keeps track of what statement they're on, so they can restart from where they left off.

Here's an example of a "jukebox" script that plays three songs in order, one after the other (I'm pretending that 'MusicPlaying' is a built-in function):


script JukeboxPlay(string song) {
PlayMusic(song);
suspend while(MusicPlaying());
}

script Jukebox() {
JukeboxPlay("song1.mod");
JukeboxPlay("song2.s3m");
JukeboxPlay("song3.mp3");
}

void autoexec() {
Jukebox();
}


Normally, whenever a script calls another script, the caller is suspended until the callee finishes. You can also 'fork' a script, so that the caller keeps running:


script ParticleManager() {
while(1) {
fork Particle(); // create a new particle
suspend; // wait for next frame
}
}


You can also 'chain' a script from another script. When you do this, the callee takes over completely from the caller. This is so you can use scripts to represent states:


script IdleGuard(int ent) {
while(1) {
// ...
if(SeePlayer(ent)) {
chain AlertGuard(ent); // stops IdleGuard()
}
} }


'on' and 'during' are also useful. 'on' blocks appear at the beginning of a script. The code in an 'on' block gets run whenever the condition is true, regardles of whether the script it appears in is suspended:


script IdleGuard(int ent) {
on(SeePlayer(ent)) {
chain AlertGuard(ent);
}

// pace back and forth. these calls suspend the
// IdleGuard() script, but the 'on' block will
// still be checked.
while(1) {
moveLeft(ent, 4);
wait(2);
moveRight(ent, 4);
wait(2);
}
}


'during' blocks are similar; they encompass a block of code. If the condition in the 'during' header becomes false, control automatically jumps to the end of the 'during' block. So the block only executes "during" the time when the condition is true. Kind of like a while loop that checks its condition constantly, instead of only at one point.

You can also have 'retrace' blocks, which allow scripts to draw things. So if you had a script that represented a particle, you'd put the code to draw the particle in the script's 'retrace' block.

Oh, and you can also access script data from outside the script, so they're kind of like structs too:


script[10] bullet(int x, int y) {
halt(); // no code for bullets
}

void SomeFunc() {
int bulletId;
bulletId = bullet(10, 10);
$bullet[bulletId].x = 5;
$bullet[bulletId].y = 7;
}


(The [10] means that 10 copies of the 'bullet' script can run at once. If this is omitted, it defaults to 16 or whatever you set the default to.)

What do you think? Comments? Suggestions? Praise? Distain? I've got some ideas for more things, but I'd like to hear what you think so far.

Thanks!
-- torin

edit: Added the bit about the '[10]'

Posted on 2004-07-20 18:50:10 (last edited on 2004-07-20 20:06:58)

Toen

This does not look much easier than just doing it in vc.

Posted on 2004-07-21 00:06:06

blues_zodiakos

I don't know, it looks to me like it could be awesome! Especially for RAD(rapid application development) type stuff with verge. The real drawback I could see is a really hefty overhead, making it NOT useful for certain things (like the particle system example, unless the particles are really simple). It also seems like it could be pretty good as a way of simplifying code and lowering the amount you would have to write. For example, in the jukebox code, if you wanted to do what that is doing in pure vc, you'd have to put code in several different areas of your program - at the very least, in both your music section, and in some sort of loop that is checked often (like hooktimer). With this type of script management system, you'd just type it once, when it is used, and forget about it - which makes your code easier to read. I think it would also make scripting complex programs easier for newbies and pros alike because it would encapsulate difficult things like DURING, etc. that are present in only a very few programming languages. It's much easier to use hammer to hit a nail then it is to use a chisel.

Again, I'm worried about the overhead of using these functions though. What kind of speed are you getting?

Posted on 2004-07-21 00:25:20 (last edited on 2004-07-21 00:26:37)

torin

There is some overhead. I used the particle system as an example, but it's definitely not designed for stuff like that. The jukebox is a more appropriate example, but it's so simple that, as Toen said, doing it in Vc wouldn't be too much harder (but I do like that all the code is in one place). I am going to try to speed things up (by, i.e., not updating every script every frame), but the precompiler has to insert a lot of checks and things, and that does slow things down.

Where I think it will be most useful is in making entities more advanced. For example, in the game I'm working on, I'm going for some "Thief"-like gameplay, where the guards and civilians do their own thing, but if they see you they chase you (or run and hide, in the case of civilians). These entities need different states, they need to remember where they last saw you, hear sounds, notice open doors, etc. I think scripts will make that kind of thing a lot easier, and you won't need too many of them running at once so the overhead shouldn't be too bad.

I think it'll also be useful for advanced scripted conversations, where entity A goes to point B while entity stamps his foot impatiently and all the other entities continue to go about their business. You can imagine something like this:


script LadyValentineBuysABook() {
say(ladyV, "I'd like \"War and Peace\" please.");
say(owner, "Certainly");
goto(owner, shelfA);
waitForAnim(owner);
say(owner, "Hmm...don't see it. Maybe Bob moved it...");
wait(5);
animate(ladyV, STAMP_FOOT);
waitForAnim(owner);
say(owner, "Oh here it is...no wait, that's not it.");
animate(owner, HUM_THOUGHTFULLY);
playSound(ANNOYING_HUM);
wait(10);
say(ladyV, "I've been STANDING here so long I could have WRITTEN IT MYSELF by now! HURRY the HELL UP!");
...
}


For this kind of high-level gameplay stuff, hopefully the overhead won't matter too much. With some optimization, it shouldn't. And it think it would be much harder to write in regular VC.

Posted on 2004-07-21 00:40:24

Zip

verge is a tool for developing tools to make games, not ACTUALLY making them.

CAN PEOPLE PLEZ STOP MEKIN GAMZ PLEZ!

Zip

Posted on 2004-07-21 00:54:10

Troupe

Hey that's cool Torin. I want to see this game you are working on :D

I'd like to see how this would be used in an actual game. Perhaps you could release a demo soon? Its an intruiging concept to say the least.

Posted on 2004-07-21 01:14:37

Omni

Zip: that's not funny :)

Posted on 2004-07-21 01:26:02

Zip

ehehe, that wasn't entirely an Omni bash, though it does seem to have come out like that. I'm at fault too. :D

ZIp

Posted on 2004-07-21 15:04:00

mcgrue

Torin, your system looks interesting and weird. I look forward to seeing a sexy example in action.

Now, is it just a pre-compiler that generates vc?

Also, the docs look good so far. Also, all you other cats with documents-in-progress should get back to work on them! Bad cats! ;D

Posted on 2004-07-21 23:47:02

torin


Thanks, Grue! I was wondering if you peeked at the in-progress documentation from time to time. ;)

There's two parts: the precompiler, which is written in Python and generates ordinary VC, and the kernel, which is a VergeC library that manages the scripts. But then, if you've looked at the docs, you may already know that.

I'm working on an example, but it might take a while to draw all the art and animations. It will be a crowded market with all the various goings-on that one would expect in such a place. It'll be part of the game I mentioned eventually.

-- torin

Posted on 2004-07-22 03:51:33


Displaying 1-10 of 10 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.