Y_INI Saving/loading help
#6

Doing it like that might be very slow. Keep in mind that for every other file, you have to open, read and close it. And that MAX_OBJECTS times. Though, it's definitely going to be faster to delete them and check if they exist.

Here's an example:
PHP код:
CMD:createobject(playeridparams[]) {

    new
        
objectid;

    if(
sscanf(params"d"objectid)) {

        return 
SendClientMessage(playerid, -1"USAGE: /createobject <id>");
    }

    new 
        
obj createObj(objectid);

    if(
obj == -1) {

        
// createObj() has returned -1
        
SendClientMessage(playerid, -1"ERROR: The server has reached its maximum amount of objects.");
    }
    return 
true;
}

createObj(objectid) {

    new
        
tempPath[24];

    for(new 
0MAX_OBJECTS++) {

        
format(tempPathsizeof(tempPath), "\\objects\\%d.ini"i);
        if(
fexist(tempPath)) {

            
// Object with ID the value of the current 'i' already exists
            
continue;
        }
        new 
INI:file INI_Open(tempPath);
        
INI_SetTag(file"objects");
        
INI_WriteInt(file"Object ID"objectid);
        
INI_Close(file);
        
        return 
i;
    }
    return -
1;

The example code allows you to keep numbers filled. Example:
> There are three files; 0.ini, 1.ini and 2.ini respectively.
> You remove 1.ini
> You create a new object
> It will save as 1.ini and not as 3.ini

Doing it otherwise may give you trouble when creating objects with the same ID.
Reply


Messages In This Thread
Y_INI Saving/loading help - by GeorgeMcReary - 22.07.2016, 16:31
Re: Y_INI Saving/loading help - by Deadpoop - 22.07.2016, 16:36
Re: Y_INI Saving/loading help - by GeorgeMcReary - 22.07.2016, 16:51
Re: Y_INI Saving/loading help - by AndySedeyn - 22.07.2016, 17:04
Re: Y_INI Saving/loading help - by GeorgeMcReary - 23.07.2016, 06:48
Re: Y_INI Saving/loading help - by AndySedeyn - 23.07.2016, 12:14

Forum Jump:


Users browsing this thread: 1 Guest(s)