Writing string into variable(enum)
#1

Hello, so I making register/login system but I have somerproblems,
Can I write string into pInfo[playerid][country] ?
I want when somebody choose country from dialog to put name of county into variable but, i get error undefined symbol i also tried "America" but no(must be assigned to an array).

And when i open .ini file to write, example. Country = America
As you see Hrvatska is my string i want to put into variable
Код:
if(dialogid == DPORIJEKLO){
        if(!response) return KickWithMessage(playerid, RED, "Morate izabrati drzavu iz koje dolazite kako biste se registrovali(Kickovani ste!)");
        if(response){
            if(listitem == 0){
                pInfo[playerid][pPorijeklo] = Hrvatska;
                PlayerTextDrawSetString(playerid, registracija[11][playerid], "Hrvatska");
            }
        }
    }
Reply
#2

.
Use strcpy to insert a string to a variable, search for that function in Code optimisations topic, example:
pawn Код:
strcpy(pInfo[playerid][pPorijeklo], "Hrvatska", 32);
Reply
#3

Quote:
Originally Posted by Virtual1ty
Посмотреть сообщение
Really offtopic: Bosanac si, ime varijable ("porijeklo") ti je na hrvatskom, a tekst registracije na srpskom ("kako biste se registrovali.. ") - tko tu koga.. !?
On topic:
Use strcpy to insert a string to a variable, search for that function in Code optimisations topic, example:
pawn Код:
strcpy(pInfo[playerid][pPorijeklo], "Hrvatska", 32);
Offtopic: Kakve to veze ? "kako biste se registrovali" srpsko ? kako bih trebao napisati da je na bosanskom hah, i otkud ti to da je rijec porijeklo na hrvatskom ?
On topic:
It doesn't work, i get these errors, I think strcpy doesn't exist:
Код:
RP.pwn(464) : error 001: expected token: ")", but found "["
RP.pwn(464) : warning 215: expression has no effect
RP.pwn(464) : error 001: expected token: ";", but found "]"
RP.pwn(464) : error 029: invalid expression, assumed zero
RP.pwn(464) : fatal error 107: too many error messages on one line
Reply
#4

the best way to accomplish something like this is using memcpy
(faster than using format)

pawn Код:
memcpy(pInfo[playerid][pPorijeklo], "Hrvatska", 0, 32);
Reply
#5

Maybe faster, but not safer, that's why we all use strcpy:
pawn Код:
#define strcpy(%0,%1,%2) \
    strcat((%0[0] = '\0', %0), %1, %2)
From the Code optimisations topic.
Reply
#6

or you could just use format:
try this
pawn Код:
if(dialogid == DPORIJEKLO){
        if(!response) return KickWithMessage(playerid, RED, "Morate izabrati drzavu iz koje dolazite kako biste se registrovali(Kickovani ste!)");
        if(response){
            if(listitem == 0){
                format(pInfo[playerid][pPorijeklo], 128, "Hrvatska");;
                PlayerTextDrawSetString(playerid, registracija[11][playerid], "Hrvatska");
            }
        }
    }
----------------------------

Edit: I think you can simply do that:
pawn Код:
pInfo[playerid][pPorijeklo] = "Hrvatska"; //= add "" to Hrvatska
I believe that format is the best solution (first suggestion)
Reply
#7

Quote:
Originally Posted by Virtual1ty
Посмотреть сообщение
Really offtopic: Bosanac si, ime varijable ("porijeklo") ti je na hrvatskom, a tekst registracije na srpskom ("kako biste se registrovali.. ") - tko tu koga.. !?
On topic:
Use strcpy to insert a string to a variable, search for that function in Code optimisations topic, example:
pawn Код:
strcpy(pInfo[playerid][pPorijeklo], "Hrvatska", 32);
Quote:
Originally Posted by CutX
Посмотреть сообщение
the best way to accomplish something like this is using memcpy
(faster than using format)

pawn Код:
memcpy(pInfo[playerid][pPorijeklo], "Hrvatska", 0, 32);
It doesn't work: http://prntscr.com/4dbvxn as you see Porijeklo is empty.

@Virtual1ty - When i use strcpy i got these errors.
Код:
RP.pwn(58) : warning 201: redefinition of constant/macro (symbol "strcpy(%0,%1,%2)")
RP.pwn(467) : error 001: expected token: ")", but found "["
RP.pwn(467) : warning 215: expression has no effect
RP.pwn(467) : error 001: expected token: ";", but found "]"
RP.pwn(467) : error 029: invalid expression, assumed zero
RP.pwn(467) : fatal error 107: too many error messages on one line
@Sarra - When i use format only one letter write: http://prntscr.com/4dbwv1 , and i can't use pInfo[playerid][pPorijeklo] = "Hrvatska"; (must be assigned to an array)


