printf message not displaying
#1

Well basically I made this code below, Everything loads fine but the thing is it doesn't tell you how many items it loaded in the printf message. I'm not sure what's wrong.

pawn Код:
forward LoadStuff();
public LoadStuff()
{
    new rows = cache_num_rows();
    if(rows)
    {
        new id, loaded;
        while(loaded < rows)
        {
            id = cache_get_field_content_int(loaded, "ID");
            cache_get_field_content(loaded, "Name", StuffInfo[id][sName], .max_len = MAX_STUFF_NAME);
            StuffInfo[id][sType] = cache_get_field_content_int(loaded, "Type");
            StuffInfo[id][sEconomyType] = cache_get_field_content_int(loaded, "EconomyType");
            StuffInfo[id][sTax] = cache_get_field_content_int(loaded, "Tax");
            StuffInfo[id][sVault] = cache_get_field_content_int(loaded, "Vault");

            loaded++;
        }
        printf(" [Stuff System] Loaded %d stuff.", loaded);
    }
    return 1;
}
Reply
#2

Hey buddy..

Could you try to move printf function like this?
NOTE: If it still doesn't display, tell me and i'll fix it for you.


PHP код:
forward LoadStuff();
public 
LoadStuff()
{
    new 
rows cache_num_rows(),idloaded=0;
     if(
rows)
      {
        while(
loaded rows)
        {
              
id cache_get_field_content_int(loaded"ID");
            
cache_get_field_content(loaded"Name"StuffInfo[id][sName], .max_len MAX_STUFF_NAME);
            
StuffInfo[id][sType] = cache_get_field_content_int(loaded"Type");
            
StuffInfo[id][sEconomyType] = cache_get_field_content_int(loaded"EconomyType");
            
StuffInfo[id][sTax] = cache_get_field_content_int(loaded"Tax");
            
StuffInfo[id][sVault] = cache_get_field_content_int(loaded"Vault");
            
loaded++;
        }
    }
     
printf(" [Stuff System] Loaded %d stuff."loaded); // right here
    
return 1;

Reply
#3

Quote:
Originally Posted by trablon
Посмотреть сообщение
Hey buddy..

Could you try to move printf function like this?
NOTE: If it still doesn't display, tell me and i'll fix it for you.


PHP код:
forward LoadStuff();
public 
LoadStuff()
{
    new 
rows cache_num_rows(),idloaded=0;
     if(
rows)
      {
        while(
loaded rows)
        {
              
id cache_get_field_content_int(loaded"ID");
            
cache_get_field_content(loaded"Name"StuffInfo[id][sName], .max_len MAX_STUFF_NAME);
            
StuffInfo[id][sType] = cache_get_field_content_int(loaded"Type");
            
StuffInfo[id][sEconomyType] = cache_get_field_content_int(loaded"EconomyType");
            
StuffInfo[id][sTax] = cache_get_field_content_int(loaded"Tax");
            
StuffInfo[id][sVault] = cache_get_field_content_int(loaded"Vault");
            
loaded++;
        }
    }
     
printf(" [Stuff System] Loaded %d stuff."loaded);
    return 
1;

Pretty sure that's a bad idea because loaded is outside of the defined brackets. So basically it wouldn't work or compile.
Reply
#4

Nope!

Buddy, if you figure out above the variables.I defined both of them as a global variable for LoadStuff(); function.
So, try it and test it.Loaded default variable is 0, so when it's looped, it will count it in this variable.
Reply
#5

Here let me fix the indentation:

pawn Код:
forward LoadStuff();
public LoadStuff()
{
    new rows = cache_num_rows();
    if(rows)
    {
        new id, loaded;
        while(loaded < rows)
        {
            id = cache_get_field_content_int(loaded, "ID");
                   cache_get_field_content(loaded, "Name", StuffInfo[id][sName], .max_len = MAX_STUFF_NAME);
                   StuffInfo[id][sType] = cache_get_field_content_int(loaded, "Type");
                   StuffInfo[id][sEconomyType] = cache_get_field_content_int(loaded, "EconomyType");
                   StuffInfo[id][sTax] = cache_get_field_content_int(loaded, "Tax");
                   StuffInfo[id][sVault] = cache_get_field_content_int(loaded, "Vault");

                   loaded++;
            }
            printf(" [Stuff System] Loaded %d stuff.", loaded);
    }
    return 1;
}
It would not make since to put the printf there.
Reply
#6

Have you tried the codes which i sent it from 1st post in this topic?
Reply
#7

Quote:
Originally Posted by trablon
Посмотреть сообщение
Have you tried the codes which i sent it from 1st post in this topic?
My bad didn't see your edit, it compiles fine but still it doesn't show the message.
Reply
#8

Okay buddy, now i get it.

I'll give you an example for solving this issue.If you do as this example, you will be fixed the issue!

PHP код:
new 
    
Database 1
main(){}
public 
OnGameModeInit()
{
    
mysql_log(LOG_ALL,LOG_TYPE_TEXT);
    
Database mysql_connect("localhost","user","testdb","pass");
    
mysql_tquery(Database,"SELECT * FROM `houses`","OnHouseLoad");
    return 
1;
}
forward OnHouseLoad();
public 
OnHouseLoad()
{
    if(
cache_num_rows())
    {
        for(new 
0i<cache_num_rows(); i++)
        {
            new 
ID cache_get_field_content_int(i,"id",Database);
            new 
Float:=  cache_get_field_content_float(i,"x",Database);
            new 
Float:=  cache_get_field_content_float(i,"y",Database);
            new 
Float:=  cache_get_field_content_float(i,"z",Database);
            
printf("Loaded house %d %f %f %f",ID,x,y,z);
        }
    }
    else print(
"No houses found.");
    return 
1;

Reply
#9

I still don't get it man.
Reply
#10

pawn Код:
forward LoadStuff();
public LoadStuff()
{
    new rows = cache_num_rows();
    for(new i; i < rows; i++)
    {
        id = cache_get_field_content_int(i, "ID");
       
        cache_get_field_content(i, "Name", StuffInfo[id][sName], .max_len = MAX_STUFF_NAME);
        StuffInfo[id][sType]        = cache_get_field_content_int(i, "Type");
        StuffInfo[id][sEconomyType] = cache_get_field_content_int(i, "EconomyType");
        StuffInfo[id][sTax]         = cache_get_field_content_int(i, "Tax");
        StuffInfo[id][sVault]       = cache_get_field_content_int(i, "Vault");
    }
    printf(" [Stuff System] Loaded %d stuff.", rows);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)