What does the return do in a function?

D.V.D

Make a wish
Reaction score
73
Maybe the title isn't so good but the question is: When you have a function that takers lets say real. What does the return do? Do you return the struct you used for the variables? Also, what are methods and what are static methods? I think that they are the action/condition/event you are creating but what's the difference?
 

Xorifelse

I'd love to elaborate about discussions...........
Reaction score
87
Code:
function sum takes integer [COLOR="SeaGreen"]a[/COLOR], integer [COLOR="SeaGreen"]b[/COLOR] returns [COLOR="Red"]integer[/COLOR]
    return a + b
endfunction

function someFunc takes noting returns nothing
    local [COLOR="Red"]integer[/COLOR] i = sum( [COLOR="SeaGreen"]4[/COLOR], [COLOR="SeaGreen"]5[/COLOR] ) // i holds the value 9.
endfunction

In vJass, a static is a normal global, or a non object orientated function.
Methods are object orientated functions, it parses an extra integer with it called "this", which holds the current struct ID.
But I suggest learning some proper Jass before you switch over to vJass, get a hold of the syntax then someday use structs.
I hope that explains it..
 

D.V.D

Make a wish
Reaction score
73
Explained a bit. I still don't get what exactly does the return mean? So what you return a integer, what does it do if it does?
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Explained a bit. I still don't get what exactly does the return mean? So what you return a integer, what does it do if it does?

It stops the function completely, and 'returns' the value to the function that called it, so that function can then use the returned value. For example, you can set a variable to the function like this:

JASS:
function GimmeUnit takes argument <name>, argument <name>, argument <name> returns unit
    return udg_ThatOneGuy
endfunction

local unit u = GimmeUnit(argument,argument,argument)


or you can simply call the function, like this:

JASS:
call GimmeUnit(argument,argument,argument)


The declaration line,

JASS:
function NAME takes ARG name, ARG name, ARG name returns VARIABLE TYPE


Specifies how the function can be used: The function's name, How many arguments it has passed to it when it is called, the type and names of those arguments (to be used inside the function), and a variable type that the function will return.

if a function "returns nothing" that means that the function can only be called, not used. For these types of functions, you can use the "return" line to "Skip Remaining Actions"

JASS:
call DoStuff()
 

Ryuu

I am back with Chocolate (:
Reaction score
64
Basically, a return is a return.
What am I talking about, let me show you an example.

Let's say you made a function called Something.

JASS:
function Something takes string s returns integer
    return 12
endfunction


Once you had this function, the following function:

JASS:
set Integer = Something("abcd")


becomes

JASS:
set Integer = 12


Because that function returns '12'.
 

GooS

Azrael
Reaction score
154
The function called (The returning function) stops and the function in which it has been called has a variable based on the conditions and/actions made in the returning function.
(Explained above me)

I'm a newb in jass so i don't really know what it's usefull for beyond the intitial condition in a trigger:

JASS:
call TriggerAddCondition( gg_trg_IRFunc, Condition( function Trig_IRCond ) )

As the only time I go beyond the initial action function is when I use callbacks such as timers.
 

cr4xzZz

Also known as azwraith_ftL.
Reaction score
51
Basically, to sum it up, the return part makes the function return a value - be it integer, boolean, real, whatever. The value can be accessed later if you saved it in a variable (as the examples above show).
 

SerraAvenger

Cuz I can
Reaction score
234
Code:
function sum takes integer [COLOR="SeaGreen"]a[/COLOR], integer [COLOR="SeaGreen"]b[/COLOR] returns [COLOR="Red"]integer[/COLOR]
    return a + b
endfunction

function someFunc takes noting returns nothing
    local [COLOR="Red"]integer[/COLOR] i = sum( [COLOR="SeaGreen"]4[/COLOR], [COLOR="SeaGreen"]5[/COLOR] ) // i holds the value 9.
endfunction

In vJass, a static is a normal global, or a non object orientated function.
Methods are object orientated functions, it parses an extra integer with it called "this", which holds the current struct ID.
But I suggest learning some proper Jass before you switch over to vJass, get a hold of the syntax then someday use structs.
I hope that explains it..

Well... I wouldn't say it is not OOP.
A static method in vJASS, to be precise, is a method that takes no struct object as parameter. It just takes the class.

For example:
JASS:
struct A
  static method test takes nothing returns integer
    return 0
  endmethod
endstruct

struct B
  static method test takes nothing returns integer
    return .allocate() // This is a static method, so it can use private methods and variables. allocate is a static method too, hence you don't need the 'B' infront of it.
  endmethod
endstruct

now
JASS:

local integer testA = A.test() // The 'return' statement makes this method return 0, so testA is 0 now
local B testB = B.test() // testB now holds a newly created instance of the 'B' class.


Return statements jump back to the last address of the Virtual Machine and hand out their value.

In a pseudocode imperative language, you could express it like that:
JASS:

109  // 109 Lines of other code before this...
110  // This is a 'function' that returns the sum of two arguments. As this is not a procedural language, there are no functions actually.
111  RETURN_STATEMENTS := RETURN_STATEMENTS + 1
112  
113  RESULT := ARGUMENT[ 0 ] + ARGUMENT[ 1 ]
114  
115  RETURN_STATEMENTS := RETURN_STATEMENTS - 1
116  GOTO LAST_LINE[ RETURN_STATEMENTS ]
117
118 // A few lines in between...
.
.
.
573 ARGUMENT[ 0 ] := 1
574 ARGUMENT[ 1 ] := 4
575 LAST_LINE[ RETURN_STATEMENTS ] := 577 // The current line + 2!
576 GOTO 111
577 ? "%d" % RESULT  // Prints 5
 
General chit-chat
Help Users
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top