These two lines:
print("Hello")
print "Hello"
They both do the same thing: They print the string "Hello." So even though print() is a function, it works as a command/keyword? What's going on here?
These two lines:
print("Hello")
print "Hello"
They both do the same thing: They print the string "Hello." So even though print() is a function, it works as a command/keyword? What's going on here?
fn"str" and fn{} only work when passing string/table literals (not in a variable, table element, ect). This is syntax sugar for fn(...). The only downside to the sugar method is that you can only pass one argument to the function.
Examples of code that will fail:
local str, t = "Hello", {}
print str -- # fail
print t -- # fail
print"Hi", true -- # fail
In short:
print "Hello" is sugar for print("Hello").
The function "print ("Hello")" allows you to use Object names and variables such as this(put a part down named "Part" before running the script):
print(game.Workspace.Part.Name)
Without the parentheses the script thinks you are trying to change the value of Part.Name instead of printing it.
That's not what I'm looking for, I'm looking for WHY it works.
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
Not sure but I think this is why it still works without parenthesis : https://www.lua.org/pil/5.html
Beforehand ROBLOX’s Lua API allowed recursions of this. Either they’ve forgotten to deprecate this or it’s accepted due to the website posted above.