Unknown Command ??! -
nezo2001 - 09.01.2015
I made this command but when i use it it give me unknown command
PHP код:
CMD:createobject(playerid, params[])
{
new objectid;
new Float:x, Float:y, Float:z;
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You have to be Rcon Admin");
if(sscanf(params, "u", objectid)) return SendClientMessage(playerid, -1, "Usage: /crateobject (Object ID)");
new pos = GetPlayerPos(playerid, x, y, z);
CreateObject(objectid, x+2, y, z, 0.0, 0.0, 96.0);
new Float:X, Float:Y, Float:Z;
GetObjectPos(X, Y, Z);
new Float:b, Float:c, Float:d;
GetObjectRot(b, c, d);
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"Object");
INI_WriteInt(File,"Object ID",objectid);
INI_WriteInt(File,"XPos",X);
INI_WriteInt(File,"YPos",Y);
INI_WriteInt(File,"ZPos",Z);
INI_WriteInt(File,"XRot",b);
INI_WriteInt(File,"YRot",c);
INI_WriteInt(File,"ZRot",d);
INI_Close(File);
SendClientMessage(playerid, -1, "Object created");
return 1;
}
Please Help !!
Re: Unknown Command ??! -
CutX - 09.01.2015
Quote:
Originally Posted by nezo2001
I made this command but when i use it it give me unknown command
PHP код:
CMD:createobject(playerid, params[])
{
new objectid;
new Float:x, Float:y, Float:z;
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You have to be Rcon Admin");
if(sscanf(params, "u", objectid)) return SendClientMessage(playerid, -1, "Usage: /crateobject (Object ID)");
new pos = GetPlayerPos(playerid, x, y, z);
CreateObject(objectid, x+2, y, z, 0.0, 0.0, 96.0);
new Float:X, Float:Y, Float:Z;
GetObjectPos(X, Y, Z);
new Float:b, Float:c, Float:d;
GetObjectRot(b, c, d);
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"Object");
INI_WriteInt(File,"Object ID",objectid);
INI_WriteInt(File,"XPos",X);
INI_WriteInt(File,"YPos",Y);
INI_WriteInt(File,"ZPos",Z);
INI_WriteInt(File,"XRot",b);
INI_WriteInt(File,"YRot",c);
INI_WriteInt(File,"ZRot",d);
INI_Close(File);
SendClientMessage(playerid, -1, "Object created");
return 1;
}
Please Help !!
|
the identifier you declared for the file handler to be stored in is a tag.
identifiers may not be the same as keywords/tags or start with numbers or operators
just change "File" to "h" or something else
example for basic file I/O in pawn
Quote:
Originally Posted by wikisamp
pawn Код:
// Open "file.txt" in "write only" mode new File:handle = fopen("file.txt", io_write); // Check, if file is open if(handle) { // Success // Write "I just wrote here!" into this file fwrite(handle, "I just wrote here!"); // Close the file fclose(handle); } else { // Error print("Failed to open file \"file.txt\"."); }
|
Re: Unknown Command ??! -
nezo2001 - 09.01.2015
What i should write instead of these
PHP код:
file.txt", io_write
Re: Unknown Command ??! -
CutX - 09.01.2015
Quote:
Originally Posted by nezo2001
What i should write instead of these
PHP код:
file.txt", io_write
|
no.
you misunderstood.
variable names may not be the same as tags/keywords used by the compiler (like "case", "break", "File" and so on)
like said before, just change it.
you're using "File" as identifier but File is also at the same time a Tag.
so how could the compiler know what you meant there.
it can't, so it skips the code, nothing gets returned resulting in "Unknown command"
even though it's actually there. But couldn't return a value to prove its existence
Re: Unknown Command ??! -
nezo2001 - 09.01.2015
But here i want to create a new file not read or write only.
I am sorry if i didn't understand you !
Re: Unknown Command ??! -
CutX - 09.01.2015
Quote:
Originally Posted by nezo2001
But here i want to create a new file not read or write only.
I am sorry if i didn't understand you !
|
look, all you need to do is change "File" to something else.
you can't use "File" as identifier as it's already a tag (side note, it's a strong tag cuz it's starting with a capital letter)
see, ill do it for you...
pawn Код:
CMD:createobject(playerid, params[])
{
new objectid;
new Float:x, Float:y, Float:z;
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You have to be Rcon Admin");
if(sscanf(params, "u", objectid)) return SendClientMessage(playerid, -1, "Usage: /crateobject (Object ID)");
new pos = GetPlayerPos(playerid, x, y, z);
CreateObject(objectid, x+2, y, z, 0.0, 0.0, 96.0);
new Float:X, Float:Y, Float:Z;
GetObjectPos(X, Y, Z);
new Float:b, Float:c, Float:d;
GetObjectRot(b, c, d);
new INI:fh = INI_Open(UserPath(playerid));
INI_SetTag(fh,"Object");
INI_WriteInt(fh,"Object ID",objectid);
INI_WriteInt(fh,"XPos",X);
INI_WriteInt(fh,"YPos",Y);
INI_WriteInt(fh,"ZPos",Z);
INI_WriteInt(fh,"XRot",b);
INI_WriteInt(fh,"YRot",c);
INI_WriteInt(fh,"ZRot",d);
INI_Close(fh);
SendClientMessage(playerid, -1, "Object created");
return 1;
}
i called it "fh" which is a synonym for "file handler"
i myself usually just call them "h" but that doesn't matter.
Re: Unknown Command ??! -
nezo2001 - 09.01.2015
Ooh this is all the problem.....!
Thank you man
Re: Unknown Command ??! -
CutX - 09.01.2015
Quote:
Originally Posted by nezo2001
Ooh this is all the problem.....!
Thank you man
|
it worked?
can't be.
cuz i just double checked and i have to admit that it did
not test if you could actually name a variable after some tag.
now after some test runs i can say that
identifiers can be named after tags.
although its bad practice so i straight forward thought that's the cause.
well apparently, that works.
But using a keyword as identifier will cause
Код:
error 029: invalid expression, assumed zero
so thats that. sorry :/
soo back to the beginning.
i think that "UserPath(playerid)" returning
a invalid value (as in a non existing file path)
will definitely cause the code to stop
Re: Unknown Command ??! -
nezo2001 - 09.01.2015
Another thing for these
PHP код:
D:\MyServer\Server\filterscripts\createobject.pwn(33) : error 001: expected token: ";", but found "{"
D:\MyServer\Server\filterscripts\createobject.pwn(35) : error 010: invalid function or declaration
PHP код:
stock info
{
format(string,sizeof(string),PATH,"Object %i",object);
return string;
}
Re: Unknown Command ??! -
CutX - 09.01.2015
Quote:
Originally Posted by nezo2001
Another thing for these
PHP код:
D:\MyServer\Server\filterscripts\createobject.pwn(33) : error 001: expected token: ";", but found "{"
D:\MyServer\Server\filterscripts\createobject.pwn(35) : error 010: invalid function or declaration
PHP код:
stock info
{
format(string,sizeof(string),PATH,"Object %i",object);
return string;
}
|
pawn Код:
info(object)
{
new string[20];
format(string,sizeof(string),PATH"Object %i",object);
return string;
}
usage-example:
printf("info: %s",info(3));
prints: "info: path/Object 3"
if PATH is defined as "path/"
adjust the size of "string"
idk what PATH holds for you or how long it is.