Creates the last object only
#1

So i have a loading system that works correctly(at MySQL section)
At Creating the object section though i have stuck. How would be possible to create all the objects the database is loading?

It creates only the last one if even i have one. What the correct loop would be?
PHP код:
                function LoadSprayTags(playerid)
                {
                
                    new 
rowsfieldsIndex tagid[playerid];
                    
cache_get_data(rowsfieldsmysql);
                    for(new 
0rowsi++)
                    {
                        
cache_get_field_content(i"TagName"TagInfo[playerid][Index][TagName], mysql,25);
                        
cache_get_field_content(i"TagOwner"TagInfo[playerid][Index][TagOwner], mysql25);
                        
cache_get_field_content(i"TagFont"TagInfo[playerid][Index][TagFont], mysql20);
                        
TagInfo[playerid][Index][TagX] = cache_get_field_content_float(i"TagX");
                        
TagInfo[playerid][Index][TagY] = cache_get_field_content_float(i"TagY");
                        
TagInfo[playerid][Index][TagZ] = cache_get_field_content_float(i"TagZ");
                        
TagInfo[playerid][Index][TagRX] = cache_get_field_content_float(i"TagRX");
                        
TagInfo[playerid][Index][TagRY] = cache_get_field_content_float(i"TagRY");
                        
TagInfo[playerid][Index][TagRZ] = cache_get_field_content_float(i"TagRZ");
                        
TagInfo[playerid][Index][TagFontSize] = cache_get_field_content_int(i"TagFontSize");
                        
TagInfo[playerid][Index][TagFontColor] = cache_get_field_content_int(i"TagFontColor");
                        
TagInfo[playerid][Index][TagBold] = cache_get_field_content_int(i"TagBold");
                        
                        
TagInfo[playerid][Index][TagObject] = CreateDynamicObject(19482TagInfo[playerid][Index][TagX], TagInfo[playerid][Index][TagY], TagInfo[playerid][Index][TagZ], TagInfo[playerid][Index][TagRX], TagInfo[playerid][Index][TagRY], TagInfo[playerid][Index][TagRZ], -1, -1, -1300.0300.0);
                        
SetDynamicObjectMaterialText(TagInfo[playerid][Index][TagObject], 0TagInfo[playerid][Index][TagName], 70TagInfo[playerid][Index][TagFont], TagInfo[playerid][Index][TagFontSize], 1TagInfo[playerid][Index][TagFontColor], 00);
                            
                        new 
str[90];
                        
                        
format(strsizeof(str)," "COL_LIGHTBLUE"Graffiti Owner:"COL_WHITE" %s \n"COL_LIGHTBLUE"Tag ID:"COL_WHITE" %i"TagInfo[playerid][Index][TagOwner], TagInfo[playerid][Index][TagID]);
                        
TagInfo[playerid][Index][TagAdminInfo] = CreateDynamic3DTextLabel(strCOLOR_YELLOWTagInfo[playerid][Index][TagX], TagInfo[playerid][Index][TagY], TagInfo[playerid][Index][TagZ], 100.0);
                            
                        
printf("Name:%s Owner:%s \n Font:%s X:%f Y:%f Z:%f \n RX:%f RY:%f RZ:%f \nFontSize:%d FontColor:%d Bold: %d"TagInfo[playerid][Index][TagName], TagInfo[playerid][Index][TagOwner], TagInfo[playerid][Index][TagFont],
                        
TagInfo[playerid][Index][TagX], TagInfo[playerid][Index][TagY], TagInfo[playerid][Index][TagZ], TagInfo[playerid][Index][TagRX], TagInfo[playerid][Index][TagRY],TagInfo[playerid][Index][TagRZ],
                        
TagInfo[playerid][Index][TagFontSize], TagInfo[playerid][Index][TagFontColor],TagInfo[playerid][Index][TagBold]);
                    }
                    
                    return 
1;
                } 
Reply
#2

As I see you're assigning all vars to taginfo, and this way you replace the next one with previous, ending up with having last xyz's.

Just a wild guess.
Reply
#3

You implemented that additional array dimension as I advised you to, but you're incorrectly using it. The point of it is to put all your database information in there up till the maximum allowed tags per player (which is defined as MAX_TAGS_PER_PLAYER, right?):

