Example for good use of parameters

Xilefenko
05 Dec 2016, 12:17I just started using functions and it kinda bugs me that there is a Parameter function which I have no idea how to properly use or what it's really for. Could someone give a good example of a function with Parameters? Thanks
The Pixie
05 Dec 2016, 13:03The GetBoolean
function takes two parameters, an object and a string. These are values that you can send to the function when you want to use it. Say you have an object called hat
, and an attribute that flags if it is worn, "worn", you could use the function like this:
flag = GetBoolean(hat, "worn")
Using parameters means you can use the same function with another attribute of a different object.
There is a Wiki article on parameters; the way Quest handles them is typical of most programming languages.
https://en.wikipedia.org/wiki/Parameter_(computer_programming)
hegemonkhan
06 Dec 2016, 00:54think 'input/output' functions, like in/for math.
Parameters/Arguments ARE your inputs, which will be used by your Function's scripting:
simpliest example of Arguments/Parameters:
<function name="adder_function" parameters="integer_number_parameter_1,integer_number_parameter_2" type="int">
return (integer_number_parameter_1 + integer_number_parameter_2)
</function>
// scripting example:
game.sum_integer_attribute = adder_function (2,7) // the '(2,7)' are the Arguments, they match up with the Parameters
// game.sum_integer_attribute = 2 + 7 = 9
game.sum_integer_attribute = adder_function (14,8) // the '(14,8)' are the Arguments, they match up with the Parameters
// game.sum_integer_attribute = 14 + 8 = 22
game.int_num_1 = 14
game.int_num_2 = 8
game.sum_integer_attribute = adder_function (game.int_num_1,game.int_num_2) // the '(game.int_num_1,game.int_num_2)' are the Arguments, they match up with the Parameters
// game.sum_integer_attribute = 14 + 8 = 22
// -----------------
here's another simple example:
<function name="my_msg_function" parameters="message_string_parameter" type="string">
return (message_string_parameter)
</function>
// scripting example:
game.message_string = my_msg_function ("hi")
// game.message_string = "hi"
game.msg_string = "hi"
game.message_string = my_msg_function (game.msg_string)
// game.message_string = "hi"

Xilefenko
06 Dec 2016, 15:20Ok thanks
hegemonkhan
07 Dec 2016, 05:31the Arguments match up with the Parameters in terms of position:
example_function (argument_position_1,argument_position_2,etc)
<function name="example_function" parameters="parameter_position_1,parameter_position_2,etc">
msg (parameter_position_1)
msg (parameter_position_2)
</function>
// ----------------------
a conceptual example:
string_variable_1 = "hi"
string_variable_2 = "bye"
example_function (string_variable_1,string_variable_2)
parameter_position_1 <=== (argument_position_1) string_variable_1 <=== "hi"
parameter_position_2 <=== (argument_position_2) string_variable_2 <=== "bye"
<function name="example_function" parameters="parameter_position_1,parameter_position_2,etc">
msg (parameter_position_1) // msg (parameter_position_1 = argument_position_1/string_variable_1 = "hi") // msg (parameter_position_1 = "hi") // msg ("hi")
msg (parameter_position_2) // msg (parameter_position_2 = argument_position_2/string_variable_2 = "bye") // msg (parameter_position_2 = "bye") // msg ("bye")
</function>
you can name your parameters whatever you want, changing the name or keeping it the same. As, you can use the Parameters from a Function for the Arguments in a function call to another Function, keeping the other/next/new/2nd Function's Parameters the same name as the first Function's Parameters' names, or changing them to be named differently. It doesn't matter.
Parameters/Arguments are a way to use inputs within/for a Function's scripting, including transfering those inputs from Function to Function.
The Argument is the input, either a direct/literal value or as a VARIABLE, and the matching Parameter is just a Variable for that input (the input/argument is stored/saved into the parameter), which you can then use that Parameter (a Variable) within/for your Function's scripting.

Xilefenko
07 Dec 2016, 08:53I think I understood it. I will play a little bit with it until I fully understand it! Thanks