save data to string
#1

Код:
public Update(index, response_code, data[])
{
    if(response_code == 200)
    {
		**save 'date' to string
    }
}
^^ i got one small problem, i would like to know how to save 'data' to string.
Reply
#2

It depends on what you want to do with it. If you want to store the data to a global variable (for everyone) then:
pawn Код:
// global:
new Update_data[128];
and to copy a string to another:
pawn Код:
strcpy(Update_data, data, 128);
and the macro:
pawn Код:
#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)
However, if you wanted to save each data for a different player, then you'd need to use 1 more dimension for the playerid.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
It depends on what you want to do with it. If you want to store the data to a global variable (for everyone) then:
pawn Код:
// global:
new Update_data[128];
and to copy a string to another:
pawn Код:
strcpy(Update_data, data, 128);
and the macro:
pawn Код:
#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)
However, if you wanted to save each data for a different player, then you'd need to use 1 more dimension for the playerid.
ok, thx, but i still get a error, can i send you code in PM? it's only 103 lines, please
Reply
#4

Post the error code and line here instead.
Reply
#5

Код:
C:\Users\Ronaldo\Music\Bass\samp03z_svr_R1_win32\filterscripts\CreamyProtection.pwn(94) : error 033: array must be indexed (variable "Update_data")
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Reply
#6

The error itself says nothing. You need to post the line 94 as well as how you declared Update_data.
Reply
#7

iiii
Reply
#8

I asked for the error code and line. Anyways, the line is:
pawn Код:
if(Update_data > CP_VERSION)
Update_data is string and it uses indexes. You try to compare it like an integer without an index too which is incorrect.
You can compare it like string (strcmp) and send a message that the version does not match the latest one which is the simpler way.

If you want to check if the greater version, then again it depends on the version. How is it supposed to be? So I can tell you how to compare it.

PS: You need to use format to pass the version in the string.
Reply
#9

the version is 1.0

You can compare it like string (strcmp) and send a message that the version does not match the latest one which is the simpler way.

^^ahh, ok, i'l do this, thx
Reply
#10

Comparing the strings (equal or not equal):
pawn Код:
if (strcmp(Update_data, CP_VERSION))
{
    // versions do not match
}
Assuming CP_VERSION is defined as:
pawn Код:
#define CP_VERSION "1.0"
and it returns a version as x.y (x and y are values between 0 and 9).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)