Help with my garage system
#1

I get this idk what i am doing wrong

Код:
C:\Users\Nate\Desktop\test\gamemodes\test.pwn(6517 -- 6530) : warning 213: tag mismatch
C:\Users\Nate\Desktop\test\gamemodes\test.pwn(6517 -- 6530) : error 032: array index out of bounds (variable "GarageInfo")
PHP код:
enum gInfo
{
    
gEnterX,
    
gEnterY,
    
gEnterZ,
    
gEnterAngle,
    
gExitX,
    
gExitY,
    
gExitZ,
    
gExitAngle,
    
gOwned,
    
gOwner,
    
gPrice,
    
gLocked,
    
gPickupID
};
new 
GarageInfo[SCRIPT_MAXGARGES][gInfo]; 
PHP код:
public SaveGarage()
{
    new 
idxFilefile2coordsstring[256];
    while (
idx sizeof(GarageInfo))
    {
        
format(coordsstringsizeof(coordsstring), "%f|%f|%f|%f|%f|%f|%f|%f|%d|%s|%d|%d\n",
        
GarageInfo[idx][gEnterX],
        
GarageInfo[idx][gEnterY],
        
GarageInfo[idx][gEnterZ],
        
GarageInfo[idx][gEnterAngle],
        
GarageInfo[idx][gExitX],
        
GarageInfo[idx][gExitY],
        
GarageInfo[idx][gExitZ],
        
GarageInfo[idx][gExitAngle],
        
GarageInfo[idx][gOwned],
        
GarageInfo[idx][gOwner],
        
GarageInfo[idx][gPrice],
        
GarageInfo[idx][gLocked],
        
GarageInfo[idx][hPickupID]);
        if(
idx == 0file2 fopen("garage.ini"io_write);
        else 
file2 fopen("garage.ini"io_append);
        
fwrite(file2coordsstring);
        
idx++;
        
fclose(file2);
    }
    return 
1;

PHP код:
public LoadGarage()
{
    
printf("Loading Garages...");
    new 
arrCoords[13][64], strFromFile2[256];
    new 
Filefile fopen("garage.ini"io_read);
    if (
file)
    {
        new 
idx;
        while (
idx sizeof(GarageInfo))
        {
            
fread(filestrFromFile2);
            
split(strFromFile2arrCoords',');
            
GarageInfo[idx][gEnterX] = floatstr(arrCoords[0]);
            
GarageInfo[idx][gEnterY] = floatstr(arrCoords[1]);
            
GarageInfo[idx][gEnterZ] = floatstr(arrCoords[2]);
            
GarageInfo[idx][gEnterAngle] = floatstr(arrCoords[3]);
            
GarageInfo[idx][gExitX] = floatstr(arrCoords[4]);
            
GarageInfo[idx][gExitY] = floatstr(arrCoords[5]);
            
GarageInfo[idx][gExitZ] = floatstr(arrCoords[6]);
            
GarageInfo[idx][gExitAngle] = floatstr(arrCoords[7]);
            
GarageInfo[idx][gOwned] = strval(arrCoords[8]);
            
strmid(GarageInfo[idx][gOwner], arrCoords[9], 0strlen(arrCoords[9]), 255);
            
GarageInfo[idx][gPrice] = strval(arrCoords[10]);
            
GarageInfo[idx][gLocked] = strval(arrCoords[11]);
            
GarageInfo[idx][gPickupID] = strval(arrCoords[12]);
            
idx++;
        }
    }
    
fclose(file);
    return 
1;

Reply
#2

Not sure but try this
PHP код:
enum gInfo
{
    
gEnterX,
    
gEnterY,
    
gEnterZ,
    
gEnterAngle,
    
gExitX,
    
gExitY,
    
gExitZ,
    
gExitAngle,
    
gOwned,
    
gOwner,
    
gPrice,
    
gLocked,
    
gPickupID,
};
new 
GarageInfo[SCRIPT_MAXGARGES][gInfo]; 
Reply
#3

Код:
gOwner
is a string, should be
Код:
gOwner[MAX_PLAYER_NAME],
You also need to add Float: infront of these vars
Код:
    gEnterX, 
    gEnterY, 
    gEnterZ, 
    gEnterAngle, 
    gExitX, 
    gExitY, 
    gExitZ, 
    gExitAngle,
Plus you really should code it yourself instead of copying another system and changing the vars as it wont teach you anything.

Код:
GarageInfo[idx][hPickupID]);
Clearly copied from a house system, you didnt switch the h with a g
Reply
#4

I want to add that it is terrible practice to open and close the file for each line written. This leads to lots of unnecessary IO and it is very slow. Open file, loop, close files. The structure also does not follow the INI file format so it shouldn't realistically have the extension .ini, either.
Reply
#5

You miss the size on gEnter's, you are using the floatstr function and you need to put the string size in the enum:
gEnterX[16]
Or you just change the savesystem and put Float: before the vars un the enum. Sorry my english hahaha
Reply
#6

Quote:
Originally Posted by Hellman92
Посмотреть сообщение
Like this?

PHP код:
Float:gEnterX
Quote:
Originally Posted by Vince
Посмотреть сообщение
I want to add that it is terrible practice to open and close the file for each line written. This leads to lots of unnecessary IO and it is very slow. Open file, loop, close files. The structure also does not follow the INI file format so it shouldn't realistically have the extension .ini, either.
So how should be it done then?

Quote:
Originally Posted by -CaRRoT
Посмотреть сообщение
Код:
gOwner
is a string, should be
Код:
gOwner[MAX_PLAYER_NAME],
You also need to add Float: infront of these vars
Код:
    gEnterX, 
    gEnterY, 
    gEnterZ, 
    gEnterAngle, 
    gExitX, 
    gExitY, 
    gExitZ, 
    gExitAngle,
Plus you really should code it yourself instead of copying another system and changing the vars as it wont teach you anything.

Код:
GarageInfo[idx][hPickupID]);
Clearly copied from a house system, you didnt switch the h with a g
I copy my own house system and convert into a garage system lol.
Reply
#7

Quote:
Originally Posted by Hellman92
Посмотреть сообщение
So how should be it done then?
Open file before loop. Do the entire loop. Close the file after loop. I reckon my earlier instructions were pretty straightforward.
Reply
#8

Quote:
Originally Posted by Vince
Посмотреть сообщение
Open file before loop. Do the entire loop. Close the file after loop. I reckon my earlier instructions were pretty straightforward.
Okey but i did not understand to 100 but now i get it thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)