|
| 25 Nov 2015 05:01 PM |
Right now, I'm learning how to script, I'm sure you've might have seen me around the Scripting forum a few times by now, asking questions, so, here's another one I have:
Currently studying Data Persistence / DataStores. And the part I'm at in the tutorial is... well, the dead beginning, because...
-------------------
local HPacks = {} local sessionData = {} function HPacks:ChangeStat(player, statName, changeValue) sessionData[player][statName] = sessionData[player][statName] + changeValue end local function setupPlayerData(player) sessionData[player] = {Money = 0, Experience = 0} end game.Players.PlayerAdded:connect(setupPlayerData) return HPacks
--------------------
I'm confused what a "return" does. My basic idea is that it... gets the value of whatever is typed after it?
Just reply with what it does, please...
|
|
|
| Report Abuse |
|
|
Ristone3
|
  |
| Joined: 17 Aug 2008 |
| Total Posts: 693 |
|
|
| 25 Nov 2015 05:38 PM |
This might help you
function Thing(message) print(message) return true end
if Thing("Hello") == true then print("It printed successfully!") else print("Something went wrong") end
Output: Hello It printed successfully!
So basically, it's a way to get a message from a function, it basically sends information back. What it sends back can be a bool, a number, a string, a table, or even an object. |
|
|
| Report Abuse |
|
|
|
| 25 Nov 2015 07:30 PM |
Still seems confusing, when you called the function in the conditional statement, "Hello" became the "message"?
-I was about to say something, but I see that the function was called in in the condition... which... Ugh, my head can't take this right now...
Explain... Explain! EXPLAIN! |
|
|
| Report Abuse |
|
|
|
| 30 Nov 2015 09:48 AM |
Buuuuuuuump.
That last post was me at a bad time. Also, Doctor Who reference. |
|
|
| Report Abuse |
|
|
OzzyFin
|
  |
| Joined: 07 Jun 2011 |
| Total Posts: 3600 |
|
|
| 30 Nov 2015 10:02 AM |
if you don't yet understand how functions are used, you shouldn't go to datastores yet
function a(argument) print(argument) end
a("hello") -- calling function a with "hello" being the argument a("hi") -- calling function a with "hi" being the argument a("bye")
this wiki page should explain it quite well http://wiki.roblox.com/index.php/Arguments_and_parameters
I personally still don't understand the difference between terms argument and parameter, because the wiki is kinda mixing them up, however it shouldn't matter.
return is simply explained here: http://wiki.roblox.com/index.php?title=Function#Using_Return
|
|
|
| Report Abuse |
|
|
OzzyFin
|
  |
| Joined: 07 Jun 2011 |
| Total Posts: 3600 |
|
|
| 30 Nov 2015 10:05 AM |
@"I personally still don't understand the difference between terms argument and parameter, because the wiki is kinda mixing them up"
what I mean with this is, in wiki there's a line
function name(argument1, arg2, arg3...) --arguments are only inserted when needed
and another
function PrintStuff(x) --this is a function, and it has one parameter, 'x'. PrintStuff("Hello world.") --"Hello world." is the argument
I've always thought that when calling a function you call it with 'parameters' and a function turns those parameters into 'arguments'
again who cares |
|
|
| Report Abuse |
|
|
|
| 30 Nov 2015 12:19 PM |
| The difference between arguments and parameters is largely semantic; when defining the function, you supply parameters. When calling the function, you supply arguments (which take the place of the parameters). |
|
|
| Report Abuse |
|
|