Functions: how and why?

Phubar

Ultra Cool Member
Reaction score
30
Hi, i want to figure out what are functions made for and how them work in general line.
I made a new function and it looks like a trigger with variables and a list of actions (though there are no event and conditons)
Can you explain very fast hte core parts of the function window?
Tnx fort the help!
 

Dave312

Censored for your safe viewing
Reaction score
269
Functions are used to make your triggers simpler, neater and easier to read. They take parameters (information you give the function which it uses to work out what it does) and gives you a result. A function must always return a result.

A simple example of an inbuilt function is Random Integer. This function returns a random number between two values. When you use this function it will ask for two values, Min and Max. These are Parameters which the function uses to calculate the random number.

When creating a custom function, the two main points to look out for are:
Return Type - this is the data type that the function returns. In the example above it returns an Integer.
Parameters - This is a list of things the function asks for in order to calculate its result.

Hope that helps.
 

Phubar

Ultra Cool Member
Reaction score
30
So i can say that a function is like a trigger action? I mean i make my own and use it like an action?
 

Dave312

Censored for your safe viewing
Reaction score
269
They are practically the same thing. You can actually create your own trigger Actions as well. The only difference between Actions and Functions is that functions have to return a value.
 

Siretu

Starcraft 2 Editor Moderator
Reaction score
293
Let me use an example of one of my most used custom functions. I have a custom function that I made which is called "Get Player Team". I didn't find a way to get the player's team easily so I made a function.

In the parameter field, I added an integer variable called player. This is the thing you send with it when you use the function.

In the actions, I checked if the player was in the player group: "Players on team 1", if so, I use the action "Return" to return 1. I then do the same thing with the other teams.

Now if I use Get Player Team(*my player*) it will return the team of the player.
 

Phubar

Ultra Cool Member
Reaction score
30
I tried to make your function on my own but i can't understand the "return" command what does. Ok it assign the value to the output but how i can assign that value to a global variable in the real trigger?
 

Phubar

Ultra Cool Member
Reaction score
30
I'm very very sorry... I found the answer just after i posted the question... playing with the new toy i made a new action not a new function... :D
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top