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.

Newcomers AppGameKit Corner / Arrays VS Type?

Author
Message
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 1st Apr 2016 10:15
Is there any advantages/disadvantages of using arrays over user-defined type?

Any performance difference?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 1st Apr 2016 12:23
They perform different uses.

A type is for keeping related information together. For example, all the characteristics of a monster (energy, attack power, defence ability, speed etc)
An array is for keeping collections of entities with the same attributes. For example, a series of integer numbers or an army of monsters.

By putting types into arrays, you have an easy way to keep collections of well-defined entities.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 1st Apr 2016 13:32
How do I put types into arrays?

Can DBPro put types into arrays too?

Can't we just make an array with 2 dimensions for example, the first dimension being monster numbers, and the seconds dimension being the attributes?
DIM MonsterAttribute[100,4]
MonsterAttribute[1,1] = attack power
MonsterAttribute[1,2] = defence
MonsterAttribute[1,3] = energy
MonsterAttribute[1,4] = speed

So far I've preferred to use arrays instead of type, because it can be saved and all.

What would the advantage of types be, other than it's convenient naming?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 1st Apr 2016 16:19
A simple example...what if you want to store a name (string), health (integer) and speed (float) for 100 bad guys?

Take a look at this tutorial that I wrote for DBPro in...April 2005! The principle is identical.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 1st Apr 2016 17:22 Edited at: 1st Apr 2016 17:31
Thanks for the turorial.

I see, we can have different types of values easily by using types.

So far, I've only made several arrays for different types of values...


Is there an easy way to 'store' the values in types, for example, for saving you game, and loading it back later? (Without saving it to an array or datafile)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 1st Apr 2016 20:06
I don't think this is possible. You need to write your own serialisation routine to save it out and read it back in again.


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt

Login to post a reply

Server time is: 2024-11-24 11:20:30
Your offset time is: 2024-11-24 11:20:30