PHP код:
// Get rid of the 'index' variable
for(new icache_get_row_count(); && MAX_TAGS_PER_PLAYERi++) {
    
// Use 'i' to address the second array dimension

The loop goes through all rows returned by the query only if i remains smaller than MAX_TAGS_PER_PLAYER (0 to 2 = 3 tags).
Reply
#4

Quote:
Originally Posted by AndySedeyn
Посмотреть сообщение
PHP код:
// Get rid of the 'index' variable
for(new icache_get_row_count(); && MAX_TAGS_PER_PLAYERi++) {
    
// Use 'i' to address the second array dimension

So like that?
PHP код:
                function LoadSprayTags(playerid)
                {
                
                    new 
Index tagid[playerid];
                    
cache_get_data(rowsfieldsmysql);
                    for(new 
icache_get_row_count(); && MAX_TAGS_PER_PLAYERi++) 
                    { 
                        
cache_get_field_content(i"TagName"TagInfo[playerid][Index][TagName], mysql,25);
                        
cache_get_field_content(i"TagOwner"TagInfo[playerid][Index][TagOwner], mysql25);
                        
cache_get_field_content(i"TagFont"TagInfo[playerid][Index][TagFont], mysql20);
                        
TagInfo[playerid][Index][TagX] = cache_get_field_content_float(i"TagX");
                        
TagInfo[playerid][Index][TagY] = cache_get_field_content_float(i"TagY");
                        
TagInfo[playerid][Index][TagZ] = cache_get_field_content_float(i"TagZ");
                        
TagInfo[playerid][Index][TagRX] = cache_get_field_content_float(i"TagRX");
                        
TagInfo[playerid][Index][TagRY] = cache_get_field_content_float(i"TagRY");
                        
TagInfo[playerid][Index][TagRZ] = cache_get_field_content_float(i"TagRZ");
                        
TagInfo[playerid][Index][TagFontSize] = cache_get_field_content_int(i"TagFontSize");
                        
TagInfo[playerid][Index][TagFontColor] = cache_get_field_content_int(i"TagFontColor");
                        
TagInfo[playerid][Index][TagBold] = cache_get_field_content_int(i"TagBold");
                        
                        
TagInfo[playerid][i][TagObject] = CreateDynamicObject(19482TagInfo[playerid][i][TagX], TagInfo[playerid][i][TagY], TagInfo[playerid][i][TagZ], TagInfo[playerid][i][TagRX], TagInfo[playerid][i][TagRY], TagInfo[playerid][i][TagRZ], -1, -1, -1300.0300.0);
                        
SetDynamicObjectMaterialText(TagInfo[playerid][i][TagObject], 0TagInfo[playerid][i][TagName], 70TagInfo[playerid][i][TagFont], TagInfo[playerid][i][TagFontSize], 1TagInfo[playerid][i][TagFontColor], 00);
                            
                        new 
str[90];
                        
                        
format(strsizeof(str)," "COL_LIGHTBLUE"Graffiti Owner:"COL_WHITE" %s \n"COL_LIGHTBLUE"Tag ID:"COL_WHITE" %i"TagInfo[playerid][i][TagOwner], TagInfo[playerid][i][TagID]);
                        
TagInfo[playerid][i][TagAdminInfo] = CreateDynamic3DTextLabel(strCOLOR_YELLOWTagInfo[playerid][i][TagX], TagInfo[playerid][i][TagY], TagInfo[playerid][i][TagZ], 100.0);
                            
                        
printf("Name:%s Owner:%s \n Font:%s X:%f Y:%f Z:%f \n RX:%f RY:%f RZ:%f \nFontSize:%d FontColor:%d Bold: %d"TagInfo[playerid][i][TagName], TagInfo[playerid][i][TagOwner], TagInfo[playerid][i][TagFont],
                        
TagInfo[playerid][i][TagX], TagInfo[playerid][i][TagY], TagInfo[playerid][i][TagZ], TagInfo[playerid][i][TagRX], TagInfo[playerid][i][TagRY],TagInfo[playerid][i][TagRZ],
                        
TagInfo[playerid][i][TagFontSize], TagInfo[playerid][i][TagFontColor],TagInfo[playerid][i][TagBold]);
                    }  
                    return 
1;
                } 
Reply
#5

No. You're still using new Index = tagid[playerid];. Use the loop variable i to go through the indices of the second dimension.

Secondly, by using cache_get_row_count(), cache_get_data becomes redundant.
Reply
#6

Quote:
Originally Posted by AndySedeyn
Посмотреть сообщение
No. You're still using new Index = tagid[playerid];. Use the loop variable i to go through the indices of the second dimension.

Secondly, by using cache_get_row_count(), cache_get_data becomes redundant.
Works thank you Andy!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)