I suppose concating a number from a loop to a string doesn't work any more



  • While going through a mod that I and another guy had "joined" to see how to add "ores" I was instantly greeted by this function:

    function loadOres()
    {
    	%file = new FileObject();
    	%file.openForRead("./ores.txt");
    	while(!%file.isEOF()){
    		%line = %file.readLine();
    		echo(%line);
    		readOreFile(%line);
    	}
    	%file.close();
    	%file.delete();
    }
    loadOres();
    

    While this wasn't too bad, it still wasn't what I was looking for, so I decided to dig deeper, thus getting this:

    if(!isObject(OreSO))
            new ScriptObject(OreSO);
    function readOreFile(%name)
    {
            %file = new FileObject();
            %file.openForRead("./types/" @ %name @ ".txt");
            %health = %file.readLine();
            %name = %file.readLine();
            %db = %file.readLine();
            %print = %file.readLine();
            %dirt = %file.readLine();
            %level = %file.readLine();
            %file.close();
            %file.delete();
            if(%name !$= "grass")
            {
                %levelobj = "Level" @ %level;
            echo(%levelobj);
                    
    			   if (%levelobj.count $= "")
    				%levelobj.count = 0;
                   %levelobj.ore[%levelobj.count] = %name;
    			   %levelobj.count += 1;
            }
            eval("new ScriptObject(" @ %name @ "SO) { health = " @ %health @ "; name = \"" @ %name @ "\"; print = \"" @ %print @ "\"; dirt = \"" @ %dirt @ "\"; };");
            OreSO.count++;
            OreSO.ore[OreSO.count] = %name;
    }
    

    A data file for this would look like this:

    10
    Dirt
    DirtDB 
    31
    3
    

    (yes, %db was completely unused.)

    This was immediately followed by this code used to create the "level" objects:

    function scriptObjectOre()
    {
            if(!isObject(Level1)) new ScriptObject(Level1);
            %c++;
            if(!isObject(Level2))  new ScriptObject(Level2);
            %c++;
            if(!isObject(Level3)) new ScriptObject(Level3);
            %c++;
            if(!isObject(Level4)) new ScriptObject(Level4);
            %c++;
            if(!isObject(Level5)) new ScriptObject(Level5);
            %c++;
            if(!isObject(Level6)) new ScriptObject(Level6);
            %c++;
            if(!isObject(Level7)) new ScriptObject(Level7);
            %c++;
            if(!isObject(Level8)) new ScriptObject(Level8);
            %c++;
            if(!isObject(Level9)) new ScriptObject(Level9);
            %c++;
            if(!isObject(Level10)) new ScriptObject(Level10);
            %c++;
            echo("Created " @ %c @ " Script Objects.");
    }
    
    scriptObjectOre();
    


  •  What language is this? I know none that allow variable names to start with %.



  • @dhromed said:

    What language is this? I know none that allow variable names to start with %.

    Google tells me it's TorqueScript.



  • Yep.
    In TS % is the prefix for local variables and $ is the prefix for global variables. When it looks like JavaScript identifiers it's actually implicit strings. All syntax-helped string operations are case-insensitive.
    There are no arrays, $A["b"] is equivalent to $Ab. @ is string concat, $= is (case-insensitive) string match, == is for comparing numbers and (if it's a string,) the IDs of objects.



  • So....

    is %file.delete(); badly named or is it actually nuking the file after reading it?



  • TS has no GC, you have to manually delete each object to prevent memory leaks. So each object in TS has a .delete() method for nuking the object. In vanilla TS you can also create destructors by overriding .onDelete(), but this functionality was patched out in the game in question.



  • @dhromed said:

     What language is this? I know none that allow variable names to start with %.

    In Perl, hash variables start with %.

     



  • @dhromed said:

     What language is this? I know none that allow variable names to start with %.

     

    I don't know - I see a lot of c++, that must be it.



  • @dhromed said:

    What language is this? I know none that allow variable names to start with %.

    While it's true that a good programmer can pick up any language reasonably easily, it doesn't mean that you won't end up confused as a result. I love Perl's unless, but JavaScript gets confused if I try using it there, or precede scalar variables with $. (If I remember correctly, mSL was a horribly bastardised version of something like JavaScript that made everything stupidly different by changing as much as it could while leaving a passing semblance to JavaScript. However, nothing comes close to being as abhorrent as AutoHotkey. Love the program, can't abide the scripting language.)

    I wonder how severe the performance penalty would be for using AppleScript as a real-time game scripting language on a Macintosh? ;-)

    It's disingenuous of the IT industry as a whole to create so many new languages with such minuscule scopes. mSL for mIRC for example, or TorqueScript for a very specific subset of video games.

    I don't know Lua personally, but it's nice to see a standard language being used for this purpose now, at least in a few places.



  • Also don't forget that some games are starting to use Stackless Python for scripting too.



  • Obviously no-one's going to agree on a standard application scripting language :)



  • So what we really need is a flexible standardised platform á la .NET/Parrot with pluggable interpreters/compilers!



  • @Daniel Beardsmore said:

    but JavaScript gets confused if I[...] precede scalar variables with $.
    Must resist... need... to nitpick...

    @Daniel Beardsmore said:

    I don't know Lua personally, but it's nice to see a standard language being used for this purpose now, at least in a few places.
    I like Lua, but I'd be perfectly happy too if everyone would choose Python or JS as their embedded language.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.