Beyond the script editor line: Is it bad practice?
#1
I suppose this is a question geared towards scripters?

So I've mixed feelings about this. I've been catching myself doing it for a bit, mostly because of the math stuff mixed with variables, dunno if they would still work if they were somehow separated in multiple lines instead of being one line.

Small example of code from my pause script:
Code:
@backgroundtone[bgt].viewport.tone.red = (@backgroundtone[bgt].viewport.tone.red * (@backgroundtone_c[bgt][3] - 1) + @backgroundtone_c[bgt][1].red) / @backgroundtone_c[bgt][3]
@backgroundtone[bgt].viewport.tone.green = (@backgroundtone[bgt].viewport.tone.green * (@backgroundtone_c[bgt][3]-1) + @backgroundtone_c[bgt][1].green) / @backgroundtone_c[bgt][3]
@backgroundtone[bgt].viewport.tone.blue = (@backgroundtone[bgt].viewport.tone.blue * (@backgroundtone_c[bgt][3]-1) + @backgroundtone_c[bgt][1].blue) / @backgroundtone_c[bgt][3]
@backgroundtone[bgt].viewport.tone.gray = (@backgroundtone[bgt].viewport.tone.gray * (@backgroundtone_c[bgt][3]-1) + @backgroundtone_c[bgt][1].gray) / @backgroundtone_c[bgt][3]

I'm sure Trickster considers code going over the script editor line to be bad practice, there's a small chance I could be wrong though. So does anyone consider having code that goes over the grey line in the script editor to be bad practice or something along those lines? o:

Edit: I meant this.
[Image: 11bn815.png]
Reply }
#2
going over that line is BAD imo. Your handwriting is pretty good though :P
Reply }
#3
Oh, I have seen plenty of scripts that go beyond the margin line but it is merely a guideline for you visually. Even Japanese scripters go beyond the margin line in the editor.

Can you really help it if performing complex math functions require your statements to go beyond the border? Maybe, but that could either require you to break your statement down to multiple lines or have extremely shortened variable names.

From a coder's point-of-view, your variables should have descriptive names, so your @backgroundtone_c value is pretty much correct. It could be shortened to @bkgrndtone_c, but that may not change your lines enough in some of these occasions.

I guess it comes down to cleanly write your code in a manner so the whole statement can be visible and understandable without having to scroll your
editor left to right.
Reply }
#4
If it still functions correctly then why change it? I'm no scripter, but that's my opinion.
Reply }
#5
@Yin: It can become much harder to debug.
I generally prefer breaking long lines into several smaller lines, but that's mainly because it's quicker to locate errors.
Reply }
#6
Taking from Punk's earlier example, you may see how easy it is to read and debug the code if formatted with line breaks:
# Background Tone (Red)
@backgroundtone[bgt].viewport.tone.red =
(@backgroundtone[bgt].viewport.tone.red *
(@backgroundtone_c[bgt][3] - 1) +
@backgroundtone_c[bgt][1].red) /
@backgroundtone_c[bgt][3]
# Background Tone (Green)
@backgroundtone[bgt].viewport.tone.green =
(@backgroundtone[bgt].viewport.tone.green *
(@backgroundtone_c[bgt][3] - 1) +
@backgroundtone_c[bgt][1].green) /
@backgroundtone_c[bgt][3]
# Background Tone (Blue)
@backgroundtone[bgt].viewport.tone.blue =
(@backgroundtone[bgt].viewport.tone.blue *
(@backgroundtone_c[bgt][3] - 1) +
@backgroundtone_c[bgt][1].blue) /
@backgroundtone_c[bgt][3]
# Background Tone (Gray)
@backgroundtone[bgt].viewport.tone.gray =
(@backgroundtone[bgt].viewport.tone.gray *
(@backgroundtone_c[bgt][3] - 1) +
@backgroundtone_c[bgt][1].gray) /
@backgroundtone_c[bgt][3]
Yeah... I did the colors too.
Reply }
#7
I second what DerVVulfman said, except I think @bkgrndtone_c is terrible... :)
@bg_tone_c anyone?

Oh, and it should be clear from the example above, but the idea is that you can break a line after specific elements, like math operators, but also dots, and so on...
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   RPGmXP Editor Hotkeys MechanicalPen 2 6,214 10-06-2013, 12:02 AM
Last Post: MechanicalPen
   Pause Script Feature Requests? PK8 11 17,950 05-25-2009, 11:07 AM
Last Post: Kain Nobel



Users browsing this thread: 1 Guest(s)