Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A script engine written in QuakeC

#1
Brick 
Yesterday I thought it would be fun to make a script interpreter in QuakeC and so I did.
I'm not sure if this is an interesting concept or just a stupid idea.
Anyway, I managed to make it. It currently supports the following features:
  • basic imperative control structures
  • scoped (untyped) variables
  • functions
  • basic numeric and string operators
  • some misc math and string functions
  • reading/writing cvars
  • executing console commands
  • handling entities

The interpreter is accessible via a command which can either run a file or a single line.
I've only tested it in server code but it should work fine in menu and client too.

Sources:
https://github.com/mbasaglia/esk-modpack...and/script
https://github.com/mbasaglia/esk-modpack.../script.qc

It has a C-like syntax, I guess somewhat similar to JavaScript. Semicolons can be replaced by commas so it's easier to execute snippets from the console.
Follows a simple script which gives a basic idea of the syntax:
Code:
function pluralize(string,number)
{
    if ( number == 1 )
        return string;
    else
        return string+"s";
}

function buckets_of_oats(n)
{
    return n+" "+pluralize("bucket",n)+" of oats";
}

function verse(n)
{
    print ( buckets_of_oats(n) + " on the wall, " + buckets_of_oats(n) + "!" );
    wallstring = n == 1 ? "WAAAAALLLL!!!" : "wall";
    print ( "Take one down, pass it around, you got " + buckets_of_oats(n-1) +
        " on the "+ wallstring );
}

function sing(n = 10)
{
    while ( n > 0 )
    {
        verse(n);
        n -= 1;
    }
}

sing();

I made it just for fun, does anyone know if something of this kind can be of any use?
Reply

#2
Looks fun. Blub\0 gave this a thumbs up for the effort on #gmqcc Smile

As for usefulness, I don't know. What kind of use do you envision? In servers you may as well code in QC directly. In CSQC, I don't know what clients would use it for really, except maybe rainbow text? Tongue
[Image:http://i.imgur.com/4XODR.png]640K ought to be enough for anybody.
     ― Linux Torvalds
Reply

#3
Yeah, rainbow text script!

It's much faster and more efficient than the console alias hack (and more readable too Tongue)

Code:
function hsv(h,s,v)
{
    h *= 6;
    c = v*s;
    m = v-c;
        
    h1 = floor(h);
    f = h - h1;
        
    n = v - c * f;
    k = v - c * (1 - f);
        
    if ( h1 == 0 )
        return rgb_to_hexcolor(vector(v,k,m));
    if ( h1 == 1 )
        return rgb_to_hexcolor(vector(n,v,m));
    if ( h1 == 2 )
        return rgb_to_hexcolor(vector(m,v,k));
    if ( h1 == 3 )
        return rgb_to_hexcolor(vector(m,n,v));
    if ( h1 == 4 )
        return rgb_to_hexcolor(vector(k,m,v));
    return rgb_to_hexcolor(vector(v,m,n));
}

function rainbow(string)
{
    string = strdecolorize(string);
    recolored="";
    for ( i = 0; i < strlen(string); i++ )
        recolored += hsv(i/strlen(string),0.75,1) + substring(string,i,1);
    return recolored;
}


command=arg1+" ";

string=""
for ( i = 2; i < argc; i+=1 )
{
    string += get("arg"+i);
    if ( i+1 < argc )
        string += " ";
}
    
localcmd(command+rainbow(string));
Reply

#4
Nice, now that's a proper benchmark against existing alternatives Smile

It's a bit sad that there is no real use for this. Can this be plugged into menu QC (without entity access then) to be useable by clients on any server?
[Image:http://i.imgur.com/4XODR.png]640K ought to be enough for anybody.
     ― Linux Torvalds
Reply

#5
Yes, it required some minor changes (mostly due to different entity fields in menu) but it works fine.
Reply

#6
Cool stuff =)

And im sure theres possible uses for it, just need to find them!
Some ideas:
Scripted map events / entities (SP just got a little easier to accomplish)
BOT Scripts (we need to get Mirio under better control! ; )
Gamecode that refines itself live (its aliiiiive! :S)
Reply

#7
(10-13-2014, 07:39 AM)tZork Wrote: Cool stuff =)

And im sure theres possible uses for it, just need to find them!
Some ideas:
Scripted map events / entities (SP just got a little easier to accomplish)
BOT Scripts (we need to get Mirio under better control! ; )
Gamecode that refines itself live (its aliiiiive! :S)

What's SP?

I didn't think of mapping, that's a great idea. Perhaps it should be sealed tight to avoid crashes though Smile We already have some nice "programmability" with target_spawn and the range of triggers though, I think the difficulty of handling it makes it more charming. But I'm not a mapper Big Grin

EDIT: Ah, SP is single player.
[Image:http://i.imgur.com/4XODR.png]640K ought to be enough for anybody.
     ― Linux Torvalds
Reply

#8
I remember back the day working on some Jedi Knight Outcast maps (uses modified Quake 3 Engine) which also had a scripting tool allowing for some really crazy stuff. You could essentially do everything with it, control every entity and even create camera sequences/ cutscenes. Thumbs up for your work! I´d like to see it in action, care to make an example video? Smile
Reply

#9
(10-13-2014, 12:44 PM)Maddin Wrote: care to make an example video? Smile

OMFG were gonna see technolcolor pony porn Tongue
[MoFo] Servers - North America - Hosted in Kansas USA - Admin DeadDred [MoFo]
Reply

#10
(10-13-2014, 12:44 PM)Maddin Wrote: I´d like to see it in action, care to make an example video? Smile

Sure, but do you have an idea about what to show in it? So far all the scripts I've written for it were quick tests to make sure that all the features are working correctly.
Reply



Possibly Related Threads...
Thread Author Replies Views Last Post
  New QuakeC virtual machine Lyberta 8 2,320 07-14-2017, 04:01 PM
Last Post: poVoq
  Moving away from QuakeC Lyberta 6 1,869 04-07-2017, 03:35 AM
Last Post: Mario
  Engine: thread handling kingtiger01 0 1,648 11-06-2015, 12:57 AM
Last Post: kingtiger01
  Engine: cpu extensions kingtiger01 0 1,429 11-06-2015, 12:39 AM
Last Post: kingtiger01
  Ongoing port to the Unvanquished engine? poVoq 9 7,105 11-05-2015, 11:09 PM
Last Post: Danfun64
  [Script] Full realtime world lighting, using static light entities MirceaKitsune 4 3,540 03-23-2015, 12:33 PM
Last Post: Lee_Stricklin
  Xonotic Game Engine, Mapping, Development - General Developer Questions p14r 6 6,186 08-04-2014, 10:24 AM
Last Post: p14r
  QuakeC: if chains? WannabeUser 2 2,184 03-13-2014, 07:28 AM
Last Post: WannabeUser
  QuakeC: Variadic macros? WannabeUser 2 1,872 03-10-2014, 05:16 PM
Last Post: WannabeUser
  Learning QuakeC? phim 13 12,244 12-24-2013, 03:07 AM
Last Post: aa

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB original theme © iAndrew 2016, remixed by -z-