PDA

View Full Version : First time scripting


YahyaBR
02/03/2013, 09:21 AM
Hello, this is my first scripting experience
im very very noob :(
i follow this tutorial http://www.youtube.com/watch?v=4Qe6NbLm5bc
i did everything in that video but i got this error when compiling

D:\Bart\Samp Server\gamemodes\Test Gaemode.pwn(50) : error 001: expected token: "-string end-", but found "-identifier-"
D:\Bart\Samp Server\gamemodes\Test Gaemode.pwn(50) : error 029: invalid expression, assumed zero
D:\Bart\Samp Server\gamemodes\Test Gaemode.pwn(50) : error 029: invalid expression, assumed zero
D:\Bart\Samp Server\gamemodes\Test Gaemode.pwn(50) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
i tried to delete the line 029 but it still giving an error of it
this is the link of my full gamemode http://pastebin.com/zj31yFqR
and please tell me some links that provide a better scripting tutorial. thanks for your help :)

ikey07
02/03/2013, 09:29 AM
Error is at 50 line, not 029, 029 is a error code

SilverKiller
02/03/2013, 09:33 AM
SendClientMessage(playerid, COLOR_BLACK, "Welcome to test server");

YahyaBR
02/03/2013, 09:44 AM
Error is at 50 line, not 029, 029 is a error code
lol my epic fail :facepalm:
now i have fixed those but i got this error in this line
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/test", cmdtext, true, 10) == 0)
{
SendClientMessage(playerid, COLOR_BLACK, "[BR]Yahya__");
SendClientMessage(playerid, COLOR_BLACK, "[BR]Yahya__");
return 1;
}
return 0;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/fix", cmdtext, true, 10) == 0)
{
RepairVehicle(vehicleid);
return 1;
}
return 0;
}

it said the "OnPlayerCommandText" symbol is already defined, so i removed the Onplayercommandtext

and become like this public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/test", cmdtext, true, 10) == 0)
{
SendClientMessage(playerid, COLOR_BLACK, "[BR]Yahya__");
SendClientMessage(playerid, COLOR_BLACK, "[BR]Yahya__");
return 1;
}
return 0;

{
RepairVehicle(vehicleid);
return 1;
}
return 0;
}
but i got those errors
D:\Bart\Samp Server\gamemodes\Test Gaemode.pwn(94) : warning 225: unreachable code
D:\Bart\Samp Server\gamemodes\Test Gaemode.pwn(95) : error 017: undefined symbol "vehicleid"
D:\Bart\Samp Server\gamemodes\Test Gaemode.pwn(98) : warning 225: unreachable code
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


1 Error.

what does the unreacheable code mean, and why the vehicleid is undefined?
thank you before :)

AndreT
02/03/2013, 09:48 AM
Welcome to SA-MP forums, YahyaBR.

It is good that you've done enough research on your own and actually have gotten somewhere. And your script is a lot like with what I started up with 6 years ago. The error line is indeed line 50 in your posted script.

The syntax of SendClientMessage is SendClientMessage(playerid, color, message[]). This means that the first 2 parameters are integers (playerid and color - the second parameter is often used with a HEX representation, though) and the 3rd parameter (message) is supposed to be an array.
A string message such as "Hey!" is actually an array and after you write a message, the [] characters are not required any more.

Please make sure you go through the useful documentation provided at the wiki (wiki.sa-mp.com). Start off with the basics (http://wiki.sa-mp.com/wiki/Scripting_Basics).

// Edit: the problem in the second code is that you have 2 returns in the same code block. Returning means that the callback will stop processing the code. This is probably not what you want.

if(!strcmp(cmdtext, "/command", true))
{
// do something here...
}
return true;

// do something else here - but this code will generate a warning about unreachable code as you returned above! And this code won't be reached as the warning suggests.
return false;

SilverKiller
02/03/2013, 09:49 AM
RepairVehicle(GetPlayerVehicleID(playerid));

And for unreachable code, remove return 0 at test command, and then make the RepairVehicle fix command again.

Or just use my code:

public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/test", cmdtext, true, 10) == 0)
{
SendClientMessage(playerid, COLOR_BLACK, "[BR]Yahya__");
SendClientMessage(playerid, COLOR_BLACK, "[BR]Yahya__");
return 1;
}
if (strcmp("/fix", cmdtext, true, 10) == 0)
{
RepairVehicle(GetPlayerVehicleID(playerid));
return 1;
}
return 0;
}

YahyaBR
02/03/2013, 11:42 AM
Welcome to SA-MP forums, YahyaBR.

It is good that you've done enough research on your own and actually have gotten somewhere. And your script is a lot like with what I started up with 6 years ago. The error line is indeed line 50 in your posted script.

The syntax of SendClientMessage is SendClientMessage(playerid, color, message[]). This means that the first 2 parameters are integers (playerid and color - the second parameter is often used with a HEX representation, though) and the 3rd parameter (message) is supposed to be an array.
A string message such as "Hey!" is actually an array and after you write a message, the [] characters are not required any more.

Please make sure you go through the useful documentation provided at the wiki (wiki.sa-mp.com). Start off with the basics (http://wiki.sa-mp.com/wiki/Scripting_Basics).

// Edit: the problem in the second code is that you have 2 returns in the same code block. Returning means that the callback will stop processing the code. This is probably not what you want.

if(!strcmp(cmdtext, "/command", true))
{
// do something here...
}
return true;

// do something else here - but this code will generate a warning about unreachable code as you returned above! And this code won't be reached as the warning suggests.
return false;
Thank you very much for the explanation :D
but what should i do when im gonna add more command

EDIT:
this one answered my question :D
RepairVehicle(GetPlayerVehicleID(playerid));

And for unreachable code, remove return 0 at test command, and then make the RepairVehicle fix command again.

Or just use my code:

public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/test", cmdtext, true, 10) == 0)
{
SendClientMessage(playerid, COLOR_BLACK, "[BR]Yahya__");
SendClientMessage(playerid, COLOR_BLACK, "[BR]Yahya__");
return 1;
}
if (strcmp("/fix", cmdtext, true, 10) == 0)
{
RepairVehicle(GetPlayerVehicleID(playerid));
return 1;
}
return 0;
}
thanks for your guys helps :)