Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

3 comments

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

0

Ah I see, Thanks

0

Np. :)

1 answer

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't[^1] predict that these will happen, so it will execute your script until that problem happens.

[^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!

"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.

This discussion is preserved as it was. New answers, comments, and votes are closed.