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

I was wondering if you wrote a code and made a mistake would it still run?

Asked by 7 years ago
x= script.Parent
x.Changed:connect(function (x)
    if x.Value ~= ""
        wait(3)
        x.Value = ""
    else
        wait()
end)

I forgot to add the then but for some reason it worked. If i forget the then does it run everything under the if nomatter what the conditions are? Im just curious for learning purposes ofcourse

0
In this case, no, it can not, as this has something to do w/ a function; however, for outside things, such as properties that may not be valid for certain objects, you can use the pcall function: http://wiki.roblox.com/index.php?title=Global_namespace/Basic_functions#pcall TheeDeathCaster 2368 — 7y
0
Ah I see, Thanks windstrike 27 — 7y
0
Np. :) TheeDeathCaster 2368 — 7y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
7 years ago
Edited 7 years ago

Mistakes when you code broadly fall into three categories.

Syntax / Static Errors

These are errors that prevent the computer from understanding what your script means; for example, forgetting an end or misspelling tehn; not having ( or ) balanced right; using an invalid name or number like person 2 or 2person

Since the computer gets confused, it just stops when it finds the mistake and does no more work.

Crashes / Runtime Errors

These are errors that happen when you try to do something that doesn't make sense, for example "cat" + "dog" doesn't make sense and Lua will error, complaining that you can't add strings.

The computer can't1 predict that these will happen, so it will execute your script until that problem happens.

"Logic Errors"

This occurs when you program doesn't have any static errors, and doesn't crash, but doesn't do what you intended.

In other words, you wrote a valid program, but you didn't write the program you intended.

The computer can't possibly know your intent (beyond the program that you've given it) so if you make a typo that still ends up being a valid program, it will still run it.

What to do

Script Analysis can help catch some of those mistakes.

In general, it's better for errors to happen sooner; you'd prefer a syntax error over a crash; you'd prefer a crash over the program silently doing the wrong thing.

Defensive coding styles will make it more likely that errors happen sooner; as you get more practice you'll learn some through trial, error, and reading.


  1. It can't always. Some tools / programming languages are better at catching these problems ahead-of-time; Lua doesn't, though ROBLOX's Script Analysis will help you catch some of them! 

Ad

Answer this question