Variable loosing content -
Xamxe - 04.02.2012
This is part of the function witch is called in OnDialogResponse callback.
The problem is that when I fill binaryPanels I lost contents of binaryDoors.
What is the problem ?
Код:
new binaryDoors[32], binaryPanels[32], decimal, exponent = 1, j;
GetVehicleDamageStatus(tveh+1, gVehData[tveh][CarPanels], gVehData[tveh][CarDoors], gVehData[tveh][CarLights], gVehData[tveh][CarTires]);
for(j = 0; j < sizeof(binaryDoors); j++)
{
if(gVehData[tveh][CarDoors] & exponent)
strins(binaryDoors, "1", 0, sizeof(binaryDoors));
else
strins(binaryDoors, "0", 0, sizeof(binaryDoors));
exponent = (2 * exponent);
}
printf("1. binaryDoors = %s", binaryDoors);
printf("1. binaryPanels = %s", binaryPanels);
exponent = 1;
for(j = 0; j < sizeof(binaryPanels); j++)
{
if(gVehData[tveh][CarPanels] & exponent)
strins(binaryPanels, "1", 0, sizeof(binaryPanels));
else
strins(binaryPanels, "0", 0, sizeof(binaryPanels));
exponent = (2 * exponent);
}
printf("2. binaryDoors = %s", binaryDoors);
printf("2. binaryPanels = %s", binaryPanels);
Re: Variable loosing content -
Xamxe - 04.02.2012
anyone??
plz help
Re: Variable loosing content -
ғαιιοцт - 04.02.2012
Are you really sure about that?! That's really weird!
So the output is twice different?
Re: Variable loosing content -
Xamxe - 04.02.2012
On 1. printf of binaryDoors it shows 32 chars
On 2. printf of binaryDoors variable is empty...
Re: Variable loosing content -
ғαιιοцт - 05.02.2012
You are sure that you need & there and not && right?
Re: Variable loosing content -
MP2 - 05.02.2012
Quote:
Originally Posted by ғαιιοцт
You are sure that you need & there and not && right?
|
It's a bitwise operator.
AW: Re: Variable loosing content -
Nero_3D - 05.02.2012
I dont know why binaryDoors is empty afterwards
But there is a much easier version
pawn Код:
//
new
binaryDoors[33], // 33 because 32 bits + EOS
binaryPanels[sizeof binaryDoors]
;
GetVehicleDamageStatus((tveh + 1),
gVehData[tveh][CarPanels],
gVehData[tveh][CarDoors],
gVehData[tveh][CarLights],
gVehData[tveh][CarTires]
);
format(binaryDoors, sizeof binaryDoors, "%032b", gVehData[tveh][CarDoors]);
format(binaryPanels, sizeof binaryPanels, "%032b", gVehData[tveh][CarPanels]);
printf("binaryDoors = %s", binaryDoors);
printf("binaryPanels = %s", binaryPanels);
Re: Variable loosing content -
ғαιιοцт - 05.02.2012
Quote:
Originally Posted by MP2
It's a bitwise operator.
|
I vever use them. I'll go look up what they are good for ^^
I already read some stuff but I don't see what they're good for.
The article sais that & is the same as &&
But && will not check the right statement if the left one is already false.
So why would & check the right statement? What's the use for that if the left one is already false??