Blockland Forums > Modification Help

[CHALLENGE] Rosetta Code - "Tasks not implemented in torquescript"

Pages: << < (6/12) > >>

Destiny/Zack0Wack0:


--- Quote from: Lugnut1206 on June 18, 2012, 03:04:30 AM ---because they aren't possible?
because they are too stupid?

what do you mean

--- End quote ---

--- Quote ---Not Considered

These tasks are not generally counted toward "unimplemented", as somebody, somewhere, decided that TorqueScript was inappropriate for these tasks, or implementations of them would be unenlightening. Feel free to try your hand at them anyway.

--- End quote ---
"OpenGL"
"Random number generator (device)"
etc.

MD5 and a lot of other things on the page can't be natively implemented because Torque's number system is too stuff for them (you can however use hacks to have bigger numbers with strings, but you won't be able to have a clean snippet to post), so they should also be not considered.

Port:

Two implementations of "Fibonacci sequence":


--- Code: ---function fibIter( %n )
{
    if ( %n < 2 )
    {
        return %n;
    }
   
    %fibPrev = 1;
    %fib = 1;
   
    for ( %num = 2 ; %num < %n ; %num++ )
    {
        %_fibPrev = %fibPrev;
        %fibPrev = %fib;
        %fib = %fib + %_fibPrev;
    }
   
    return %fib;
}

function fibRec( %n )
{
    if ( %n < 2 )
    {
        return %n;
    }
    else
    {
        return fibRec( %n - 1 ) + fibRec( %n - 2 );
    }
}

--- End code ---


Port:

"Repeat a string":


--- Code: ---function stringRepeat( %string, %times )
{
    %result = "";
   
    for ( %i = 0 ; %i < %times ; %i++ )
    {
        %result = %result @ %string;
    }
   
    return %result;
}

--- End code ---


Port:

"Real constants and functions"

[*] E: Not available.
[*] Pi: $pi
[*] Square Root: mSqrt(x)
[*] Natural Logarithm: Not available.
[*] Base 10 Logarithm: mLog(x)
[*] Exponential: Not available.
[*] Absolute Value: mAbs(x)
[*] Floor: mFloor(x)
[*] Ceiling: mCeil(x)
[*] Exponentiation: mPow(x, y)
[*] Exponentiation Modulo: Not available.

Port:

"Assertion":


--- Code: ---if ( !expression )
{
    // possibly display an error
    // error( x );
    
    return;
    // instead, possibly return a value to parent function to abort as well
    // return x;
}

--- End code ---


"Add a variable to a class instance at runtime":

x.y = z;


"Higher-order functions":


--- Code: ---function first( %x )
{
    return call( %x );
}

function second()
{
    return "foobar";
}

--- End code ---

==>echo( first( second ) );
foobar


"Include a file":

exec("path/to/file.cs");


"Singletons":


--- Code: ---singleton ShaderData( SSAOShader )
{  
    DXVertexShaderFile = "shaders/common/postFx/postFxV.hlsl";
    DXPixelShaderFile = "shaders/common/postFx/ssao/SSAO_P.hlsl";            
    pixVersion = 3.0;
};

--- End code ---


"Reverse a string":


--- Code: ---function stringReverse( %string )
{
    %result = "";
    
    for ( %i = strLen( %string ) - 1 ; %i >= 0 ; %i-- )
    {
        %result = %result @ getSubStr( %string, %i, 1 ),
    }
    
    return %result;
}

--- End code ---


"Binary string":

"\xFA\x62"

Pages: << < (6/12) > >>

Go to full version