Variable loosing content
#1

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);
Reply
#2

anyone??
plz help
Reply
#3

Are you really sure about that?! That's really weird!
So the output is twice different?
Reply
#4

On 1. printf of binaryDoors it shows 32 chars
On 2. printf of binaryDoors variable is empty...
Reply
#5

You are sure that you need & there and not && right?
Reply
#6

Quote:
Originally Posted by ғαιιοцт
Посмотреть сообщение
You are sure that you need & there and not && right?
It's a bitwise operator.
Reply
#7

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);
Reply
#8

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??
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)