Jump to content

Dora Gustafson

Advisor
  • Posts

    2,120
  • Joined

  • Last visited

Posts posted by Dora Gustafson

  1. This has not been suggested yet:

    string truncate_float_decimals( float x, integer n)
    {
        string s = (string)x;
        integer i = llSubStringIndex( s, ".");
        return llGetSubString( s, 0, i-1)+llGetSubString( s, i, i+n);
    }

    It is straight forward
    In this form it doesn't work with scientific notation and it does not round but it is simple and can easily be modified for special needs

    This code is not tested but the principle is

     

    • Like 1
  2. JSON in LSL is slow compared to a similar task solved the traditional way with lists

    Avoid using JSON it in time critical applications

    Use JSON for complex list arrays when the execution time is not critical

    • Like 3
  3. I may be wrong but in my book the script is running in an event handler and the event handle will be busy until the loop is finished. Thus it will stop other events while running and the event queue will build up. Virtually this is what the llSleep() does but in so many more words

    • Like 1
  4. Texture animations are by nature not synchronized, but if they are loaded to the viewer at the same time they are.

    For instance if you tp to a site and can see all the animated faces they will most likely be in sync

    The chance for sync is even better if all faces use the same texture (it is only loaded one time)

    :smileysurprised::):smileyvery-happy:

  5. You don't want a script for that

    Simple, basic animations and other animations that do not animate at least neck and scull bones does exactly  what you want, or rather the viewer does it for you. Use mouse cursor and keys: 'Alt Gr' + 'left mouse' to 'look' at an object/avatar and your avatar will keep looking at that object/avatar when it moves around

    :smileysurprised::):smileyvery-happy:

  6. I still don't understand rotations/quarternions fully and don't expect I ever will, but I have learned the mathematical rules and I have worked a lot with them
    Now I can do most things I want with rotations even though sometimes I need to rewrite several times before I get it right:smileyembarrassed:

    My advise is: Work with it, read examples an make them work, give yourself problems and solve them

    It takes time but there is no shortcut for normal people

    :smileysurprised::):smileyvery-happy:

  7. Bit flag parameters are used in many LSL functions and not in a small way

    1. llTakeControls() and control
    2. llRequestPermissions() and run_time_permissions
    3. llGetInventoryPermMask and llGetObjectPermMask()
    4. Masks in llParticleSystem()
    5. llSetVehicleFlags and llRemoveVehicleFlags

    I will not list them all

    These examples shows what bit flags are good at: Marking and unmarking mutual independent cases

    :smileysurprised::):smileyvery-happy:

  8. Using each bit in an integer gives you 32 Booleans which is 32 times more dense than one Boolean per integer. One Boolean per integer is standard in LSL. It can be TRUE or FALSE.

    But maybe that is what you are saying, I'm not sure

    :smileysurprised::):smileyvery-happy:

  9. Bit flags are useful but why restrict the use to the Exclusive OR function when we have the full register?

    // bit logic by Dora Gustafson, Studio Dora 2016integer bits; // contains flags 0 thru 31integer flag( integer x){    return 1<<x & bits;}setflag( integer x){    bits = 1<<x | bits;}clrflag( integer x){    bits = ~( 1<<x) & bits;}eorflag( integer x){    bits = 1<<x ^ bits;}showbits(){    string s;    integer i = 32;    while ( i-- )    if ( flag( i)) s+="1";    else s+="0";    llOwnerSay( s);}default{    state_entry()    {        showbits();        setflag( 0);        setflag( 3);        setflag( 4);        showbits();        clrflag( 2);        clrflag( 3);        eorflag( 4);        eorflag( 5);        setflag( 31);        showbits();    }}/*Test output: 00000000000000000000000000000000Test output: 00000000000000000000000000011001Test output: 10000000000000000000000000100001*/

    I use bit flags regular but never in a convoluted  form like this, rather as in-line code

    :smileysurprised::):smileyvery-happy:

    • Like 1
  10. I still use RPN and will to the day I die. Not so much on original calculators. Much more in apps that runs on PC, tablet and smart phone. In those apps the original Hewlett-Packard code lives on. Really, I would feel lost without it.

    :smileysurprised::):smileyvery-happy:

  11.  

    

    "exponent" and "magnitude" triggered me:smileywink:

    Or exponent and mantissa.

    Give me back the slide rule, no batteries, readable everywhere and not controlled by Google or Microsoft

    :smileysurprised::):smileyvery-happy:

  12. float a = 1.2345678E38;float b = 0.0;float c = 1.2345678e-8;string fixedPrecision(float input, integer precision){    if((precision = (precision - 7 - (precision < 1))) & 0x80000000)        return llGetSubString((string)input, 0, precision);    return (string)input;}default{    state_entry()    {        llOwnerSay( "a = "+fixedPrecision( a, 3)+" b = "+fixedPrecision( b, 3)+" c = "+fixedPrecision( c, 3));    }}/* Output: a = 123456800000000000000000000000000000000.000 b = 0.000 c = 0.000*/

    I had to do this to figure out what might be the meaning of the word 'precision'.

    The output indicates that precision is used for the number of decimal digits after the decimal point.

    In my vocabulary a is presented with seven digits precision while c is presented with zero digits precision.

    After all this routine is very useful for numbers with absolute values not too big and not too small and zero

    :smileysurprised::):smileyvery-happy:

  13. You are right, my mistake

    Still it is a bit in sane to keep digits after the point that carry no value and to round small numbers to zero

    float a = 1E38;float b = 0.0;float c = 1e-8;default{    state_entry()    {        llOwnerSay( "a = "+(string)a+" b = "+(string)b+" c = "+(string)c);    }}/*Output a = 100000000000000000000000000000000000000.000000 b = 0.000000 c = 0.000000*/

    :smileysurprised::):smileyvery-happy:

×
×
  • Create New...