PDA

View Full Version : issue data file


rumen98
14/05/2014, 05:59 PM
new labeltext[80];
format(labeltext, sizeof(labeltext), "Building ID %d\nBuilding Level %d\nType /scavenge to Scavenge",ammunationid,store);
dini_Set(file, "BuildingName", labeltext);

here is the code I want to ask why result in my file is
BuildingName=Building ID 0
Building Level 1
Type /scavenge to Scavenge
and after reload when funcion try to load file and make 3DTextLabel
StoreLabel[dini_Int(file, "BuildingID")] = Create3DTextLabel(dini_Get(file, "BuildingName"), 0x00BC00FF, dini_Float(file, "CPOutX"), dini_Float(file, "CPOutY"), dini_Float(file, "CPOutZ")+0.7, 25, 0, 1);

only be charged
BuildingName=Building ID 0
without
Building Level 1
Type /scavenge to Scavenge

rumen98
15/05/2014, 08:55 PM
someone?

Sasino97
15/05/2014, 09:12 PM
The problem is that dini_Get is defined as:

stock dini_Get(filename[],key[]) {
new tmpres[DINI_MAX_STRING];

new key_length = strlen(key);
if (key_length==0 || key_length+2>DINI_MAX_STRING) return tmpres;

new File:fohnd;
fohnd=fopen(filename,io_read);
if (!fohnd) return tmpres;

while (fread(fohnd,tmpres)) {
if (
tmpres[key_length]=='='
&& !strcmp(tmpres, key, true, key_length)
) {
/* We've got what we need */
DINI_StripNewLine(tmpres);
strmid(tmpres, tmpres, key_length + 1, strlen(tmpres), DINI_MAX_STRING);
fclose(fohnd);
return tmpres;
}
}
fclose(fohnd);
return tmpres;
}
(at least the original one)

So it will read only one line.
I suggest you to do

new labeltext[80];
format(labeltext, sizeof(labeltext), "Building ID %d#Building Level %d#Type /scavenge to Scavenge",ammunationid,store);
dini_Set(file, "BuildingName", labeltext); // changed \n to #

So your file will be saved like this
BuildingName=Building ID 0#Building Level 1#Type /scavenge to Scavenge

but then when creating the label we will convert a # to a \n


new labelname[32];
labelname = dini_Get(file, "BuildingName");
str_replace("#", "\n", labelname);

StoreLabel[dini_Int(file, "BuildingID")] = Create3DTextLabel(labelname, 0x00BC00FF, dini_Float(file, "CPOutX"), dini_Float(file, "CPOutY"), dini_Float(file, "CPOutZ")+0.7, 25, 0, 1);



And define this stock function (from strlib by westie) (http://forum.sa-mp.com/showthread.php?t=85697)
stock str_replace(sSearch[], sReplace[], const sSubject[], &iCount = 0)
{
new
iLengthTarget = strlen(sSearch),
iLengthReplace = strlen(sReplace),
iLengthSource = strlen(sSubject),
iItterations = (iLengthSource - iLengthTarget) + 1;

new
sTemp[128],
sReturn[_strlib_med_string];

strcat(sReturn, sSubject, _strlib_med_string);
iCount = 0;

for(new iIndex; iIndex < iItterations; ++iIndex)
{
strmid(sTemp, sReturn, iIndex, (iIndex + iLengthTarget), (iLengthTarget + 1));

if(!strcmp(sTemp, sSearch, false))
{
strdel(sReturn, iIndex, (iIndex + iLengthTarget));
strins(sReturn, sReplace, iIndex, iLengthReplace);

iIndex += iLengthTarget;
iCount++;
}
}

return sReturn;
}

I hope I was helpful :)

rumen98
15/05/2014, 09:23 PM
D:\Downloads\ZombieWorld\pawno\include\SRB.inc(227 ) : error 047: array sizes do not match, or destination array is too small
D:\Downloads\ZombieWorld\pawno\include\SRB.inc(268 ) : error 017: undefined symbol "_strlib_med_string"
D:\Downloads\ZombieWorld\pawno\include\SRB.inc(268 ) : error 009: invalid array size (negative, zero or out of bounds)
D:\Downloads\ZombieWorld\pawno\include\SRB.inc(268 ) : warning 217: loose indentation
D:\Downloads\ZombieWorld\pawno\include\SRB.inc(268 ) : error 036: empty statement
D:\Downloads\ZombieWorld\pawno\include\SRB.inc(268 ) : fatal error 107: too many error messages on one line

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


5 Errors.

I get these errors
Here is the code from line 266 to 270
new
sTemp[128],
sReturn[_strlib_med_string];

strcat(sReturn, sSubject, _strlib_med_string);

Sasino97
15/05/2014, 09:28 PM
sorry for that, I didn't test it, then try to download the full library (http://forum.sa-mp.com/showthread.php?t=85697) and include it in your script

rumen98
15/05/2014, 09:33 PM
D:\Downloads\ZombieWorld\filterscripts\reality.pwn (392) : error 047: array sizes do not match, or destination array is too small
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


1 Error.

Line 392
labelname = dini_Get(file, "BuildingName");


Edit:
I fixed it, I found the error just changed
new labelname[32];
to
new labelname[256];

rumen98
16/05/2014, 06:50 PM
I do not know what happens now, but do not want to replace the # with \n