Turn an integer into variable? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Turn an integer into variable? (
/showthread.php?tid=633624)
Turn an integer into variable? -
YouHack - 04.05.2017
Hi,
I'm trying to use an "if" statement with "data" in this code: ( From
HTTP in wiki )
PHP код:
forward MyHttpResponse(index, response_code, data[]);
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp("/hello",cmdtext,true))
{
HTTP(playerid, HTTP_GET, "kc.gd/hello.txt", "", "MyHttpResponse");
return 1;
}
return 0;
}
public MyHttpResponse(index, response_code, data[])
{
// In this callback "index" would normally be called "playerid" ( if you didn't get it already :) )
new
buffer[ 128 ];
if(response_code == 200) //Did the request succeed?
{
//Yes!
format(buffer, sizeof(buffer), "The URL replied: %s", data);
SendClientMessage(index, 0xFFFFFFFF, buffer);
}
else
{
//No!
format(buffer, sizeof(buffer), "The request failed! The response code was: %d", response_code);
SendClientMessage(index, 0xFFFFFFFF, buffer);
}
}
and it returns:
Код:
error 033: array must be indexed (variable "databody")
example of usage:
PHP код:
if(databody == -1){
thanks.
Re: Turn an integer into variable? -
Dignity - 04.05.2017
"databody" is an array, so you have to index it, like so:
If "databody" is meant to be a string, you can just do this to check whether it's empty or not:
pawn Код:
if ( ! strlen ( databody ) ) {
// code here to be called if databody is empty
}
also i'm pretty sure an integer IS a variable lol
Re: Turn an integer into variable? -
Vince - 04.05.2017
If your API always returns an integer then you can simply use strval(). Otherwise you need to use strcmp().
Re: Turn an integer into variable? -
YouHack - 04.05.2017
Databody hasn't just -1, it has 0 and 1 + between 0 and 1 ( decimal ) ...
Re: Turn an integer into variable? -
YouHack - 04.05.2017
Solved using strval(), thanks both.