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

What is the Syntax for Get Value?

Hi! I am a beginner Lua Coder. I stumbled across the print syntax and was wondering what get's syntax was.

I do know java and Turing, so I thought learning the syntax first would be faster the re-learning the whole language.

In Java, to get a value, it's

type variable = ScannerName.nextType();

In Turing, it is simply

get variable

So I was wondering what it is in Lua.

I spend a small 10-min trying to figure it out. Considering that the run window is the game itself, I think that there is no get value. But, I am asking to make sure.

Also, is there a good web page that gives me all the list of syntax? I just cannot seem to find one. Thanks in advance.

1 comment

0

The type(), method will return the parameter's value type in the form of a string. More information can be found on the Roblox Wiki, but this link will show you the basic functions in RBXLua. http://wiki.roblox.com/index.php?title=Global_namespace/Basic_functions#type

1 answer

✓ Accepted answer

There is no "get" keyword. In Lua, it's very close to how Java does it. You can:

  1. Assign 1+ expressions to 1+ variables: a, b = 1+2, "hello" --'a' will be 3, 'b' will be "hello"; more common is just one variable: c = workspace.MyPart
  2. Pass the expression(s) to a function: doSomething(a, 20)

Note that in Java, you have to declare the type of the variable, but in lua you don't. The closest thing is that you can specify that a variable is local, like so: local a, local a, b, c, or even local a, b = 1+2, "hello"

By the way, you can send or receive multiple arguments to a function:

function receiveMultiple(a, b)
	print(a, b)
end
receiveMultiple(1, 10) -- will print 1, 10
function receiveAnyNumber(...)
	local list = {...}
	for i = 1, #list do
		print(list[i])
	end
end
receiveAnyNumber() -- will not print anything
receiveAnyNumber(1, 2, 4) -- will print 1 then 2 then 4
function returnMultiple()
	return 1, 2
end
print(returnMultiple()) -- will print 1, 2
a, b = returnMultiple() -- a will be '1', b will be '2'

Online resources for learning Lua:

2 comments

0

Thanks a lot man. Really appreciate your help!

0

You're welcome! Btw, when you find an answer that solves your problem, you're encouraged to mark it as the answer to your question, so everyone knows your problem is resolved.

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