Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / FUNCTION question - passing variable limit?

Author
Message
mindsclay
12
Years of Service
User Offline
Joined: 1st May 2012
Location: Rocklin, CA, USA
Posted: 2nd Oct 2013 23:26 Edited at: 2nd Oct 2013 23:28
Has anyone come across there being a limit as to how many variables can be passed to a function?

I was experiencing a crash until I removed two of the variables from the functions input. They are being used outside of the function now, thus the values contained within them weren't the culprit.

I tried using the exact same code in the main loop without using a function, same variables and all. That worked like a charm, but as soon as I use the code in a function it causes a crash, unless I reduce the variables being passed to the function.

www.mindsclay.com
lucifermagus.mindsclay.com (not working with Firefox)
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 2nd Oct 2013 23:28
Yes, in Tier 1 there is a limit of 9 parameters that can be passed in a function.

And, no, they don't plan on changing that, it has been asked and it is not easy to do at all.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 2nd Oct 2013 23:37
You can pass UDTs to functions. Like create a type called color and have variables for RGB. Now you can pass 3 values as 1!

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 3rd Oct 2013 00:15
As DA says. I hit this problem recently. So I made

MyFunc(x as float, y as float, z as float ...

into

type tVector3
x as float
y as float
z as float
endtype

global pos as tVector 3
...

pos.x = 10
pos.y = 1.0
pos.z = 1.0

..

MyFunc(pos as tVector3 ...


mindsclay
12
Years of Service
User Offline
Joined: 1st May 2012
Location: Rocklin, CA, USA
Posted: 3rd Oct 2013 03:50
Or an array.

I was merely wondering if there was a limit as a sanity check.

Thanks.

www.mindsclay.com
lucifermagus.mindsclay.com (not working with Firefox)
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 3rd Oct 2013 05:05
As far as I know you CANNOT pass arrays into functions in AppGameKit Basic as there is no way to indicate that it is one in the function declaration.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 3rd Oct 2013 11:09
I think Mindsclay is talking more about passing an array index to the function, then affecting the array directly inside the function, rather than passing a dynamic array. That's something that we'll never see in native AppGameKit - it's just too complicated for interpreted systems.

I tend to make some typed arrays for position, colour, that sort of thing, it makes code much more readable I find.

I am the one who knocks...
mindsclay
12
Years of Service
User Offline
Joined: 1st May 2012
Location: Rocklin, CA, USA
Posted: 3rd Oct 2013 23:04 Edited at: 3rd Oct 2013 23:08
I meant an array out of a function. I used this when I couldn't use UDTs.

But since arrays are global anyway, no need, eh?

By the way, using UDTs is working awesomely. The number of variables I send to a function has dramatically decreased.

www.mindsclay.com
lucifermagus.mindsclay.com (not working with Firefox)
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 4th Oct 2013 00:27
@VanB
Quote: "That's something that we'll never see in native AppGameKit - it's just too complicated for interpreted systems."

Let's have a little look at the 2nd Stretch goal of AppGameKit v2. *Puts on glasses* Passing arrays into functions. Admittedly, much easier said than done. One day I hope it'll be implemented. Also, the "too complicated for interpreted systems" bit, is that a generalisation or in regards to AGK's interpreter? Java seems to handle it quite well.

Quote: "But since arrays are global anyway, no need, eh?"

I wouldn't say that. One of the major reasons I moved from BASIC to C++ was because C++ supports pointers. Imagine if you had 20 integer arrays, each for different purposes and you had to repeatedly sort them as new data came in. In C++, you would write the one sort function and simply pass the arrays into it, in BASIC you'd have to have 20 separate sort functions, one for each array. If there's another way, let me know because I haven't found it. But if you're happy to write specific functions then yep, global arrays should be all you need.

Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 4th Oct 2013 11:22
Maybe it's more that it's a luxury feature and we tend not to see it in game centric languages. I mean, there would be extra housekeeping no matter how it's done. Say I made a function to sort an array that is passed to it... I would have to check the number of indices in the array, I'd have to know the type setup that it uses, and multi-dimensional arrays would be even trickier. I don't think that passing arrays to functions is all that useful in game programming, we aren't writing engines, we are all kinda used to our functions being quite specific when dealing with arrays.

I think it gets to a point of diminishing returns pretty quickly with that, because we don't usually have arrays that would 'fit the bill' - like a straightforward 1D string array, say, a list of files to be loaded... Well my arrays tend never be that straightforward at least. If I needed to do that, I'd use a specific array directly, I wouldn't write a function to do all the extra house-keeping so it can use any array passed to it, then only ever pass 1 array to it!

I don't have any specific knowledge about the way AppGameKit works, but the evidence is right there... no TGC language has had this feature before. I guess what I'm really suggesting is, do we really need that feature, considering how practical it is or isn't for game programming?

I am the one who knocks...
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 4th Oct 2013 12:43
Quote: "I don't think that passing arrays to functions is all that useful in game programming, we aren't writing engines, we are all kinda used to our functions being quite specific when dealing with arrays."

That's a fair point. I guess my personal style is to try to write functions to be able to handle an appropriate range of input and not the specific data I had in mind at the time of writing because I don't know what else I'll use it for. I'm a fairly young programmer so I like to cast a wide net and keep my options open.

Quote: "If I needed to do that, I'd use a specific array directly, I wouldn't write a function to do all the extra house-keeping so it can use any array passed to it, then only ever pass 1 array to it!"

I'm the kind of programmer who would write the extra house keeping for it. Might use that function for another project which just might happen to have more than one array of strings. Maybe I'm just thinking too far ahead.

Quote: "I guess what I'm really suggesting is, do we really need that feature, considering how practical it is or isn't for game programming?"

If they can add it in without breaking anything and without spending too much time on it then it may come in handy one day. Kind of like being able to operator overload the comma in C++. I can't think of too many uses for that but it's there if you ever need it.

Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 4th Oct 2013 19:45
I definitely want to be able to pass arrays to functions. That and dynamic arrays/lists like in DBP. Those, render to image and improvements to the IDE and bugfixes are all I wish for right now. Oh, and full Ouya support.

Login to post a reply

Server time is: 2024-11-24 19:53:33
Your offset time is: 2024-11-24 19:53:33