[Solved (properbly)]FloatArray get strange values -
Falco-Ger - 26.04.2012
Hi guys,
i am to make a dynamic property system filterscript for a reallife server, but i got some wired problems...
when i read out a float from string with sscanf with the "f" it seems allright. when i print it with printf("%f", value) it shows up correctly.
but when i do something like
new Float:temp = value;
printf("%f", temp);
it shows extraordinary high numbers?!
global:
Код:
#define MAXPROPETIES 100
Float:PropDataF[MAXPROPERTIES][6];
enum
{
PWORLDX,
PWORLDY,
PWORLDZ,
PINTX,
PINTY,
PINTZ
}
in ReadFile(), own function
Код:
while (fread(FHandle,Prop))
{
printf("Reading Line %i: %s", i+1, Prop);
if(sscanf(Prop,"ffffffdddddssssssssss"
, PropDataF[j][PWORLDX], PropDataF[j][PWORLDY], PropDataF[j][PWORLDZ]
, PropDataF[j][PINTX], PropDataF[j][PINTY], PropDataF[j][PINTZ]
, PropDataI[j][PINTID], PropDataI[j][PPRICE]
, PropDataI[j][PLEVEL], PropDataI[j][PRENT], PropDataI[j][PMAXIN]
, PropDataS[j][0], PropDataS[j][1], PropDataS[j][2], PropDataS[j][3], PropDataS[j][4]
, PropDataS[j][5], PropDataS[j][6], PropDataS[j][7], PropDataS[j][8], PropDataS[j][9]
) )
{
printf ("invalid format in line %i: %s", i, Prop);
PropDataB[i] = false;
}
else
{
printf ("Property Loaded into memory: ID: %i", j);
fwrite(FBackupHandle, Prop);
PropDataB[j] = true;
j = j+1;
if (j >= MAXPROPERTIES)
{
break;
}
}
i = i+1;
}
Example Line: 427.896759 2532.036132 16.600128 225.630996 1022.479980 1084.069946 7 20000 2 500 4 Falco NOONE NOONE NOONE NOONE NOONE NOONE NOONE NOONE NOONE
in OnPlayerKeyStateChange (but shouldn't matter where)
Код:
new Float:tempx = PropDataF[i][PWORLDX],
Float:tempy = PropDataF[i][PWORLDY],
Float:tempz = PropDataF[i][PWORLDZ];
printf("temp values are: %f %f %f",tempx, tempy, tempz);
printf("printing with printf shows %f %f %f", PropDataF[i][PWORLDX], PropDataF[i][PWORLDY], PropDataF[i][PWORLDZ]);
example console output is:
Код:
temp values are: 1137971712.000000 1159627392.000000 1098985472.000000
printing with printf shows 424.142181 2536.166015 16.148437
strangely enough i get this output when compiling, guess thats related to that dump values i get
Код:
...\filterscripts\easyprop.pwn(269) : warning 213: tag mismatch
...\filterscripts\easyprop.pwn(269) : warning 213: tag mismatch
...\filterscripts\easyprop.pwn(269) : warning 213: tag mismatch
...\filterscripts\easyprop.pwn(667) : warning 213: tag mismatch
...\filterscripts\easyprop.pwn(714) : warning 213: tag mismatch
the lines
Код:
269 - GetPlayerPos(playerid, PropDataF[ID][PWORLDX], PropDataF[ID][PWORLDY], PropDataF[ID][PWORLDZ]);
667 - printf("creating 3DText %i for property %i at %f %f %f: %s", Prop3DText[i], i, PropDataF[i][PWORLDX],
PropDataF[i][PWORLDY], PropDataF[i][PWORLDZ], str);
714 - printf("creating 3DText %i for property %i at %f %f %f: %s", Prop3DText[ID], ID, PropDataF[ID][PWORLDX],
PropDataF[ID][PWORLDY], PropDataF[ID][PWORLDZ], str);
but no such warnings for things like
Код:
Prop3DText[ID] = Create3DTextLabel(str, 0xFFFFFFAA
, PropDataF[ID][PWORLDX], PropDataF[ID][PWORLDY], PropDataF[ID][PWORLDZ], 500.0, true);
edit: sorry, that tab layout in the bb code thingy, it's better in my pawno editor
edit2: i guess 2 of theese warnings are because Text3D is no integer i should print with printf, but no static_cast in that c(?) language. anyone know how i can force it cast to integer so that it doesn't give me a warning for such things?
Re: FloatArray get strange values -
MP2 - 26.04.2012
Use float() to turn an integer in to a float.
pawn Код:
new myInt = 69;
new Float:myFloat = float(myint);
If you need to turn a string in to a float, use floatstr().
To turn a float in to an integer, use floatround() (rounds up).
Re: FloatArray get strange values -
Falco-Ger - 26.04.2012
sscanf should do that automaticaly, doesn't it?
i think the reason for the strange behavior are somewhere else. why do i get the first 3 warnings shown in the compiler output.
any why does printf shows the correct values whereas saving them somewhere else first, and then print it shows something very dump?
i now tripple checked for overwriting arrays out of bounds. found nothing but maybe im just blind.
Re: FloatArray get strange values -
Falco-Ger - 27.04.2012
enum
{
a,
b,
c,
ect...
}
just declares variables and initializes them with 0, then 1, 2, 3 and so on? why would i not use enums just like numbers for arrays with names i can remember?
anyway printing those out gives me 0, 1, 2 and so on.
i use 2 enums.
i use 2 arrays because i can not define one array with like 8 integer variables, and then 6 float variables
![undecided](images/smilies/neutral.gif)
propdatas is for strings, works good for me
how would you declare an array using enums?
new array[3] creates array[0], array[1] and array[2], i dont get your point
again, what should i do with an enum in sscanf, it's only names for counting numbers
i DO know that pawn is far from c and i hate that
i DO know about warnings, and i can usualy fix them, because i can't in THIS case i am asking you
your link doesn't explain anything about enums, just some kind of printf trick stuff, that i dont need
Re: FloatArray get strange values -
Falco-Ger - 27.04.2012
fine then, ill #define those as numbers, i guess when i do so you tell me that everything will work
edit:
wtf... i dont get it but now i know that ill never use enums again...
when they use keywords from c and c++ they should do the same thing for the sake of mankind and sanity
thanks anyway...
Re: FloatArray get strange values -
Falco-Ger - 27.04.2012
my identation is allright, the bb code just puts my 4 space tabs from pawno to 8 spaces in the web browser
for long lines i use tabs like this
Код:
FunctionWithAShitLoadOfArguments(ArgumentNameThatIsReallyLong1, ArgumentNameThatIsReallyLong2
, ArgumentNameThatIsReallyLong3, ArgumentNameThatIsReallyLong4
, ArgumentNameThatIsReallyLong5, ArgumentNameThatIsReallyLong6
);
so i dont have to scroll 3 meters to the right to see the code and for reasons of visibility
the rest is ****ed up because i just copy + paste it here and i didn't bother to remove tabs that i put because it's in a control structure like if/for/while/etc
sorry for that, again
anyway thanks for the help.
Re: FloatArray get strange values -
Falco-Ger - 27.04.2012
SOLVED
Edit: why the hell does that have to be on the second page