Jump to content

Starting with LSL


Lexie Linden
 Share

You are about to reply to a thread that has been inactive for 464 days.

Please take a moment to consider if this thread is worth bumping.

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 3
Link to comment
Share on other sites

  • 3 weeks later...
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
  • Like 1
Link to comment
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!

Link to comment
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
Link to comment
Share on other sites

  • 2 months later...

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
Link to comment
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
Link to comment
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
Link to comment
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.
Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

  • 2 weeks later...
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

Link to comment
Share on other sites

  • 2 months later...

As someone who picked up LSL in the last 2 years when I rezzed in.

Have something you desire to make happen. A bouncy ball that if an avatar touches it plays a sound and dies.

Literally, anything that gets your creative scripting juices flowing. The passion to make things happen in SL is what will fuel your curiosity to discover the means. If all else fails there is a wonderful community of intelligent passionate scripters who are willing to set you in the right direction. :)

 

// " That's what I'm saying, quote unquote, and you can quote me on the quote unquote - Dane Cook "

Link to comment
Share on other sites

5 hours ago, LoneWolfiNTj said:

This appear to be a lake. There is no college there.

Fake? No, you are just reading a post that was made eight years ago.  SL changes a lot in that much time.  You should be very surprised when ancient advice (and especially directions to a specific spot) is still valid.  The College was an institution in SL for many, many years.

Link to comment
Share on other sites

  • 2 weeks later...
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.

To add to this, you can typically save a lot of memory in in-lining your functions .. even if you call that functions many, many times.

The cost is the maintenance overhead that comes with code duplication. 

silly example

easy to read - 1024 bytes in functions (2x512)

function a (integer x) {
	return x+40;
}
function c (integer x) {
	return x+20;
}


z = a(100) + c(33);
g = a(22) + c(4);

less memory - 0 bytes in functions

no functions at all 

z = (100 + 40) + (33 + 20);
g = (22 + 40) + (4 + 20);

this example is rather silly , but you get the idea.

Obviously for much larger and more complicated functions it gets messy much faster but this can save considerable memory and make the difference between a single script project or a multiple script one.

  • Thanks 1
Link to comment
Share on other sites

19 hours ago, steph Arnott said:

User created functions should assessed as to memory usage. A function that returns no memory reduction in usage is pointless.

Whats considered good coding practice  tends to produce slow bloated very readable code, abstracted a dozen api's high and so far from actual hardware as to make it irrelevant.

LSL might still be one api stacked onto of another, but its presented to the user as almost a fixed virtual platform so should be treated as bare metal. Fast and memory efficient for the win.

Newbies to LSL tend to accidentally write more platform specific efficient code, and as they learn good practices and industry standards, their code explodes in volume and consumes vastly more resources. Perversely, end user perspectives are exactly the opposite and newbie coders are blamed for all that ails SL, and skilled coders producing huge multi script abstracted madness are fine.

In a way I guess good LSL requires a coder to go full circle, and get back to the point that they understand why their early small hacky scripts were actually good, if a little clumsy.

 

 

Link to comment
Share on other sites

14 minutes ago, CoffeeDujour said:

Simple fact is that most just want a script to achieve something.  The issue of bloating does start to appear in the mid stage level. It seems to me a case of not understanding the code in the first place. Another issue is that many do not take into account built in function delays. Personally i would rather see ten scripts that just do as written than one which seems to have been kludge together using code that clearly was by different people. An issue i got persuaded into was this stupid idea that scripts should be in a single state and those using multi states are idiots. That i found out after a heck of a lot of issues is total nonsense. Unfortunately when learning one tends to think those doing technobabble know what they are talking about.

At the end of the day LSL is not running a bank etc and was only ever intended for agents to create fun things. The world is not going to explode if a green coder writes three hundred lines to move a box 0.1 every time to get a smooth movement from A to B. And it would actually run more efficient than a loop. I know, i did that in the early days and was damned impressed with myself.

As for user functions i create them when i have to and not as an excuse to be lazy. But that is my way.

  • Like 2
Link to comment
Share on other sites

On 3/20/2019 at 7:04 AM, Rolig Loon said:

Fake? No, you are just reading a post that was made eight years ago.  SL changes a lot in that much time.  You should be very surprised when ancient advice (and especially directions to a specific spot) is still valid.  The College was an institution in SL for many, many years.

Re "Fake", no, I said "lake". 🙂 Nope, that wasn't a typo. If you don't believe me, go there; you'll find it's a lake, not a fake.

Re "8yrs... changes a lot...", yep, appears so, in 2nd Life as in 1st. To bad, the college sounds like a kind of thing that would be very useful. Are there any other entities like it (that teach LSL programming, object construction, etc) still around?

Link to comment
Share on other sites

On 3/20/2019 at 3:52 PM, steph Arnott said:

It ceased five odd years ago. 'why?' have no idea, even if i did it would be useless information. 

Oh, I dunno. I've often found historical "why's" to be useful information, though the uses may only manifest months or years after learning them.

 

Link to comment
Share on other sites

  • 1 month later...
You are about to reply to a thread that has been inactive for 464 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...