How would I do this in an array or static const?
#2

First of all, you have to distinguish the terms from each other. They all mean something in particular and can be combined all together:

Static: The static keyword makes your variables only available in the file they get declared in. The values therefore can't be used in any other file and also it avoids name clashing of variables between different files.

Const: The keyword const defines a constant value which can't be changed. From time to time it is useful to make use of constant values for a more compact source code and to avoid logic programming faults.

Array: An array is a set of values and therefore cells. You can combine an array with the const and static keyword to make the values constant and to reduce the array's scope to the file only.


In your case I wouldn't use strings to determine which skins are reserved for which origins as string comparissons are simply more complicated than simple integer comparissons. In case you are in need of the origins' names aswell, simply create a secondary array with them. You may think of database normalisation in this case as the concept behind it is exactly the same.

Instead of setting a range of ages, I would simply set the minimum and maximum of the range and do two comparissons later on.

pawn Код:
#include "a_samp"

static const originData[][] = {
    "African American", // Index: 0
    "Caucasian" // Index: 1
};

static const relations[][] = {
    {0, 16, 25, 1}, // Ethnicity/Origin, Minimum age, Maximum age, Skin
    {0, 26, 35, 22},
    {1, 25, 35, 23}
};

main() {
    // Two characters (1: African American, Age 21; 2: Caucasian, Age 35)
    new data[2][2] = {{0, 21}, {1, 35}};
    for(new i = 0; i < sizeof(data); i++) {
        for(new j = 0; j < sizeof(relations); j++) {
            if(relations[j][0] == data[i][0] && relations[j][1] <= data[i][1] && relations[j][2] >= data[i][1]) {
                printf("SkinID for dataset %i: %i", i, relations[j][3]);
            }
        }
    }
}
Result:

Код:
SkinID for dataset 0: 1
SkinID for dataset 1: 23
Make sure to set a default skin to cover logic gaps in your relation array.
Reply


Messages In This Thread
How would I do this in an array or static const? - by Jack_Leslie - 22.06.2014, 06:31
Re: How would I do this in an array or static const? - by Campbell- - 22.06.2014, 09:44
Re: How would I do this in an array or static const? - by Jack_Leslie - 22.06.2014, 10:39
AW: How would I do this in an array or static const? - by Campbell- - 22.06.2014, 13:05

Forum Jump:


Users browsing this thread: 1 Guest(s)