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

Help with Parameters?

Asked by 9 years ago

Could a fellow coder explain to me a little more about how parameters work? Is it like this:

BeCool(4)

function BeCool(num)
    print(".."num"..")
end

And when are parameters used? And what for?

Thanks,

1 answer

Log in to vote
1
Answered by 9 years ago

Hello NAWESOME14, Parameters are a way to pass information(Player created info like numbers, letters, etc) from global variables into a function or from a function to another function (not sure if applies to LUA.). For example:

Lets say I want to make a calculator that just adds numbers together. I would have something like this:

function calculator(playerNum1, playerNum2)
    local results = playerNum1 + playerNum2
    print(results)
end
calculator(3,4)

When you call the function calculator() you put the information you want to use in the script. In our example, we need to put numbers. Of course, you can make the code a little dynamic so it can receive the players own numbers and then calculate it that way inside the function by removing (3,4) and maybe setting it to a variable that receives user input data.

You use parameters when the script requires certain information in order to run the code inside the function. You use parameters mostly all the time, like Cframe, Vector3, etc. Those require information to be passed through them using parameters in order to position or orientate the object, brick or whatever you are trying to accomplish in your script. I hope this helped. Kind Regards, Mawesome4ever

Ad

Answer this question