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

Why doesn't TextBounds.X not work?

Asked by 8 years ago
Edited 8 years ago

This is supposed to check if the current X TextBounds is bigger, and if it's bigger, it should change the variable to the new X TextBounds. However this isn't changing the value. I'll show you why below.

--NewMessage is a ScrollingFrame and Content is a TextLabel.
local X = 0
if X < newMessage.Content.TextBounds.X then
    print('Fixing.. X is ' .. X .. ' and will be ' .. newMessage.Content.TextBounds.X)
    local X = newMessage.Content.TextBounds.X
end
print('X = ',X)

OUTPUT

Fixing.. X is 0 and will be 161

X = 0

Why is the value not changing to 161? Is it something simple that I kept forgetting? Thanks! :)

1 answer

Log in to vote
3
Answered by 8 years ago
Edited 8 years ago

When updating a value, do not put localbefore it as this will create a new local variable for everything within that section, leaving the previously defined X's value as it is. This is a simple fix, just remove the local on line 5. Your code will then be this:

--NewMessage is a ScrollingFrame and Content is a TextLabel.
local X = 0
if X < newMessage.Content.TextBounds.X then
    print('Fixing.. X is ' .. X .. ' and will be ' .. newMessage.Content.TextBounds.X)
    X = newMessage.Content.TextBounds.X
end
print('X = ',X)

The output should then be:

Fixing.. X is 0 and will be 161

X = 161

Ad

Answer this question