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 / AGK command equivalent to C++ Vectors ?

Author
Message
Mamute
21
Years of Service
User Offline
Joined: 16th Oct 2002
Location:
Posted: 18th May 2013 20:34
In C++ vectors work as arrays dispite the fact they can group and don't need to be initialised to a specific dimension as arrays do.

In vectors just push the new value into in and it increases one in size.

Is there equivalent to C++ vectors in AppGameKit ?

Thanks !

|MaMUtE|
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 18th May 2013 20:36
In Basic - no. In C++ - yes.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Mamute
21
Years of Service
User Offline
Joined: 16th Oct 2002
Location:
Posted: 18th May 2013 21:31
Also why doesn't AppGameKit as a boolean data type .. ?

Strange the team didn't put it on AGK..

|MaMUtE|
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th May 2013 00:29
Someone explained the data types in another thread not long ago. If I recall correctly, even if a boolean type was added, the system still grabs a 4 byte integer and then has to mask/shift the bits in order to get a 1 or 2 byte data type. Now this happens internally, but is still more work. I'm not sure if a full 4 bytes is still reserved however for just a boolean or not.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 19th May 2013 10:38 Edited at: 19th May 2013 10:45
Quote: "Also why doesn't AppGameKit as [have] a boolean data type .. ?"


In Basic or C++? Since 1999 most C++ compilers already have a bool type with true and false defined. VC++ has BOOL, TRUE and FALSE defined.

This is a bit of a pig's ear, because any non-zero number is interpreted as true, and hence:

if (b==true) is not equivalent to if(b)

Basic follows the C lack of typing, so defining TRUE and FALSE in Basic results in the same danger.

This doesn't happen in Pascal, Modula-2 etc, because true and false have always been defined as enumerated types: type boolean = (false,true) and you cannot simply use a number.

So defining a boolean type in Basic would be ok, if hazardous, but defining it for Pascal or C++ would cause a potential keyword conflict.

Most 32-bit compilers will align data on 4-byte boundaries. Older CPUs are significantly slower fetching non-aligned data. The latest Intel and ARM processors are apparently better at it.

This is why C++ has #pragma pack and Pascal has the packed keyword. The unpacked size of a boolean in Delphi is 1 byte, despite the fact that only 1 bit is required to store the values 0 and 1, so:

var b : array[1..32] of boolean; // uses 32 bytes
z : packed array[1..32] of boolean; //uses 4 bytes

As always, the trade-off is memory versus CPU efficiency.

It becomes even more fun using fuzzy logic, where the "truth" of a statement might (for example) be a value between 0 and 100!

EDIT:

It is fairly easy to extend Pascal to provide a C-style if:



-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 19th May 2013 21:20
What about:


Then you can just code like this in basic:



this.mess = abs(sin(times#))
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 19th May 2013 22:39
Yes, Bax - but as you don't have a strict boolean type, simply defining a few constants doesn't disambiguate it.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 20th May 2013 11:32
I know, I was just suggesting a workaround for anyone 'missing' bools. It's not like there is a major disadvantage not having them. Like most languages there are things we would each like to have / not have from other languages. Bools would be a very handy addition.

As you suggested there are always Tier 2 alternatives. Tier 1 is designed to make it easier to make cross platform development in one simple language but it is far from complete.

Just trying to help, back to my hole.


this.mess = abs(sin(times#))
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 20th May 2013 16:04
I have found that Tier 2 is just as easy for cross platform work. I use exactly the same files for Windows, iOS, Mac and Android.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master

Login to post a reply

Server time is: 2024-05-04 08:54:12
Your offset time is: 2024-05-04 08:54:12