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

[string.sub help]

Asked by 11 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.)

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

2 answers

Log in to vote
2
Answered by 11 years ago
1elseif string.sub(string.lower(msg),1,13) == "openfrontdoor" then
2    mdoor.Transparency = 0.4
3    mdoor.CanCollide = false
4elseif string.sub(string.lower(msg),1,14) == "closefrontdoor" then
5    mdoor.Transparency = 0
6    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 — 11y
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 11 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.

1else if string.sub(string.lower(msg),1,13) == "openFrontDoor" then
2    mdoor.Transparency = 0.4
3    mdoor.CanCollide = false
4else if string.sub(string.lower(msg),1,14) == "closeFrontDoor" then
5    mdoor.Transparency = 0
6    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 — 11y
0
Actually, using else if in this situation is a bad idea and requires more ends. Articulating 1335 — 11y

Answer this question