Код:
enum PlayerInfo
{
    pLozinka[129], 
    pAdmin, 
    pHelper, 
    pDonator, 
    pLevel, 
    pUbojstva, 
    pNovac,
    pSmrti,
    pGodine,
    pSpol,
    pPorijeklo,
    pEmail,
    pRegistrovan,
    pTutorial 
}
new pInfo[MAX_PLAYERS][PlayerInfo];
Код:
public OnPlayerDisconnect(playerid, reason)
{
        new INI:file = INI_Open(Path(playerid)); 
        INI_SetTag(file,"Podatci");
        INI_WriteInt(file,"Admin",pInfo[playerid][pAdmin]); 
        INI_WriteInt(file,"Helper",pInfo[playerid][pHelper]);
        INI_WriteInt(file,"Donator",pInfo[playerid][pDonator]);
        INI_WriteInt(file,"Novac",GetPlayerMoney(playerid));
        INI_WriteInt(file,"Level",GetPlayerScore(playerid));
        INI_WriteInt(file,"Ubojstva",pInfo[playerid][pUbojstva]);
        INI_WriteInt(file,"Smrti",pInfo[playerid][pSmrti]);
        INI_WriteInt(file,"Godine",pInfo[playerid][pGodine]);
        INI_WriteInt(file,"Spol",pInfo[playerid][pSpol]);
        INI_WriteString(file,"Porijeklo",pInfo[playerid][pPorijeklo]);
        INI_WriteString(file,"Email",pInfo[playerid][pEmail]);
        INI_Close(file);
        return 1;
}
Код:
forward loadaccount_user(playerid, name[], value[]);
public loadaccount_user(playerid, name[], value[])
{
    INI_String("Lozinka", pInfo[playerid][pLozinka],129); 
    INI_Int("Admin",pInfo[playerid][pAdmin]);
    INI_Int("Helper",pInfo[playerid][pHelper]);
    INI_Int("Donator",pInfo[playerid][pDonator]);
    INI_Int("Novac",pInfo[playerid][pNovac]); 
    INI_Int("Level",pInfo[playerid][pLevel]);
    INI_Int("Ubojstva",pInfo[playerid][pUbojstva]);
    INI_Int("Smrti",pInfo[playerid][pSmrti]);
    INI_Int("Godine",pInfo[playerid][pGodine]);
    INI_Int("Spol",pInfo[playerid][pSpol]);
    INI_Int("Porijeklo",pInfo[playerid][pPorijeklo]);
    INI_Int("Email",pInfo[playerid][pEmail]);
    return 1;
}
If you got confused about writing string loading like int, i don't know i was searching and find this solution.
Reply
#8

pawn Код:
enum PlayerInfo
{
    pLozinka[129],
    pAdmin,
    pHelper,
    pDonator,
    pLevel,
    pUbojstva,
    pNovac,
    pSmrti,
    pGodine,
    pSpol,
    pPorijeklo[128],
    pEmail,
    pRegistrovan,
    pTutorial
}
new pInfo[MAX_PLAYERS][PlayerInfo];
IMPORTANT: Add [128] to pPorijeklo this should fix it all and retry using format
pawn Код:
if(dialogid == DPORIJEKLO){
        if(!response) return KickWithMessage(playerid, RED, "Morate izabrati drzavu iz koje dolazite kako biste se registrovali(Kickovani ste!)");
        if(response){
            if(listitem == 0){
                format(pInfo[playerid][pPorijeklo], 128, "Hrvatska");;
                PlayerTextDrawSetString(playerid, registracija[11][playerid], "Hrvatska");
            }
        }
    }
Reply
#9

Quote:
Originally Posted by ******
Посмотреть сообщение
The best version of strcpy is:

pawn Код:
#define strcpy(%0,%1) \
    strcat((%0[0] = '\0', %0), %1)
You can still use the third parameter, but now it is optional.
I will use it, if it won't give me errors,
Код:
RP.pwn(467) : error 001: expected token: ")", but found "["
RP.pwn(467) : warning 215: expression has no effect
RP.pwn(467) : error 001: expected token: ";", but found "]"
RP.pwn(467) : error 029: invalid expression, assumed zero
RP.pwn(467) : fatal error 107: too many error messages on one line
467 LINE - strcpy(pInfo[playerid][pPorijeklo], "Hrvatska");

Код:
f(dialogid == DPORIJEKLO){
        if(!response) return KickWithMessage(playerid, RED, "Morate izabrati drzavu iz koje dolazite kako biste se registrovali(Kickovani ste!)");
        if(response){
            if(listitem == 0){
                strcpy(pInfo[playerid][pPorijeklo], "Hrvatska");
                PlayerTextDrawSetString(playerid, registracija[11][playerid], "Hrvatska");
            }
Reply
#10

Quote:
Originally Posted by ******
Посмотреть сообщение
Ahh, you can't do that with enums, strings inside them are not actually arrays. You would need:

pawn Код:
strcpy(gCountry[playerid], "Hrvatska");
The problem is that most people assume that arrays and things that look like arrays inside enums are the same and can be treated the same - they aren't and can't.
Thanks, i didn't know that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)