Jump to content
Lexie Linden

Starting with LSL

Recommended Posts

4 hours ago, Love Zhaoying said:

I’ve found something interesting and annoying a few years ago: each user function has a certain amount of overhead memory dedicated. I saved a lot of memory by combining 7-10 functions into 1. Surprising?

All custom functions are 512 byte alligned in memory.

That means they all use at least 512bytes, no matter how small they are, and that they get more memory as they become bigger, in 512 byte chunks.

  • Thanks 2

Share this post


Link to post
Share on other sites
On 9/15/2018 at 8:56 AM, Klytyna said:
Quote

So sayeth every failed amateur coder since the late 1940's, when the electronic programmable computers were first being built and developed...

Learning to program isn't an 8-10 hour task.

It absolutely is. Perspective is important here. Most of the people who wrote here seem to ignore the context. When you have never scripted or programmed and you want to make a small script, you just want to make something that works, at all, even if just partially. Your goal is not to become a professional programmer or scripter, you just want to make a small thing and call it your own. It doesn't matter if it's incomplete, bugged, bloated or laggy. You just want it to work at all.

If you can make your cube say something else than "Touched." when you click on it, that's fun.

If you can make it say the current SLT time, then wow, things are getting exciting!

And if you can make it say the current time in your own time zone, that's another exciting step and it doesn't matter what the script looks like, as long as it works.

That's how you start. To someone who never scripted or programmed before, they can't even know if they will be able to make their cube do that because everything seems so uncertain.

In 8-10 hours of taking a good programming tutorial, you learn about data types like strings, you hopefully learn that integers and floats are treated as different and somewhat incompatible things, you learn about global and local variables, you learn that you CAN create your own functions, you learn that lists exist and that they can be used in creative ways, for example as a 2D grid or as dynamic memory.

You learn the general idea of brackets, and you learn how functions and everything else are vaguely supposed to work together. Without this knowledge, you might write

state_entry(){
llGetObjectName();
}

and you will save. It will compile without errors, making you believe that you did this step right. The next step is to somehow access and display this information. You might try...

touch_start(integer t){
llOwnerSay("My name is t");}

or

llOwnerSay("My name is "+t);}

or

llOwnerSay("My name is "+ObjectName");}

or

llOwnerSay("My name is "+llGetObjectName);}

or

llOwnerSay("My name is "+llGetObjectName(););}

etc.

You will try all these wild attempts at magic and fail fail fail and waste a great amount of time and effort.

What truly matters is that you get some sense of direction. That's what the 8-10 hours are for. If you took a partial C# tutorial, state_entry() won't look so strange to you because you've seen it many times before and you vaguely know how to use it. On the wiki, you will vaguely know what kind of information that you need, what part of the page is pertinent to your current need, and if you copy/paste something, you will at least have a vague idea of what it actually does and where/how to use it in your script. You won't spend an hour doing trial and error trying to figure out where to copy/paste something or if you're even trying to copy/paste the right thing.

Later you will stumble on some tricks like "position.y" or "string functionName(){" or "functionName(string height){" and you will leave them on the back-burner until the day where you find a reason to use them and learn them properly. As long as you're just trying to get a cube to tell you the SLT time, you won't need to learn & use any of that fancy stuff.

Quote

 

There's a BIG problem with telling would-be LSL scripters to "learn the basics using [insert advisors favorite language here]".

That's how you aquire BAD habits, and end up constantly moaning that LSL doesn't support Feature-X of #Buttscript (tm).

 

With 8-10 hours, you haven't formed habits yet, and you certainly haven't learnt to depend on language-specific features. And LSL looks a lot like a simpler, more convenient version of C#, so it's easy to transition.

Quote

For an LSL beginner, learning to "flowchart" would be a damn sight more useful than learning a different programming language.

That's exactly what spending 8-10 on a tutorial is for. It gives you a sense of how things work, it gets you started smoothly on your first projects, and you learn more and refine as you keep scripting. If your first project is a complex one, it will become a disgusting mess, but at least it will give you small victory after small victory and you will actually get to see your script DO things and evolve, instead of getting stuck at the start for hours, staring at a script that is completely unintelligible to you.

My first script was something that would lock my earrings on me using RLV. I had no basics. Somehow with a lot of trial and error and many hours, I kinda got it to work to lock the specific item that had the script in it. I learned NOTHING from the experience.

 

Edited by Naskiff

Share this post


Link to post
Share on other sites
On 9/20/2018 at 3:34 PM, Kyrah Abattoir said:

All custom functions are 512 byte alligned in memory.

That means they all use at least 512bytes, no matter how small they are, and that they get more memory as they become bigger, in 512 byte chunks.

Sorry I missed your response. Thanks! If it was clearly documented, I would have changed my scripting habits years ago to save all the memory!

Share this post


Link to post
Share on other sites
6 hours ago, Naskiff said:

My first script was something that would lock my earrings on me using RLV. I had no basics. Somehow with a lot of trial and error and many hours, I kinda got it to work to lock the specific item that had the script in it. I learned NOTHING from the experience.

