• Hey! Register here to create your account, engage with the community, and talk about what is new!

Function Return Values (Potential Implementation)

Ashli

Server Developer
Developer
Joined
Sep 12, 2020
Messages
112
Reaction score
26
Function parameters have been confirmed by the devs.
The way I imagine they would work is you put a bunch of scoped (Function-Local) variables in the Function chest, and they are set accordingly based on input to the Call Function.



I thought about how Function Return Values could be implemented and had some discussion about it and this is probably the best way of doing it:

Have a tag on the Function block specifying whether the Function is void or returns a value.

If the Function is set to void/no return:
Parameters in the return control block are ignored.
Every Call Function value counts as a parameter.


If the Function is set to return a value:
The first parameter in the Call Function (Which should be a variable) is NOT used as a parameter but rather the set variable.
The mentioned variable is set to whatever is inside the Return block (or 0 if none exists)



The call function menu would say whether the function has a return value or not when scrolling over the function.


Relevant Screenshots:
1616268538758.png

1616268913288.png

Hope this makes sense, there might be a better way to implement return values but this seems like the most sensible and convenient way of doing it.
 

Attachments

  • 1616268715762.png
    1616268715762.png
    32.5 KB · Views: 0
  • 1616268753837.png
    1616268753837.png
    35 KB · Views: 0
D

Deleted member 26

Guest
I have taken this into consideration, there will be some version of this when function parameters are released on beta. It should be important to note, that the first implementation of function is not final in any way. Because this is such a key feature, I want to make sure that this is done well and can easily be expanded on in the future.

With function parameters, there will be a type of parameter that you can choose that acts as a variable "pointer". So, instead of a variable containing the value of a variable it contains the actual reference to the variable which allows you to basically make your own return statements. Spooky!
 

Daandar

New member
Overlord
Joined
Sep 10, 2020
Messages
26
Reaction score
10
barely have any coding knowledge outside of diamondfire, but i'm pretty sure this means that old functions won't break or stop working right?
 
D

Deleted member 26

Guest
barely have any coding knowledge outside of diamondfire, but i'm pretty sure this means that old functions won't break or stop working right?
Of course! All old functions will work.
 
Top Bottom