Problems with enumerated strings
#1

enum ABC{
a[2],
b[32]
};
new vector[ABC];
main(){
vector="a";
}
While the actual size of vector is 40 cells, and needed is 2 it gives an error about having a too small array.
Can anyone help me with this, as I maybe just make mistakes in the syntax.

Btw, try this out :
#define cout<<%1; print(%1);
Reply
#2

I have this too. I tried storing a player's name in a enum and it returned only as 1 character or 2 from the start.
Reply
#3

Quote:
Originally Posted by Retardedwolf
Посмотреть сообщение
I have this too. I tried storing a player's name in a enum and it returned only as 1 character or 2 from the start.
to answer both of your questions, its:
vector[ONE OF THE ENUMS] = Value;
example:

vector[a] = "12";
Reply
#4

Well, actually the size of vector is 3 cells (0 (a), 1 (b)). This is what would be called a multi-dimensional array you have here. I'm not sure where you got 40 from though. What that code is basically doing is creating a multi-dimensional array, vector has 3 cells, cell 0 contains a, which is an array with 2 cells, and cell 1 is an array with 32 cells, cell 3 contains the null character.

So how you access these arrays within the enumerator is like so:

pawn Код:
main()
{
    vector[a] = "a";
    vector[b] = "Hello World";
}
I hope that was the answer you were looking for.
Reply
#5

Quote:
Originally Posted by DeadAhead
Посмотреть сообщение
to answer both of your questions, its:
vector[ONE OF THE ENUMS] = Value;
example:

vector[a] = "12";
Wow you're so smart about things you can't prove, and are false, that's sad.
Anyway, I just realized that sadly the full array can't be used while being with enumerated and in fact if I use a value like this vector[enum_val] then it's always returning one index, which in such case will always fail.

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
I hope that was the answer you were looking for.
It is the answer, till :
struct_.pwn(14) : error 047: array sizes do not match, or destination array is too small

For now I've done the trick like this, but is it just me or in case like mine, they behave like seperate cells.. and can't be used as arrays, so then I need to make a unsafe call :
pawn Код:
main(){
    memcpy(vector[a],"a text", 0, 4*3, 32);
    memcpy(vector[b],"b text", 0, 4*3, 32);
    print(vector[a]);
    print(vector[b]);
}
Reply
#6

That is strange actually, I've thought before that you were able to use that syntax to assign a string to an enumerated array. Although you could also use format to get around the error, like so:

pawn Код:
format(vector[b],32,"Hello world");
Which is somewhat unsatisfactory.
Reply
#7

Thanks for explanation.

I'd appreciate to see that function, as for now pawn seems to be very limited, especially while working macros, so far :
#define vector.%1. vector[%1]
Is the best I've got and now it requires to have predefinition. (I'm trying to get somewhat a structure of struct, which could be in some way tricked to work with STL - otherwise most of STL is just an dynamic array)
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
I'll try and explain what your code is ACTUALLY doing by giving you equivalent code:

pawn Код:
new vector[34];
#define a 0
#define b 2
Those are the values that "a" and "b" take, vector becomes a big array with you indexing things, however as you've seen already there is some extra checking in the compiler to prevent you assigning to the array directly. What this does mean is that you can actually fit a 34 character string into "vector[a]", it will just overwrite the contents of "vector[b]". I have actually used this trick in the past. Also of interest is the fact that enum items are the only things which you can assign both standard numbers and arrays (strings) to - this is another trick I've used in some unreleased code to make a function which can take either a single id or an array of ids.
Thanks for the explanation ******, I wasn't aware that is how enumeration was handled, now it's making a lot more sense, I should've looked into this before replying with invalid information. Apologies for that RSX.
Reply
#9

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Thanks for the explanation ******, I wasn't aware that is how enumeration was handled, now it's making a lot more sense, I should've looked into this before replying with invalid information. Apologies for that RSX.
Then I can just give additional note, that you can use for example :
vector[b][23] which is then actually vector[b+23] which in my opinion as in C then becomes *(vector+b+23) And this function is too pretty useful I guess, as you could make something like this :

pawn Код:
enum _:Coords{
    Float:pX, Float:pY, Float:pZ, Float:rX, Float:rY, Float:rZ
};
enum _:ABC{
    PosRot[Coords],
    a[32],
    b[32]
};

main(){
    new Complex[ABC];
    Complex[PosRot][pY]=10.0;
}
Reply
#10

Would it be value[x][1] to access b?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)