MY first script in SL, grabbed the vector for the sun position in SL, and checked if the z axis was positive or negative so as to work out if it was sim-day or sim-night, so as to automagically turn a light on and off...

I did learn from the experience, I learned that LSL worked NOTHING like ANY of the programming or scripting languages I had learned before despite "appearing to use similar syntax to..." several of them.

Telling people that they can learn LSL in 8-10 hours by watching Spew-Tube videos for non LSL languages, is an example of WEAPONS GRADE STUPIDITY.

In addition if you learned NOTHING from your first script, you weren't paying attention, you should at least have learned how to debug a LSL script using the unhelpful in world script editor...

Also, I'd be more impressed if you had mastered the 8-10 minute tutorial on quoting other peoples posts, and adding your replies, rather than making a pigs ear of it and producing some trash that says I wrote your reply...

 

Edited by Klytyna
  • Like 1

Share this post


Link to post
Share on other sites

The article has nothing to do with LSL, but I think it's a very good explanation of what coding is all about -- my background is originally in literature and languages, then business and law, and I had no particular coding experience until I encountered LSL.   This article really sums up my experience of coding, and why I enjoy it so much:  https://slate.com/human-interest/2018/12/against-teaching-kids-to-code-creativity-problem-solving.html

Edited by Innula Zenovka
  • Thanks 1

Share this post


Link to post
Share on other sites

Nice article.  Thank you. The author is making the same points that you and I make frequently here in SL.  Coding is only superficially about using the correct syntax and selecting functions appropriate to your task.  The heart of coding is logic, supported by curiosity and experimentation.  While it is possible to learn some basic principles of coding by aping someone else's examples, you cannot truly understand what is going on without being able to step back and appreciate the flow of logic that a script represents.  You cannot write tight, useful scripts until you tinker enough with your work to see how and when it is likely to fail -- again, a process of applying curiosity and experimentation.  The best preparation for learning to write computer code, whether you are in grade school or a retiree, is solving and creating puzzles to exercise your talent for anticipating outcomes, assessing alternatives, and optimizing efficiency.

Edited by Rolig Loon
  • Like 1

Share this post


Link to post
Share on other sites

I puchased the 'scripting your world' book. I found it very good.

Edited by steph Arnott
Book title was incorrect.

Share this post


Link to post
Share on other sites
On 12/10/2018 at 7:13 PM, Rolig Loon said:

Nice article.  Thank you. The author is making the same points that you and I make frequently here in SL.  Coding is only superficially about using the correct syntax and selecting functions appropriate to your task.  The heart of coding is logic, supported by curiosity and experimentation.  While it is possible to learn some basic principles of coding by aping someone else's examples, you cannot truly understand what is going on without being able to step back and appreciate the flow of logic that a script represents.  You cannot write tight, useful scripts until you tinker enough with your work to see how and when it is likely to fail -- again, a process of applying curiosity and experimentation.  The best preparation for learning to write computer code, whether you are in grade school or a retiree, is solving and creating puzzles to exercise your talent for anticipating outcomes, assessing alternatives, and optimizing efficiency.

Could be interesting to have a list of projects up on the wiki in the tutorial section that novices could attempt and then once completed would leave them with a deeper understanding than they would usually have of LSL and its application in world. Would help give them a solid foundation. Not a tutorial per say, more a series of briefs. Its a shame they locked up the wiki and only let the elite few alter it.

  • Like 2

Share this post


Link to post
Share on other sites
5 hours ago, chibiusa Ling said:

 Its a shame they locked up the wiki and only let the elite few alter it.

It was locked because idiots kept editing the scripts making them useless. Also there already is a set of scripting projects inworld which are an addition to the 'Scripting your world' publication.

Edited by steph Arnott
Book title was incorrect.

Share this post


Link to post
Share on other sites
1 hour ago, steph Arnott said:

It was locked because idiots kept editing the scripts making them useless. Also there already is a set of scripting projects inworld which are an addition to the 'Scripting your world' publication.

Yeah I know why it was locked. As regards Scripting Your World (my copy is sat across from me on my book shelf), that book is okay for giving someone a base I guess but at the same time I would question giving it to new scripters these days. Whilst it does contain a lot of useful information some of the coding techniques contained within are now outdated and would just be teaching people that inefficient practices are "How its done". The book needs updating really but I doubt that will ever happen. The best place to learn scripting is in world at The College of Scripting IMO.

Share this post


Link to post
Share on other sites

Will not undated for the simple fact that the book in all these years has not even paid for itself. Most SL clients do not want to pay for anything. As for the book being out of date it still gives the reqiured processes of lsl. Using newer code and better code is the next level. One does not teach a five year old how read by using the works of Shakespeare. ' The College of Scripting IMO ' do no t make me laugh, I got more bogus nonsense from that lot that it took months to de-learn all their garbage.

Share this post


Link to post
Share on other sites
On 10/9/2018 at 8:29 PM, Love Zhaoying said:

Sorry I missed your response. Thanks! If it was clearly documented, I would have changed my scripting habits years ago to save all the memory!

You and me both, I used to write dozens of custom functions for the smallest things in order to mimic some form of encapsulation.

But not anymore :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×