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
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?
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.
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 Montreal Canada - 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
  [META] Xonotic reboot/port in modern engine ballerburg9005 32 14,085 02-22-2022, 05:11 PM
Last Post: ballerburg9005
  [TUTORIAL] How to create a command - DarkPlaces engine C programming LegendGuard 1 2,612 03-31-2021, 03:43 PM
Last Post: LegendGuard
  What was easy for you in development? (Darkplaces and QuakeC programming) LegendGuard 2 3,066 08-08-2020, 05:25 PM
Last Post: LegendGuard
  [TUTORIAL] How to create a command - Xonotic QuakeC programming LegendGuard 3 3,704 07-25-2020, 06:24 PM
Last Post: LegendGuard
  Moving away from QuakeC Lyberta 11 10,850 07-17-2020, 07:36 AM
Last Post: LegendGuard
  [NEED HELP] [Commission] To update Jeff's Modpack - QuakeC programmer wanted breakfast 4 5,345 07-08-2020, 12:45 PM
Last Post: breakfast
  VR script MirceaKitsune 2 2,888 10-16-2019, 05:48 PM
Last Post: MirceaKitsune
  New QuakeC virtual machine Lyberta 5 7,655 07-14-2017, 04:01 PM
Last Post: poVoq
  Engine: thread handling kingtiger01 0 3,412 11-06-2015, 12:57 AM
Last Post: kingtiger01
  Engine: cpu extensions kingtiger01 0 3,010 11-06-2015, 12:39 AM
Last Post: kingtiger01

Forum Jump:


Users browsing this thread:
1 Guest(s)

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