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 Studio Chat / can i set a array in a function with every dimension ?

Author
Message
stigmat
5
Years of Service
User Offline
Joined: 1st Apr 2019
Location:
Posted: 17th Sep 2021 09:22
Hi all, when i make a function with a array in option i do this function myfunction (array[]) ,if i want the same but with 2 timension array i do function myfunction (array[][]) , cant i do a function where the option can be any dimension array ?
thank for your help
hosch
Developer
2
Years of Service
User Offline
Joined: 25th May 2021
Location:
Posted: 17th Sep 2021 11:29
According to the help docs up to 6 dimensions are allowed as arguments to functions.

Arrays are somewhat static, because you reserve the memory, even though the offer great flexibility in AGK. In most cases you might not know the amount of data it holds, but the dimensions should be clear. You define the use case for the array, therefore the dimensions should be defined by you beforehand.

What you could try to do (might not work, untested): pass a dimension ID with the function and set up the array based on that.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 17th Sep 2021 12:39 Edited at: 17th Sep 2021 16:13
The short answer is no.

You are passing an array into a function so AppGameKit needs the correct parameter passing. What you are asking for is called function overloading which, sadly, AppGameKit does not support.

On a related note: since you are passing an array into a function, you might want to use the REF keyword. Passing an array is a costly move especially for a big array because the entire contents of the array need to be copied into a local variable for the function to use. If instead, you use the REF keyword then you are only passing a reference to the array which is much, much faster.

Check the Passing by Reference section of the help file.
stigmat
5
Years of Service
User Offline
Joined: 1st Apr 2019
Location:
Posted: 17th Sep 2021 18:29
Thank i understand, this is the diference with php and javascript, i can make a function like function myfunction ($array) and i can use it with every dimention
TamBam
12
Years of Service
User Offline
Joined: 29th Nov 2011
Location: India
Posted: 18th Sep 2021 02:50
@stigmat App Game Kit design for making games publish and earn money . What we get from AppGameKit is more than enough and comparing with php or java script is not relevant .
Virtual Nomad
Moderator
18
Years of Service
Recently Online
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 18th Sep 2021 02:56 Edited at: 18th Sep 2021 03:00
tambam wrote: "comparing with php or java script is not relevant"

of course it is. stigmat is asking a Q about functions in AppGameKit and comparing it to functions in other languages that they know.
why is that irrelevant?
[My Itch.io Home] [AGK on Itch.io]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 18th Sep 2021 23:07
@stigmat, Yes it would be nice to just pass in an array and index its values like in PHP, this is a very versatile system, AppGameKit is not so versatile but this is not a bad thing its actually what I would expect from a language, C++ for example would need templates to achieve but still has restrictions and C is type or struct pointer only, in my experience only non compiled scripting languages (PHP, Lua, JavaScript etc) have non static variable types.

irrelevant?

The only irrelevant question is the one that never got asked!

I think what TamBam is trying to say is "its not exactly fair to AppGameKit to compare it to PHP or JavaScript" which is of course is true as they are very different products that do very different things and the latter have had decades of development time by huge teams of people, AppGameKit has not ... that being said, all coding comparison questions have to be asked as all languages differ and well, this is TGC forum, all questions are welcome*

(*as long as they conform to the forum TOS.)

Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
TamBam
12
Years of Service
User Offline
Joined: 29th Nov 2011
Location: India
Posted: 19th Sep 2021 04:48 Edited at: 19th Sep 2021 04:49
@Virtual Nomad " PHP and JavaScript " mainly develop for website design (Backend, frontend ) and AppGameKit mainly for gaming . So no compare comes . But yes you can Ask question Like " Is their any function in AppGameKit same as ECHO in PHP " so we can answer ( yes you can use 'Print' will work same as ECHO ) .
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th Sep 2021 05:36 Edited at: 19th Sep 2021 05:36
if you didn't do it very often you could probably do it with a JSON string.
Doing it every frame would be very very slow
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 19th Sep 2021 13:32
I did think of that myself but it presents more issues than it solves, to process the json we need a type to match the structure, if we have the type might as well just send a ref pointer to a type and be done with the faffing about, unless the data is coming from PHP or network then of course json is a must IMO

if your function is taking 6 or more arguments you probably have a bad code structure, in some cases you absolutely need all elements of a data structure inside the function make a type for that function call, a type with 25 elements is now passed to a function as a single variable.

only other way is send in a delimited string and parse that, but as with json its going to be a slow process and not recommended in a loop, its easy enough to parse a json string in the same way alleviating the need for a matching type but is it really worth the negative speed impact when we can just use the tools AppGameKit gives us and use a temp type and a REF pointer, same functionally, less overhead ...
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Sep 2021 00:05
I think using json would be far too inefficient for passing an array of data given all the string parsing that would be required.

If you're unsure of the dimensions your array will have (but your function knows how to process such a structure), you could develop your own type of array structure with memblocks. Not exactly a simple task but not the hardest thing I've seen done in agk.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-04-20 01:01:23
Your offset time is: 2024-04-20 01:01:23