Problem with orm_addvar_string
#1

pawn Код:
new nFriend[MAX_PLAYERS][MAX_FRIENDS][MAX_PLAYER_NAME];
new String[24];
for(new Friend = 1; Friend < MAX_FRIENDS;)
{        
    format(String, sizeof(String), "Friend%d", Friend);
    orm_addvar_string(ormid, nFriend[playerid][Friend], MAX_PLAYER_NAME, String);
    Friend++;
}
Currently changing a few things in my systems, but for some reason the orm_addvar_string gives off an error, any idea why?

pawn Код:
(5370) : error 035: argument type mismatch (argument 2)
Could it be becuase of the dimensions of nFriend?

All the best,
Eirik
Reply
#2

Quote:
Originally Posted by Knappen
Посмотреть сообщение
Could it be becuase of the dimensions of nFriend?
yes

see,

you create it like this
new nFriend[MAX_PLAYERS][MAX_FRIENDS][MAX_PLAYER_NAME]

but you use it like this
nFriend[playerid][Friend]

the MAX_PLAYER_NAME dimension thingy is missing
Reply
#3

That's how you usually use a string though, so I don't believe that is the answer.

pawn Код:
new String[10];

String = "Hello!";
pawn Код:
new Name[MAX_PLAYERS][MAX_PLAYER_NAME];
GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
Say that I want to add a string into a specific playerid, and Friend ID 141, I'd do it like this.
pawn Код:
// playerid = 5, Friend ID = 141
nFriend[5][141] = "Knappen";
I wouldn't do like you are suggesting, because then you would have an array out of bounds, I believe.
pawn Код:
nFriend[5][141][24] = "Knappen";
Reply
#4

Try to cheat the compiler a little:
pawn Код:
orm_addvar_string(ormid, nFriend[playerid][Friend][0], MAX_PLAYER_NAME, String);
But please test if the orm loads/saves the string correctly (I hope that it will simply read MAX_PLAYER_NAME cells starting from index 0)
Reply
#5

It compiles fine at least. I'll get back to you as soon as I have tested it. Thank you.

Edit:
That seems to work just fine. Thanks a lot. Any particular reason it doesn't work like normal?
Reply
#6

Only a theory about that, and you might've found a bug in a_mysql.inc .
pawn Код:
native orm_addvar_string(ORM:id, &{Float, _}:var, var_maxlen, varname[]);
Basically the second argument requires reference to a single celled variable, and it doesn't raise an error when used with enumerated array only because either the compiler doesn't know it's an array (but usually it does), or the variable has a new tag - the enums one. That was sphagetti statement, let me demonstrate:
pawn Код:
new Foo[16];
enum Bar {
    Foobar[16]
}
new Barfoo[Bar];

//(...)
//No can do, we want a single cell and you give us an array! - Error
orm_addvar_string(oid, Foo, 16, "foobarfoo");
//Compiler is confused! Compiler hurts itself in its confusion! - No dimensions mismatch? No idea why though
orm_addvar_string(oid, Barfoo[Foobar], 16, "foobarfoo");
The 'fix' I gave you, works because it's a plugin function. In memory every string cell is set in a row, so we pass the address of first one, and read the memory until MAX_PLAYER_NAME cells. If orm_addvar was a pawn function, there would be a lot of "dimensions do not match" stuff.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)