• Announcements

    • Xiola Linden

      The New Community Platform   03/21/2017

      We are still working on making adjustments and changes to the new platform. Thanks  to everyone who has been sending in feedback and filing any bugs you've encountered! 
Sign in to follow this  
Followers 0
Beowulf Zessinthal

LSL vs C# simple examples

7 posts in this topic

When i first learnt to script (in LSL), i thought i had fallen into heaven :) 

So logical, so powerful .. ahh.. but soon in Sansar the scripting language will be C#.

Im excited for the chance to see some comparative LSL vs C# examples.

I will post a basic LSL script here.. would someone show me a reasonable C# version?

Then maybe folk who already know both can post a few other examples?

Title what the script does: 

LSL: Switch alpha values of object using a timer


float alpha;

default
{
    state_entry(){
    alpha= 1.0;
    llSetAlpha(alpha, ALL_SIDES);
    llSetTimerEvent(2);
    }

    timer(){
        if(alpha == 1.0){
        alpha= 0.4;
        }
        else{
        alpha= 1.0; 
        }
    llSetAlpha(alpha, ALL_SIDES);
    }
}

 

Share this post


Link to post
Share on other sites

It would look like something like this in C#:

float alpha= 1.0f;

public void default_event_state_entry()
{
    this.alpha = 1.0;
    this.llSetAlpha(alpha,ALL_SIDES);
    this.llSetTimerEvent(2);
}

public void default_event_timer()
{
    switch( alpha )
    {
        case 1.0:
            alpha = 0.4;
        break;
        default:
            alpha = 1.0;
        break;
    }
    this.llSetAlpha( alpha,ALL_SIDES);
}

For larger project C# will be superior and easier to code and control. The most notable difference in the above sample is the definition of default_event_state_entry, where you have to create event handlers for the basic events touch_start etc. Second the switch statement makes handling if-statements much easier.

Compared to LSL there will be a little more code to write, but IMHO this is a small price to pay for much better programming control and logic.

Share this post


Link to post
Share on other sites

awesome thanks so much!  .. i dont quite understand the detail of it yet of course but i will look at it really hard tomorrow and soak up 'how it looks' as a first step! That will be a big and exciting time for me! thanks again Rachel!

1 person likes this

Share this post


Link to post
Share on other sites

Everyone .. please feel free to add in simple comparative examples if you think they can demonstrate some specific thing you are interested in showing about C#!

Share this post


Link to post
Share on other sites

I wonder if you'll find that the LSL/C# language differences will be dwarfed by the differences in simulation and scripting architecture between SL and Sansar. Most of the time you spent learning LSL was not in learning the language, but rather how the simulator, event system, physics, communications, UI, camera and other SL bits operate, and how the LSL function library lets you work them.

Share this post


Link to post
Share on other sites

Thats true Madelaine ..  but as i cannot get in yet i am getting better acquainted with the things i will need to know.

So later i will have less frustration^^

C# seems very doable after LSL .. so far only 1.5 days spent, but already im optimistic^^

Over the next few days i will watch a few youtube tutorials too. 

Bring it on baby!

Edited by Beowulf Zessinthal

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  
Followers 0