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

how to make this movement system script cleaner?

Asked by 8 years ago

on line 2, is there a better way to get the parent's move stat? i dont want to have to type a function for each number (4,5,6,7,8, etc.)

also is there a way to project selection boxes from line 4 according to the move stat ?

like a move stat of 3 would be 3 bricks in each direction, 4 would be 4 in each direction, etc.

(if it's math, i suck at math)

for i, v in pairs(game.Workspace.Map:GetChildren()) do
    if script.Parent.Move.Value == 3 then
        if v.Name == "TerrainB" then
            Instance.new("SelectionBox", v)

    if script.Parent.Move.Value == 4 then
        if v.Name == "TerrainB" then
            Instance.new("SelectionBox", v)

    if script.Parent.Move.Value == 5 then
        if v.Name == "TerrainB" then
            Instance.new("SelectionBox", v)

    end
        end

    end
        end
            end

    end
        end
0
Tab your code correctly. BlueTaslem 18071 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

This may be a small improvement for superalp1111 answer:-

You might be able to use if we do not need to check the value ranges each time:-

if script.Parent.Move.Value > = 3 and script.Parent.Move.Value <= 10 then
    for i, v in pairs(game.Workspace.Map:GetChildren()) do 
        if v.Name == "TerrainB" then 
            Instance.new("SelectionBox", v) 
        end
    end
end

Method 2, this would be faster as only one check is made instead of two possible checks when putting the "if script.Parent.Move.Value > = 3 and script.Parent.Move.Value <= 10 then " 1st:-

for i, v in pairs(game.Workspace.Map:GetChildren()) do 
    if v.Name == "TerrainB" then 
        if script.Parent.Move.Value > = 3 and script.Parent.Move.Value <= 10 then
            Instance.new("SelectionBox", v) 
        end
    end
end

Hope this helps.

0
it made the selection boxes, but it's not visible AwesomeSauce666556 0 — 8y
0
which method are you using? User#5423 17 — 8y
0
second one AwesomeSauce666556 0 — 8y
0
The second method is the same logic as superalp1111 but swapped around, there is no real difference except the checking order User#5423 17 — 8y
0
oh hmm. i dont know why it isnt visible. it's visible when with another script when i move the mouse over the bricks AwesomeSauce666556 0 — 8y
Ad
Log in to vote
1
Answered by 8 years ago

If you are going to type absolutely same thing in every if condition, this may help you.

for i, v in pairs(game.Workspace.Map:GetChildren()) do 
    if script.Parent.Move.Value > = 3 and script.Parent.Move.Value <= 10 then       
        if v.Name == "TerrainB" then 
        Instance.new("SelectionBox", v) 
    end
end

So you can type as much conditions as you want if you put "and" and "or" between conditions. For ex. This script will work when value is between 3 and 10, or when equal to 3 or 10.

0
thanks. thats one part AwesomeSauce666556 0 — 8y

Answer this question