You can't. In fact in most programming languages you can't return more than 1 value. Before patch 9 of beta you could have used pointers to pass variables by reference and modify them, but they were removed by unknown reasons. (Still haven't tested if release sets them back).
You will have to work around using global variables or some way to pass those values back.
so why do functions offer arrays as return values ?
edit: btw, most modern languages in fact allow returning arrays. Only low level languages like c don't allow this, but you can get around that by using structs (and i'm pretty sure you can directly return structs in c, not just pointers)
so why do functions offer arrays as return values ?
edit: btw, most modern languages in fact allow returning arrays. Only low level languages like c don't allow this, but you can get around that by using structs (and i'm pretty sure you can directly return structs in c, not just pointers)
First C isn't a low level programming language, it's a high level programming language. LLPL are x86, MIPS, PowerPC, ARM, etc arquitectures and they work quite different than galaxy, C or JAVA.
second, an array is actually a hidden pointer(in the case of galaxy and C). It's the pointer to the start direction of the memory assigned to that array. In JAVA, it is an object (a reference to a struct). In other words the function is only returning the direction.
third, indeed you can return structs in C, this could be the 'exception' as it uses the computer's STACK to do so, which is less efficient than returning the pointer to that struct. However, we are talking of Galaxy, not of C. In galaxy, you can't return structs only native types and arrays, so that's it. Oh and as I said before, you can't return more than 1 value.
Well, c might technically be a high level language since it needs a compiler, but it's still very close to low level languages and that's pretty obvious when you look at it's syntax, and also arrays are not pointers. Arrays are only pointers when the language defines them to be pointers - as c does. The concept of an array does not require nor imply the use of pointers. In most modern languages arrays are not pointers at all and thus can be handled like any other object.
but on topic: I was referring to the UI of galaxy which OFFERS return values as arrays. That's what confused me.
Well, c might technically be a high level language since it needs a compiler, but it's still very close to low level languages and that's pretty obvious when you look at it's syntax, and also arrays are not pointers. Arrays are only pointers when the language defines them to be pointers - as c does. The concept of an array does not require nor imply the use of pointers. In most modern languages arrays are not pointers at all and thus can be handled like any other object.
but on topic: I was referring to the UI of galaxy which OFFERS return values as arrays. That's what confused me.
I was talking of the implementation of an array, not of it's concept. Oh and trust me C isn't THAT close, it's actually quite far but it's one of the closests compared to other HLPL. I'm a software engineer, I know of what I'm talking about ;).
On topic:
Anyways, I tested what you just said and you can't return arrays either way, even if the GUI allows you. There's no way you can return the array itself. So at the end, galaxy only allows native types.
Okay functions can return arrays apparently, but return always only gives me the possibility to return 1 single value. How can I return 2 values ?
@pixartist: Go help :(
You can't. In fact in most programming languages you can't return more than 1 value. Before patch 9 of beta you could have used pointers to pass variables by reference and modify them, but they were removed by unknown reasons. (Still haven't tested if release sets them back).
You will have to work around using global variables or some way to pass those values back.
@BlinkHawk: Go
so why do functions offer arrays as return values ?
edit: btw, most modern languages in fact allow returning arrays. Only low level languages like c don't allow this, but you can get around that by using structs (and i'm pretty sure you can directly return structs in c, not just pointers)
First C isn't a low level programming language, it's a high level programming language. LLPL are x86, MIPS, PowerPC, ARM, etc arquitectures and they work quite different than galaxy, C or JAVA.
second, an array is actually a hidden pointer(in the case of galaxy and C). It's the pointer to the start direction of the memory assigned to that array. In JAVA, it is an object (a reference to a struct). In other words the function is only returning the direction.
third, indeed you can return structs in C, this could be the 'exception' as it uses the computer's STACK to do so, which is less efficient than returning the pointer to that struct. However, we are talking of Galaxy, not of C. In galaxy, you can't return structs only native types and arrays, so that's it. Oh and as I said before, you can't return more than 1 value.
@BlinkHawk: Go
Well, c might technically be a high level language since it needs a compiler, but it's still very close to low level languages and that's pretty obvious when you look at it's syntax, and also arrays are not pointers. Arrays are only pointers when the language defines them to be pointers - as c does. The concept of an array does not require nor imply the use of pointers. In most modern languages arrays are not pointers at all and thus can be handled like any other object.
but on topic: I was referring to the UI of galaxy which OFFERS return values as arrays. That's what confused me.
I was talking of the implementation of an array, not of it's concept. Oh and trust me C isn't THAT close, it's actually quite far but it's one of the closests compared to other HLPL. I'm a software engineer, I know of what I'm talking about ;).
On topic: Anyways, I tested what you just said and you can't return arrays either way, even if the GUI allows you. There's no way you can return the array itself. So at the end, galaxy only allows native types.
@BlinkHawk: Go
yeah, you just confirmed what I said, you CAN'T, even though the UI implies it ;)
Simple answer: The UI is wrong. Maybe it's a leftover from when it was possible by returning pointers.