 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue May 16, 2006 12:08 am Post subject: if statements don't work very well what am i doing wrong? |
|
|
Hi folks,
I have this function with some if statement see below:
| Code: | int GameEvents(void){
int test = 0;
if (BlockStatus[3] == 0 || BlockStatus[4] == 0){
//sprintf(sBuffer, "Begin: %i,%i,%i,%i", BlockStatus[1], BlockStatus[2], BlockStatus[3], BlockStatus[4]);
//DebugOutput(sBuffer);
if (iQuadPosY == 11) {
sprintf(sBuffer, "ELF IS GEKOZEN");
DebugOutput(sBuffer);
// if no blocks are changed yet then the quad is in its whole on the bottom
if (BlockStatus[3] == 0 && BlockStatus[4] == 0) {
iField[iQuadPosX + 1][12] = iCurrentQuad[3];
BlockStatus[3] = 1;
iField[iQuadPosX + 1][11] = iCurrentQuad[2];
BlockStatus[2] = 1;
iField[iQuadPosX][12] = iCurrentQuad[4];
BlockStatus[4] = 1;
iField[iQuadPosX][11] = iCurrentQuad[1];
BlockStatus[1] = 1;
CheckSurroundingField(iQuadPosX + 1, 12, iCurrentQuad[3]);
CheckSurroundingField(iQuadPosX + 1, 11, iCurrentQuad[2]);
CheckSurroundingField(iQuadPosX, 12, iCurrentQuad[4]);
CheckSurroundingField(iQuadPosX, 11, iCurrentQuad[1]);
sprintf(sBuffer, "(11) BEIDE 0: %i,%i,%i,%i", BlockStatus[1], BlockStatus[2], BlockStatus[3], BlockStatus[4]);
DebugOutput(sBuffer);
}
// only the left part is on the bottom
else if (BlockStatus[4] == 0 && BlockStatus[3] == 1) {
iField[iQuadPosX][12] = iCurrentQuad[4];
BlockStatus[4] = 1;
iField[iQuadPosX][11] = iCurrentQuad[1];
BlockStatus[1] = 1;
CheckSurroundingField(iQuadPosX, 12, iCurrentQuad[4]);
CheckSurroundingField(iQuadPosX, 11, iCurrentQuad[1]);
sprintf(sBuffer, "(11) BLOK 4: %i,%i,%i,%i", BlockStatus[1], BlockStatus[2], BlockStatus[3], BlockStatus[4]);
DebugOutput(sBuffer);
}
// only the right part is on the bottom
else if (BlockStatus[4] == 1 && BlockStatus[3] == 0) {
iField[iQuadPosX + 1][12] = iCurrentQuad[3];
BlockStatus[3] = 1;
iField[iQuadPosX + 1][11] = iCurrentQuad[2];
BlockStatus[2] = 1;
CheckSurroundingField(iQuadPosX + 1, 12, iCurrentQuad[3]);
CheckSurroundingField(iQuadPosX + 1, 11, iCurrentQuad[2]);
sprintf(sBuffer, "(11) BLOK 3: %i,%i,%i,%i", BlockStatus[1], BlockStatus[2], BlockStatus[3], BlockStatus[4]);
DebugOutput(sBuffer);
}
iControllable = 1;
}
else {
//sprintf(sBuffer, "NIET ELF GEKOZEN: %i,%i,%i,%i", BlockStatus[1], BlockStatus[2], BlockStatus[3], BlockStatus[4]);
//DebugOutput(sBuffer);
if (iField[iQuadPosX + 1][iQuadPosY + 2] > 0 && iField[iQuadPosX][iQuadPosY + 2] > 0 && BlockStatus[3] == 0 && BlockStatus[4] == 0){
iField[iQuadPosX + 1][iQuadPosY + 1] = iCurrentQuad[3];
BlockStatus[3] = 1;
iField[iQuadPosX + 1][iQuadPosY] = iCurrentQuad[2];
BlockStatus[2] = 1;
iField[iQuadPosX][iQuadPosY + 1] = iCurrentQuad[4];
BlockStatus[4] = 1;
iField[iQuadPosX][iQuadPosY] = iCurrentQuad[1];
BlockStatus[1] = 1;
CheckSurroundingField(iQuadPosX + 1, iQuadPosY + 1, iCurrentQuad[3]);
CheckSurroundingField(iQuadPosX + 1, iQuadPosY, iCurrentQuad[2]);
CheckSurroundingField(iQuadPosX, iQuadPosY + 1, iCurrentQuad[4]);
CheckSurroundingField(iQuadPosX, iQuadPosY, iCurrentQuad[1]);
iControllable = 1;
sprintf(sBuffer, "(?) BEIDE 0: %i,%i,%i,%i", BlockStatus[1], BlockStatus[2], BlockStatus[3], BlockStatus[4]);
DebugOutput(sBuffer);
}
else if (iField[iQuadPosX + 1][iQuadPosY + 2] > 0 && iField[iQuadPosX][iQuadPosY + 2] == 0 && BlockStatus[3] == 0 && BlockStatus[4] == 0) {
iField[iQuadPosX + 1][iQuadPosY + 1] = iCurrentQuad[3];
BlockStatus[3] = 1;
iField[iQuadPosX + 1][iQuadPosY] = iCurrentQuad[2];
BlockStatus[2] = 1;
CheckSurroundingField(iQuadPosX + 1, iQuadPosY + 1, iCurrentQuad[3]);
CheckSurroundingField(iQuadPosX + 1, iQuadPosY, iCurrentQuad[2]);
iControllable = 1;
sprintf(sBuffer, "(?1) BLOK 3: %i,%i,%i,%i", BlockStatus[1], BlockStatus[2], BlockStatus[3], BlockStatus[4]);
DebugOutput(sBuffer);
test = 1;
}
else if (iField[iQuadPosX + 1][iQuadPosY + 2] == 0 && iField[iQuadPosX][iQuadPosY + 2] > 0 && BlockStatus[3] == 0 && BlockStatus[4] == 0) {
iField[iQuadPosX][iQuadPosY + 1] = iCurrentQuad[4];
BlockStatus[4] = 1;
iField[iQuadPosX][iQuadPosY] = iCurrentQuad[1];
BlockStatus[1] = 1;
CheckSurroundingField(iQuadPosX, iQuadPosY + 1, iCurrentQuad[4]);
CheckSurroundingField(iQuadPosX, iQuadPosY, iCurrentQuad[1]);
iControllable = 1;
sprintf(sBuffer, "(?1) BLOK 4: %i,%i,%i,%i", BlockStatus[1], BlockStatus[2], BlockStatus[3], BlockStatus[4]);
DebugOutput(sBuffer);
}
else if (iField[iQuadPosX][iQuadPosY + 2] > 0 && BlockStatus[3] == 1 && BlockStatus[4] == 0) {
iField[iQuadPosX][iQuadPosY + 1] = iCurrentQuad[4];
BlockStatus[4] = 1;
iField[iQuadPosX][iQuadPosY] = iCurrentQuad[1];
BlockStatus[1] = 1;
CheckSurroundingField(iQuadPosX, iQuadPosY + 1, iCurrentQuad[4]);
CheckSurroundingField(iQuadPosX, iQuadPosY, iCurrentQuad[1]);
iControllable = 1;
sprintf(sBuffer, "(?2) BLOK 4: %i,%i,%i,%i", BlockStatus[1], BlockStatus[2], BlockStatus[3], BlockStatus[4]);
DebugOutput(sBuffer);
}
else if (iField[iQuadPosX + 1][iQuadPosY + 2] > 0 && BlockStatus[3] == 0 && BlockStatus[4] == 1) {
iField[iQuadPosX + 1][iQuadPosY + 1] = iCurrentQuad[3];
BlockStatus[3] = 1;
iField[iQuadPosX + 1][iQuadPosY] = iCurrentQuad[2];
BlockStatus[2] = 1;
CheckSurroundingField(iQuadPosX + 1, iQuadPosY + 1, iCurrentQuad[3]);
CheckSurroundingField(iQuadPosX + 1, iQuadPosY, iCurrentQuad[2]);
iControllable = 1;
sprintf(sBuffer, "(?2) BLOK 3: %i,%i,%i,%i", BlockStatus[1], BlockStatus[2], BlockStatus[3], BlockStatus[4]);
DebugOutput(sBuffer);
}
else {}
if (test == 1) {
sprintf(sBuffer, "NO ELF2: %i,%i,%i,%i", BlockStatus[1], BlockStatus[2], BlockStatus[3], BlockStatus[4]);
DebugOutput(sBuffer);
}
if (iControllable == 0) {
if (iDropSpeed == 40){
iQuadPosY += 1;
iDropSpeed = 0;
}
else { iDropSpeed += 1;}
}
else {
if (iDropSpeed == 10){
iQuadPosY += 1;
iDropSpeed = 0;
}
else { iDropSpeed += 1;}
}
if (test == 1) {
sprintf(sBuffer, "DROP GEDAAN: %i,%i,%i,%i", BlockStatus[1], BlockStatus[2], BlockStatus[3], BlockStatus[4]);
DebugOutput(sBuffer);
}
}
}
else {
sprintf(sBuffer, "CHECK: %i,%i,%i,%i", BlockStatus[1], BlockStatus[2], BlockStatus[3], BlockStatus[4]);
DebugOutput(sBuffer);
if (BlockStatus[3] == 1) {
if (BlockStatus[2] == 1) {
if (BlockStatus[1] == 1) {
if (BlockStatus[4] == 1) {
sprintf(sBuffer, "CHECK OKAY: %i,%i,%i,%i", BlockStatus[1], BlockStatus[2], BlockStatus[3], BlockStatus[4]);
DebugOutput(sBuffer);
BlockStatus[1] = 0;
BlockStatus[2] = 0;
BlockStatus[3] = 0;
BlockStatus[4] = 0;
GameCreateQuad();
return 0;
}
}
}
}
}
if (test == 1) {
sprintf(sBuffer, "EINDE FUNCTIE: %i,%i,%i,%i", BlockStatus[1], BlockStatus[2], BlockStatus[3], BlockStatus[4]);
DebugOutput(sBuffer);
}
/*if (iMessageShow == 1){
if (iMessageDuration < 120) {
iMessageDuration += 1;
}
else { iMessageShow = 0; iMessageDuration = 0;}
}*/
return 0;
} |
if you look at the code i give somewhere the test integer the value 1.
BlockStatus[4] is at this time 0, when this happens it goes to the if statement where the "NO ELF2" is passed to the debugfunction then suddenly BlockStatus[4] == 1 why is this? _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
PlayfulPuppy
Joined: 05 May 2006 Posts: 22
|
Posted: Tue May 16, 2006 9:17 am Post subject: |
|
|
I can think of 2 possible reasons:
First of all, by the looks of it you're using your arrays as 1 based, when in C/C++ they're zero based. For example, if you do 'char buffer[4]', the valid indicies to buffer are 0 to 3. 4 is going past the end of the array (So you'd be reading/writing the next element in memory past the array). This is because it's elements, because 0 counts as an element.
The other option is that sBuffer isn't large enough and you're writing past the end of array, which is writing over some of the data in your buffers. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|