PDA

View Full Version : strreplace problem


antonio600x
30/08/2011, 11:58 AM
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(191) : error 035: argument type mismatch (argument 2)
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(192) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(402) : error 025: function heading differs from prototype
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(403) : error 021: symbol already defined: "strreplace"
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(411) : warning 209: function "strreplace" should return a value
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.



public OnPlayerText(playerid, text[])
{
new pname[MAX_PLAYER_NAME], str[128];
GetPlayerName(playerid, pname, sizeof(pname));
strreplace(pname, '_', ' ');/191
format(str, sizeof(str), "%s says: %s", pname, text);.
ProxDetector(30.0, playerid, str, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3, COLOR_FADE4, COLOR_FADE5);
return 0;
}


stock strreplace(string[], find, replace)//402
{//403
for(new i=0; string[i]; i++)
{
if(string[i] == find)
{
string[i] = replace;
}
}
}//411


how to fix that?

Pinguinn
30/08/2011, 12:00 PM
You have already 'strreplace', but try this


stock strreplace(string[], find, replace)
{
for(new i=0; string[i]; i++)
{
if(string[i] == find)
{
string[i] = replace;
}
}
return replace;
}

antonio600x
30/08/2011, 12:03 PM
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(191) : error 035: argument type mismatch (argument 2)
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(192) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(402) : error 025: function heading differs from prototype
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(403) : error 021: symbol already defined: "strreplace"
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(411) : error 079: inconsistent return types (array & non-array)

JaTochNietDan
30/08/2011, 12:18 PM
You could easily use the standard strfind (http://wiki.sa-mp.com/wiki/Strfind) function to do the same thing, for example:

public OnPlayerText(playerid, text[])
{
new pname[MAX_PLAYER_NAME], str[128];
GetPlayerName(playerid, pname, sizeof(pname));

pname[strfind(pname, "_", false)] = ' '; // Find the location of _ in the array and replace it with a space!

format(str, sizeof(str), "%s says: %s", pname, text);
ProxDetector(30.0, playerid, str, COLOR_FADE1, COLOR_FADE2, COLOR_FADE3, COLOR_FADE4, COLOR_FADE5);
return 0;
}

Simple as that, no need for a custom function!

antonio600x
30/08/2011, 12:26 PM
C:\Documents and Settings\Administrator\Desktop\SAMP SERVER\gamemodes\gmbeta.pwn(195) : error 029: invalid expression, assumed zero


format(str, sizeof(str), "%s kaze: %s", pname, text);.

JaTochNietDan
30/08/2011, 12:54 PM
Is that a full stop that's in your code too after the semi colon? Or did you just write it in the post, I suggest using pawn BBCode in future to make it easier to see.

Anyway, there shouldn't be a fullstop there.