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 / [Request] new command to get true array length.

Author
Message
Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 26th Apr 2019 12:11
As array .length will return -1 when list is empty and ( amont of elements - 1 ) when there are elements,
I ask TheGameCreators to know if they can simply add a new array method to return the true size in amont of elements.
A method like :



But this method should return the true amount of elements in the array (and not true amount -1)

Regards,
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 26th Apr 2019 12:21 Edited at: 26th Apr 2019 12:25
Just use size = myArray.length+1

then size = 0 is no elements, 1 is one element, 2 is two elements...etc...

Why have a new command just to add 1 when you can do it? The value in myArray.length is well described in the documentation.
Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 26th Apr 2019 12:26
@Bengismo :
Having to add +1 each time can lead to errors (forgetting sometimes the +1).
I think it's really nothing to Tgc to add the requested command.

Regard,
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 26th Apr 2019 12:30 Edited at: 26th Apr 2019 12:31
Having two different commands (.size and .length) only confuses the issue further and so some people would forget which one they used and having both would make knowing whether to add 1 or subtract 1 even further confusing.

Better to read the documentation on arrays and understand it properly then to confuse it further.

Anyway.. ..we will see if they add it.
Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 26th Apr 2019 13:47
@Bengismo : If things were good, .length may return the true size of an array ... Just like C/C++/Java/Python, etc... And use of array should be done from 0 to length-1
Here we have a configusing command, that may lead to bad coding practices ...
The best solution may be to makes .length return the true array size instead of size-1 ... But if TGC Made the current choice ... I cannot force them to change it ...
And having 2 commands is not a confusing thing.. People that wants the exact size of an array uses .size
and current .length lets existing code source being comptatible + peoples that's like this way of handling arrays can continue to use .length and don't care about .size.
Nothing confusing if things are clearly stated.
Zappo
Valued Member
20
Years of Service
User Offline
Joined: 27th Oct 2004
Location: In the post
Posted: 26th Apr 2019 15:19
I understand the confusion, especially compared to other languages, but I do agree with Bengismo.
I think being able to iterate through an array using:
For t=0 to myArray.length
is much easier for most people - especially beginners. If you were to accidentally use your myArray.size instead it would give an "Array index out of bounds" error.

Chart data provided with kind permission from ELSPA
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Apr 2019 16:39
I agree with Zappo .
Green Gandalf of the TGC forums aka Scorpius of the Malevolence:Sword of Ahkranox forums.
Shader developer for Evochron Legacy produced by StarWraith 3D Games.
Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 26th Apr 2019 22:44
Zappor wrote: "is much easier for most people - especially beginners. "

Excepted that when you have 1 element in a dynamic list to handle : For 0 to 0 is a bit ... not adapted and illogic
but many here seems to be adept of -1 = 0 and 0 = 1 or more generic x = x-1... It's fully illogic and give to learn bad coding practices ... but if you prefer that beginner learn bad coding practice to potentially prepare them to other languages when they feel more skilled ... it's not my case, I think it's best for beginner to learn things that are common and that can help them to learn more than only AppGameKit. Even if I like TGC Products.

Regards,
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 27th Apr 2019 12:41
TGC are not going to change the way AppGameKit for loops currently work as it would break all the working code there is out there right now. "For i=0 to 0" runs through the loop once and changing that behaviour now would be a terrible decision.

I use C/C++ and python on a daily basis and a typical for loop accessing an array always involves ending one less than the number of elements in an array. ie...0 to NumberOfElements-1. The array.length variable gives you an easy way to get (Number of elements-1) value so it makes sense and is well documented in AGK's documentation.

Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 27th Apr 2019 20:54
bengismo wrote: "TGC are not going to change the way AppGameKit for loops currently work as it would break all the working code there is out there right now. "For i=0 to 0" runs through the loop once and changing that behaviour now would be a terrible decision. "

That's why I firstly asked for a new command for arrays the .size one

Login to post a reply

Server time is: 2024-11-22 21:59:01
Your offset time is: 2024-11-22 21:59:01