Error while using cache_get_content_field
#1

So hello there, i have a problem with my script i can't get it working.
I want to store a value from my database "COLOR_WHITE" into pInfo[playerid][namecolor] but. When i store it i recieve no errors but it's still not working, i made a test string with SendClientMessage and it print's to me only letter "C" and the name is then converted to black, as the variable is not defined and doesn't exist in my color list as "C". The mysql colomn is "namecolor" set to TEXT as type. I tried varchar(250) too, nothing happens.

This is were the variable is set when user log in:
PHP код:
new dest[256];
cache_get_field_content(0,"namecolor",dest);
//cache_get_field_content(0,"namecolor",pInfo[playerid][namecolor],dbhandle,128); //i tried this too and same.
format(pInfo[playerid][namecolor], sizeof(dest), dest); 
Here is when user uses command to change color: (still in test purposes)
PHP код:
CMD:color(playeridparams[])
{
    new 
color pInfo[playerid][namecolor];
        
SetPlayerColor(playeridpInfo[playerid][namecolor]);
        new 
string[128];
    
format(stringsizeof(string), "Color: %s"color);
    
SendClientMessage(playeridCOLOR_GREENstring);
    return 
1;



I have no idea how to resolve this..
Reply
#2

Save and load the color as integer.
pInfo[playerid][namecolor] should be declared as integer as well.
Retrieve it with cache_get_field_content_int function.

pawn Код:
format(string, sizeof(string), "Color: %06x", pInfo[playerid][namecolor] >>> 8);
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Save and load the color as integer.
pInfo[playerid][namecolor] should be declared as integer as well.
Retrieve it with cache_get_field_content_int function.

pawn Код:
format(string, sizeof(string), "Color: %06x", pInfo[playerid][namecolor] >>> 8);
Ok but what if i want to print something else from the database, this method with cache_get_field_content won't work either... For example what if i have some logs and i want to print them into a dialog, this will not work with integer for those thoo.
Reply
#4

cache_get_field_content works just fine to retrieve the data as string, it is probably something wrong with what you have done.

Keep in mind that if you don't select that column in a SELECT query and then trying to retrieve that column won't work. Unless you post the mysql_log.txt, I can't say for sure what is wrong.
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
cache_get_field_content works just fine to retrieve the data as string, it is probably something wrong with what you have done.

Keep in mind that if you don't select that column in a SELECT query and then trying to retrieve that column won't work. Unless you post the mysql_log.txt, I can't say for sure what is wrong.
Ah that's why is not working, i am always using SELECT... what should i use instead?
Reply
#6

That is really depends on what you want to select (which columns). An example of what I meant in my previous post:
Код:
SELECT column1 FROM table LIMIT 1;
and then retrieving it like:
Код:
cache_get_field_content(0, "column2", dest);
dest will be empty because there is no data selected for column2, what we selected were the data for column1.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)