SA-MP Forums Archive
enums - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: enums (/showthread.php?tid=483557)



enums - Roai - 26.12.2013

i'm trying to work with enums but i have problem with those,

PHP код:
enum Pam
{
pamo[256],
};
enum Times
{
lMinute,
lHour,
sName[30],
paranum,
Pam:sParamater[30],
};
new 
Loop[MAX_LOOPS][Times];
Loop[0][sParamater.1] = " "
Quote:

C:\Users\win7\Desktop\samp03x_svr_R1-2_win32\gamemodes\lvdm.pwn(41) : error 010: invalid function or declaration

41:
PHP код:
Loop[0][sParamater.1] = " "
can someone explain to me how to use it right?


Re: enums - Patrick - 26.12.2013

In my understanding you want to reset the string stored inside that variable?

pawn Код:
Loop[0][sParamater.1] = '\0';



Re: enums - Konstantinos - 26.12.2013

Those are invalid:
pawn Код:
Pam:sParamater
and
pawn Код:
[sParamater.1]
You cannot use a 2D inside an enum either so the best solution for it is:
pawn Код:
enum Times
{
    lMinute,
    lHour,
    sName[30],
    paranum
};

new Loop[MAX_LOOPS][Times];
new Loop_sParamater[MAX_LOOPS][30][128]; // 256 is not needed, it'll be fine with lowered value.
   
// somewhere:
Loop_sParamater[0][1] = " ";
In case you want to reset the string as pds2k12 said:
pawn Код:
Loop_sParamater[0][1][0] = EOS;
// EOS or '\0'



AW: enums - Nero_3D - 26.12.2013

The funny thing is you can actually stack enums

Thats actually valid code
pawn Код:
enum enum1 {
    var1,
    var2,
    array1[5]
}

enum enum2 {
    var3,
    var4,
    array2[enum1]
}

new Array[enum2];

main() {
    printf("%d", Array[var3]);
    printf("%d", Array[var4]);
    printf("%d", Array[array2][var1]);
    printf("%d", Array[array2][var2]);
    printf("%d", Array[array2][array1][0]);
}
But well there is no advantage at all with this


Re: enums - Roai - 26.12.2013

thanks a lot


Re: enums - Roai - 29.12.2013

another question - how do i take enum as a paramater?


AW: enums - Nero_3D - 29.12.2013

Since enums can't have two dimensions you have to trick it
We just multiply the last two values
pawn Код:
#define MAX_LOOPS 10

enum Pam
{
    pamo[256],
    firstpam[256]
}

#define idx(%0,%1,%2) (%2 + (%0 * %0:%1))

enum Times
{
    lMinute,
    lHour,
    sName[30],
    paranum,
    sParameter[idx(Pam, 50, Pam: 0)]
}
new Loop[MAX_LOOPS][Times];

main() {
    strcat(Loop[0][sParameter][idx(Pam, 25, pamo)], "Hello World", 256);
    strcat(Loop[0][sParameter][idx(Pam, 20, pamo)], "Hello World 2", 256);

    printf(Loop[0][sParameter][idx(Pam, 20, pamo)]);
    printf(Loop[0][sParameter][idx(Pam, 25, pamo)][4]);
}
Edit: Should be working now, it useses now a macro, should be easier


Re: enums - Roai - 29.12.2013

thanks a lot