I don't understand what they are for? and I don't understand how to use them.
The tutorial I'm using is so unbelievably cryptic I'm about to bust a nut. I'll copy/paste the part I need help understanding:
Having read this, I'm still not an inche closer to understand the purpose/use of take/return.
For example
Now from what I understand, this function's under purpose is to return 5 to an integer, there by increasing the value of that integer. However what integer are we talking about? assuming what I'm thinking is correct
As for the take part I don't even have a clue, not even remotely what his talking about.
Any and all clearification would be nice
The tutorial I'm using is so unbelievably cryptic I'm about to bust a nut. I'll copy/paste the part I need help understanding:
Lesson 3: Functions
Overview
In this lesson, I will be going over how to:
1.Create functions
2.Call functions
3.Anything else I can think of
Part 1: Creating a function
Now, you're probably wanting to know how to create functions, right? Well, to create functions, you first need to tell the program that you're creating a function, so you do that by delcaring a function. This is basically telling the program the function's name, what values it needs to get when called, and what it returns. Take a look at this function:
JASS:function DisplayAMessage takes string message returns nothing call BJDebugMsg(message) endfunction
Now, the word 'function' tells the program that you will be declaring a function. The next part of the function is the name of the function. You need to make sure your function has a unique name that no other function has, otherwise you'll get errors when saving a map. Next, you tell the program what the function 'takes' or needs pretty much. This function 'takes' a string, which is basically a message of some sort. After you put the type the function needs, you then have to put a name for it (so you can refer to it inside of your function). Lastly, you tell the program the type the function will return. You could make this a string, integer, real, and so on. However for this example, no value will be returned so we put 'nothing'.
After declaring a function, inside the function you need to put what the function does, otherwise it would be pretty useless. This function simply calls another function using the string value that is needed to call it. Lastly, you need to tell the program when the function ends, you do this by putting 'endfunction' at the end of the function.
Part 2: Calling functions
Now, that may not all make sense, so I'll now explain how you call functions, which should hopefully clear things up a bit. First off, you can call a function in a few different ways, but I'll start by the easiest way, which is using the word 'call'.
JASS:call DisplayAMessage("hello")
This line would call the function I just showed you. When calling a function this way, you need to have the word 'call' followed by the function name which is then followed by parenthesis with the values the function takes inside of them. If a function takes multiple values, they are each separated by a comma ','. It works that same way when declaring functions too (whoops forgot to mention that earlier =P)
Now, I will go over what the return values in functions are. They're pretty simple really, though I don't want anyone to be confused about anything. When a function has a return value, you can set variables that are the same type as the return value to that function. Here's an example:
JASS:local string player_name = GetPlayerName(Player(0))
Now, see that when you set a variable to the return value of a function, you don't need the word 'call'. Also, if you want to pass the return value of a function into another function call, you don't need to put the word 'call' either, as seen with the Player function that was the needed parameter in the GetPlayerName function.
If when and when not to use call are confusing you, let me just say you can only have 1 call in a line, and call can't be used if you have another word before that such as 'set' or you're declaring a local variable.
Also, and this is important when declaring a function, if the function declaration states that the function returns a value, somewhere in the function if must have a line that 'returns' the value, like so:
JASS:function TestReturn takes nothing returns integer return 5 endfunction
When a function reaches the line with return on it, it returns the specified value and ends (no code below that line is looked at by Wc3)
There is one last thing you need to know when calling functions, you can only call a function that is above another, since that may not make complete sense, here's an example:
JASS:function SomeFunction takes nothing returns nothing endfunction function SomeOtherFunction takes nothing returns nothing endfunction
Now, this is only used as a visual example so I can more easily describe what I was saying. You can only call a function that is above the function you are currently in. So, 'SomeOtherFunction' would be able to call 'SomeFunction'. However, 'SomeFunction' wouldn't be able to call 'SomeOtherFunction'.
Challenge Time!
Now, I figure you're wondering why the challenges so far aren't very hard (I'm just assuming that), and that's because we haven't taught you enough for us to really stump you on something. I hope this challenge will make you think more than normal. The following code has a few errors in it, find each error in it. There are 5 errors in the following code, can you find them all?
JASS:function Function2 takes nothing returns string local string message = SomeFunction("Hello World") endfunction function SomeFunction takes string returns nothing local string a message a message = 'Something is wrong' call DisplayTextToPlayer(Player(0), 0, 0, a message) endfunction
Good Luck -wyrmlord
Having read this, I'm still not an inche closer to understand the purpose/use of take/return.
For example
JASS:
function TestReturn takes nothing returns integer
return 5
endfunction
Now from what I understand, this function's under purpose is to return 5 to an integer, there by increasing the value of that integer. However what integer are we talking about? assuming what I'm thinking is correct
As for the take part I don't even have a clue, not even remotely what his talking about.
Any and all clearification would be nice