Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is meant by making a code "efficient"? Is it readability or is it less lines?

Asked by 3 years ago

I screwed up one of my games due to it being too "efficient" and by too efficient I mean I used a lot of module scripts and very little local scripts. This screwed my game up as my scripts depended so much on something to happen that even if there was one error in one script it would cause a error in other scripts. The whole game would error

I did save a lot of lines though.

But I do not understand what is meant by making a code efficient.

Does efficient mean easy to edit. Or less lines?

1 answer

Log in to vote
0
Answered by 3 years ago

I'd define efficiency as how quickly the code can complete and operation and how much memory it uses to do it. There is a ton of maths behind this, you can look it up if you're interested - at a basic level it's just common sense, get something directly rather than looping of possible etc.

It might not necessarily be "efficiency" but having tidy, modular code - which you could give to someone else and they'd be able to understand it - is really good practice. Don't have huge functions etc. Have a few small functions which deal with distinct aspects (e.g. one getting a player from character, one setting up a folder and int values inside the player, one to populate the values of these values). This will improve reusability and save you time in the long run (as well as letting you easily add extra steps etc.)

I like the idea of module scripts (it's like a more convoluted static variable from C# lol) but you've got to make sure you're using the modular code for what it's designed for, don't keep editing it to work with different use cases. (Someone else might be able to say whether calling numerous modules takes less memory than just copying the code - but if you copy the code you lose the ability to change everything all at once) so I'd say module scripts are both easy to edit and have less lines

Just be careful with your scripts, do lots of debugging to find the error because if you're using modules properly the only errors you should get are when you accidentally pass the wrong order of parameters. Just make sure you read your own module scripts before trying to call them from somewhere else. If you get an error undo what you just did and go through step by step to see what caused it.

Sorry this was a bit long winded, I'm looking forward to reading other people's opinions!

Ad

Answer this question