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

Mentioning a word in a for loop?

Asked by 8 years ago

This is something I have never tried before. Doing a #variable with a for loop. Does this actually work though?

startingTime = game.Workspace.Map.STimer.Value

for mapIn = #STimer, 1, -1
    game.Workspace.Message.Text = mapIn
        wait(1)
end

1 answer

Log in to vote
3
Answered by 8 years ago

What you're referring to is the numeric for loop. This loop is nothing more than saying:

-- Remember, the first "word" we give a for loop, is always the variable of it's integer. And because it's a variable, it can be anything ("i" just seems to be a fast and easy choice most of the time)

for i = 1,5 do
    print(i)
end

-- Output --
-- > 1
-- > 2
-- > 3
-- > 4
-- > 5

Now, when you say something like #STimer, this isn't any different from using any other number. The "#" operator converts a table or string, to a number that represents how much content it has. For example:

-- On a string:
print(#'hello') -- > 5 (because this string has 5 characters. This can also be done with string.len())

-- On a table:
print(#{1,2,3,4,5}) -- > 5 (because this array has 5 values in it)

In your example, this will actually error since you're using "#" on neither a string, nor a table. "STimer" in this case is a value object of some kind, and cannot be converted to a number. Not enough information is provided from your code to allow me to correct it, but hopefully that explanation on numeric for loops was sufficient. Let me know if you have any questions.

0
Oh I get it now. NeonicPlasma 181 — 8y
Ad

Answer this question