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

Rebuilding my ELS Script, Recommendations? (still open to responses)

Asked by 4 years ago
Edited 4 years ago

So, I've been trying to figure out how to properly rebuild my ELS script, but when I brought it up to someone else I just got scrutinized for how old and Sh*tty it was, any idea's and recommendations would be fantastic. Here is some of the code:

ELS = script.Parent
while true do
            wait(0)

        if script.Parent.Lon.value == true and script.Parent.TAPattern.value == 4 then
        ELS.RTA1.BrickColor = BrickColor.new ("Medium blue")
        ELS.RTA2.BrickColor = BrickColor.new ("Lily white")
        ELS.RTA3.BrickColor = BrickColor.new ("Medium blue")
        ELS.RTA4.BrickColor = BrickColor.new ("Lily white")
        ELS.RTA5.BrickColor = BrickColor.new ("Medium blue")
        ELS.RTA6.BrickColor = BrickColor.new ("Lily white")
        ELS.RTA7.BrickColor = BrickColor.new ("Medium blue")
        ELS.RTA8.BrickColor = BrickColor.new ("Lily white")
        ELS.RTA9.BrickColor = BrickColor.new ("Medium blue")
        ELS.RTA10.BrickColor = BrickColor.new ("Lily white")

        ELS.RTA1.Transparency = 0
        ELS.RTA2.Transparency = 1
        ELS.RTA3.Transparency = 1
        ELS.RTA4.Transparency = 1
        ELS.RTA5.Transparency = 1
        ELS.RTA6.Transparency = 1
        ELS.RTA7.Transparency = 1
        ELS.RTA8.Transparency = 1
        ELS.RTA9.Transparency = 1
        ELS.RTA10.Transparency = 1

        wait(0.01)
        ELS.RTA1.Transparency = 1
        ELS.RTA2.Transparency = 0
        ELS.RTA3.Transparency = 1
        ELS.RTA4.Transparency = 1
        ELS.RTA5.Transparency = 1
        ELS.RTA6.Transparency = 1
        ELS.RTA7.Transparency = 1
        ELS.RTA8.Transparency = 1
        ELS.RTA9.Transparency = 1
        ELS.RTA10.Transparency = 1

        wait(0.01)
        ELS.RTA1.Transparency = 1
        ELS.RTA2.Transparency = 1
        ELS.RTA3.Transparency = 0
        ELS.RTA4.Transparency = 1
        ELS.RTA5.Transparency = 1
        ELS.RTA6.Transparency = 1
        ELS.RTA7.Transparency = 1
        ELS.RTA8.Transparency = 1
        ELS.RTA9.Transparency = 1
        ELS.RTA10.Transparency = 1

You can see how "Sh*tty" it is. RTA = Rear Traffic Advisor (I have the TA on the lightbar and the one in the rear window)

1 answer

Log in to vote
0
Answered by 4 years ago

This is just how I personally would do it.

local ELS = script.Parent;
local frames = {
  {B1 = 1; R1 = 0;};
  {B1 = 0; R1 = 1;};
};
local currFrame = 0;

while wait() do
  if script.Parent.Lon.Value == true and script.Parent.LPattern.Value == 0 then
    for Light, Value in pairs(frames) do
      local lightObj = ELS:FindFirstChild(Light);
      lightObj.Transparency = Value;
      --lightObj:FindFirstChild("PointLight").Enabled = (Value == 0);
    end;
    currFrame = currFrame + 1;
    if currFrame > #frames then
      currFrame = 1;
    end;
  else
    currFrame = 1;
  end;
end;

Again, this is just how I would do it. I have not made an ELS system before but have wanted to. This is the quick and dirty way that I would do it. The pretty way I would do it would be making a ModuleScript that allows you to add and remove frames.

0
This is a bad answer. Calling wait in the conditional part of a while loop, not using events (Changed would work best here), and abusing semicolons. programmerHere 371 — 4y
0
Abusing semicolons. Bro I'm coming from a background of 12 years of PHP and JavaScript. All a semicolon does is an end of line delimiter. If you think a .Changed event would work best here, then instead of downvoting, make your own damn answer on here with how you would do it. I said this is "PERSONALLY" how I would do it, didn't say it was the best or worst way. MrLonely1221 701 — 4y
0
lol royaltoe 5144 — 4y
1
Using a discard function inside of the wait loop has no consequences. If you have no use for the delta nor the total script runtime then it's completely fine to use wait() as a condition. Remember, if you can't use function calls in a condition, you can't use variables in a condition. It's essentially the same thing! So much for "programmerHere" lol Fifkee 2017 — 4y
Ad

Answer this question