Saving and Loading IDs.
#1

Hey all.

So... Let's suppose I want to create a Dynamic Label Creator.

I define MAX_LABELS.

pawn Код:
#define MAX_LABELS 1000
Create enums about Label:

pawn Код:
enum lInfo
{
    LText
    Float:LX;
    Float:LY;
    Float;LZ;
}
And that variable.

pawn Код:
new LabelInfo[MAX_LABELS][lInfo];
Ok... So let's suppose we made a variable:

pawn Код:
new labelid;
And to make enums with labelid wich represet ID of that Label.

pawn Код:
LabelInfo[labelid][LX]
etc..

But, how can I save that ID from that label? I need to write in in a file and load at every sa-mp.exe folder...?
Reply
#2

Yeah, just make a loop that goes through all id's and save them individually. Upon load, you again make a loop that will load each file.

..or you could write them all to 1 file, with 1 line for each label and use sscanf to separate the values from each line.
Reply
#3

so you want to write it to a file?

then just something like this
pawn Код:
#include <a_samp>

#define MAX_LABELS 1000

enum lInfo
{
    bool:created,
    LText[30],
    Float:LX,
    Float:LY,
    Float:LZ
};

new LabelInfo[MAX_LABELS][lInfo];

public OnFilterScriptInit()
{
    //lets set some stuff for 5 labels
    for(new labelid=0; labelid<5; labelid++)
    {
        LabelInfo[labelid][created] = true;
        format(LabelInfo[labelid][LText], 30,"some text");
        LabelInfo[labelid][LX] = labelid+3.14;
        LabelInfo[labelid][LY] = labelid+4.14;
        LabelInfo[labelid][LZ] = labelid+5.14;
    }


    new File:h=fopen("myLabels.txt",io_write);
   
    new str[40];//need to be adjusted depending on the LText size
    for(new i=0; LabelInfo[i][created]; i++)
    {
        format(str,sizeof str,"LabelInfo[%d][LText] = \"%s\";\n",i,LabelInfo[i][LText]);
        fwrite(h,str);
        format(str,sizeof str,"LabelInfo[%d][LX] = %.3f;\n",i,LabelInfo[i][LX]);
        fwrite(h,str);
        format(str,sizeof str,"LabelInfo[%d][LY] = %.3f;\n",i,LabelInfo[i][LY]);
        fwrite(h,str);
        format(str,sizeof str,"LabelInfo[%d][LZ] = %.3f;\n\n",i,LabelInfo[i][LZ]);
        fwrite(h,str);
    }
   
    fclose(h);
   
    return 1;
}
?

file would look like
Код:
LabelInfo[0][LText] = "some text";
LabelInfo[0][LX] = 3.140;
LabelInfo[0][LY] = 4.139;
LabelInfo[0][LZ] = 5.139;

LabelInfo[1][LText] = "some text";
LabelInfo[1][LX] = 4.140;
LabelInfo[1][LY] = 5.139;
LabelInfo[1][LZ] = 6.139;

LabelInfo[2][LText] = "some text";
LabelInfo[2][LX] = 5.140;
LabelInfo[2][LY] = 6.139;
LabelInfo[2][LZ] = 7.139;

LabelInfo[3][LText] = "some text";
LabelInfo[3][LX] = 6.140;
LabelInfo[3][LY] = 7.139;
LabelInfo[3][LZ] = 8.139;

LabelInfo[4][LText] = "some text";
LabelInfo[4][LX] = 7.140;
LabelInfo[4][LY] = 8.139;
LabelInfo[4][LZ] = 9.139;
or is that not what you meant?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)