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

How do I make this script say "Hello Robloxians" (Part 2)?

Asked by 9 years ago

I got the answer from someone, but what they gave me had an error. This is what I had for the script he answered:

function SayHello(Name)
print(Name..'!')
end

SayHello("Hello Narblet") OUTCOME --> Hello Narblet!

SayHello("Hello FUDGEWAD") OUTCOME --> Hello FUDGEWAD!

They are saying there is an error in Line 7. But I don't see what the problem is. Please help me.

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

You can't include random pieces of English inside your program.

The Lua interpreter will believe it's code and cause problems.


If you need to include explanatory text, you have to use comments (using a double hyphen)

function SayHello(Name)
print(Name..'!')
end

SayHello("Hello Narblet")  -- Hello Narblet!

SayHello("Hello FUDGEWAD") -- Hello FUDGEWAD!

-- (or like this if you prefer):
-- OUTCOME --> Helo FUDGEWAD

(In this editor, comments (the stuff that Lua ignores) is highlighted green. Compare with what you originally posted)



From comments:

Comments don't do anything. The computer ignores them. So why would you ever have comments in code?

While they don't mean anything to Lua, they do (should) mean things to humans writing and reading code. You write comments to make explanations to yourself or to others using your code (like you had).

Good code includes comments.

On the other hand, since comments make Lua ignore pieces of the program, it's frequent that you'll see things like this:

x = x ^ 0.5
-- x = math.sqrt(x)

Where some code has been "commented out" to be ignored. While this can be convenient for debugging, in the long term it's almost universally considered to be bad practice to have this commented-out code remain.

0
What do you mean the LUA would cause problems User#5689 -1 — 9y
1
The computer will treat everything except comments (the green things) as code, thus your error. Also Lua is not an acronym. Perci1 4988 — 9y
0
I mean the text would cause problems for Lua. If you were ordering food at a restaurant, and I said, "I would aghi like a oshaowiehei burger with oawihe no gof pickles asodifjasodjfi", you wouldn't get anywhere. You're including garbage that doesn't mean anything -- which confuses the waitress (or Lua, in this context) BlueTaslem 18071 — 9y
0
So the green letters means nothing then. I shouldn't have included them? User#5689 -1 — 9y
0
Good code includes comments -- they *can* and *should* mean something to HUMANS -- (yourself or others using your code) -- but ultimately the computer will ignore them. Explanations are good to keep track of what's going on. BlueTaslem 18071 — 9y
Ad

Answer this question