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

[string.sub help]

Asked by 10 years ago

Can anyone see a problem with what is indexed below? I have made sure the variables are correctly found, I have tested this script in game with a report-error thing, and it doesn't show an error. (Yes, there is more to the script, this is just a piece of it.)

            elseif string.sub(string.lower(msg),1,13) == "openFrontDoor" then
                mdoor.Transparency = 0.4
                mdoor.CanCollide = false
            elseif string.sub(string.lower(msg),1,14) == "closeFrontDoor" then
                mdoor.Transparency = 0
                mdoor.CanCollide = true

2 answers

Log in to vote
2
Answered by 10 years ago
elseif string.sub(string.lower(msg),1,13) == "openfrontdoor" then
    mdoor.Transparency = 0.4
    mdoor.CanCollide = false
elseif string.sub(string.lower(msg),1,14) == "closefrontdoor" then
    mdoor.Transparency = 0
    mdoor.CanCollide = true

Your script was not working because you were calling string.lower on the message, which makes all letters lowercase, then comparing it to a string that contains capital letters.

0
Thanks! wattleman 90 — 10y
0
msg:lower():sub(1,13) is a much shorter way to write the same thing! BlueTaslem 18071 — 10y
Ad
Log in to vote
-3
Answered by 10 years ago

There's supposed to be a space in between else and if. I know I didn't fully answer this because I'm new to scripting also, but this is what I know.

else if string.sub(string.lower(msg),1,13) == "openFrontDoor" then
    mdoor.Transparency = 0.4
    mdoor.CanCollide = false
else if string.sub(string.lower(msg),1,14) == "closeFrontDoor" then
    mdoor.Transparency = 0
    mdoor.CanCollide = true
0
That is false. It is elseif, but can also be "else if." As far in this situation, the difference does not matter. AmericanStripes 610 — 10y
0
Actually, using else if in this situation is a bad idea and requires more ends. Articulating 1335 — 10y

Answer this question