PDA

View Full Version : int[x] Checks Bug? (Or maybe just not wrote up yet?)



Zim
01-03-2013, 03:34 AM
For some reason or another when I converted my massive calculator script into int[24] format instead of 25 separate integers, the script cannot do the checks.

if(N[0]==0&&N[1]==0&&N[2]==0&&N[3]==0&&N[4]==0&&N[5]==0&&N[6]==0&&N[7]==0&&N[8]==0&&N[9]==0&&N[10]==0&&N[11]==0&&N[12]==0&&N[13]==0&&N[14]==0&&N[15]==0&&N[16]==0&&N[17]==0&&N[18]==0&&N[19]==0&&N[20]==0&&N[21]==0&&N[22]==0&&N[23]==0&&N[24]==0){PB();return;}
Does not work, for example...
Whereas


if(N==0&&oK==0&&oM==0&&oB==0&&oT==0&&kN==0&&kK==0&&kM==0&&kB==0&&kT==0&&mN==0&&mK==0&&mM==0&&mB==0&&mT==0&&bN==0&&bK==0&&bM==0&&bB==0&&bT==0&&tN==0&&tK==0&&tM==0&&tB==0&&tT==0){PB();return;}

activated the PB() function just fine.
I don't know if this is a bug or something that ZC is just not capable of doing.. It's essentially the exact same thing, except one is 25 checks to the same array, and the other is 25 separate integers.
It would help out my game development very much to be able to do this check with one array instead of 25 separate integers!
Thanks for all your years of work into this already!

SUCCESSOR
01-03-2013, 05:11 AM
For some reason or another when I converted my massive calculator script into int[24] format instead of 25 separate integers, the script cannot do the checks.

if(N[0]==0&&N[1]==0&&N[2]==0&&N[3]==0&&N[4]==0&&N[5]==0&&N[6]==0&&N[7]==0&&N[8]==0&&N[9]==0&&N[10]==0&&N[11]==0&&N[12]==0&&N[13]==0&&N[14]==0&&N[15]==0&&N[16]==0&&N[17]==0&&N[18]==0&&N[19]==0&&N[20]==0&&N[21]==0&&N[22]==0&&N[23]==0&&N[24]==0){PB();return;}
Does not work, for example...


That is almost unreadable. Do something like this instead:


if(Ncheck()) PB();

//function that checks N[] array
bool Ncheck()
{
for(int i; i < 25; i++){
//if value is 0 keep going
if(N[i] == 0) continue;

//if not zero end function
return false;
}
//all values are 0 so return true
return true;

}

I use arrays like this and never have a problem. Double check the rest of your script and make sure nothing is saving data to the array and that the array is set up right.

EDIT: I copied the code you said didn't work(the condition of the if) and put it in a script that plays a sound if the condition is true and it worked fine. Something else in your script is going wrong.

int N[25];

global script test
{
void run()
{
while(N[0]==0&&N[1]==0&&N[2]==0&&N[3]==0&&N[4]==0&&N[5]==0&&N[6]==0&&N[7]==0&&N[8]==0&&N[9]==0&&N[10]==0&&N[11]==0&&N[12]==0&&N[13]==0&&N[14]==0&&N[15]==0&&N[16]==0&&N[17]==0&&N[18]==0&&N[19]==0&&N[20]==0&&N[21]==0&&N[22]==0&&N[23]==0&&N[24]==0){
Game->PlaySound(23);
Waitframe();
}
}
}

Zim
01-03-2013, 07:09 PM
[QUOTE=SUCCESSOR;893198]That is almost unreadable. Do something like this instead:


if(Ncheck()) PB();

//function that checks N[] array
bool Ncheck()
{
for(int i; i < 25; i++){
//if value is 0 keep going
if(N[i] == 0) continue;

//if not zero end function
return false;
}
//all values are 0 so return true
return true;

}
I can't do it like that because there's like 30 lines of code afterward that are the same thing but checking each one is >0...


if(mA && Cal==true)
{time+=15;
//This script block determines what happens to the numbers as the buttons are pressed on the keypad.
if(N[0]==0&&N[1]==0&&N[2]==0&&N[3]==0&&N[4]==0&&N[5]==0&&N[6]==0&&N[7]==0&&N[8]==0&&N[9]==0&&N[10]==0&&N[11]==0&&N[12]==0&&N[13]==0&&N[14]==0&&N[15]==0&&N[16]==0&&N[17]==0&&N[18]==0&&N[19]==0&&N[20]==0&&N[21]==0&&N[22]==0&&N[23]==0&&N[24]==0){PB();return;}
if(N[0]>0&&N[0]<10&&N[1]==0&&N[2]==0&&N[3]==0&&N[4]==0&&N[5]==0&&N[6]==0&&N[7]==0&&N[8]==0&&N[9]==0&&N[10]==0&&N[11]==0&&N[12]==0&&N[13]==0&&N[14]==0&&N[15]==0&&N[16]==0&&N[17]==0&&N[18]==0&&N[19]==0&&N[20]==0&&N[21]==0&&N[22]==0&&N[23]==0&&N[24]==0){N[0]=N[0]*10;PB();return;}
if(N[0]>=10&&N[0]<100&&N[1]==0&&N[2]==0&&N[3]==0&&N[4]==0&&N[5]==0&&N[7]==0&&N[8]==0&&N[9]==0&&N[10]==0&&N[11]==0&&N[12]==0&&N[13]==0&&N[14]==0&&N[15]==0&&N[16]==0&&N[17]==0&&N[18]==0&&N[19]==0&&N[20]==0&&N[21]==0&&N[22]==0&&N[23]==0&&N[24]==0){N[0]=N[0]*10;PB();return;}
if(N[0]>=100&&N[1]==0&&N[2]==0&&N[3]==0&&N[4]==0&&N[5]==0&&N[6]==0&&N[7]==0&&N[8]==0&&N[9]==0&&N[10]==0&&N[11]==0&&N[12]==0&&N[13]==0&&N[14]==0&&N[15]==0&&N[16]==0&&N[17]==0&&N[18]==0&&N[19]==0&&N[20]==0&&N[21]==0&&N[22]==0&&N[23]==0&&N[24]==0){N[1]=(N[0]-N[0]%100)/100;N[0]=(N[0]-(N[0]-N[0]%100))*10;PB();return;}
if(N[1]>0&&N[1]<10&&N[2]==0&&N[3]==0&&N[4]==0&&N[5]==0&&N[6]==0&&N[7]==0&&N[8]==0&&N[9]==0&&N[10]==0&&N[11]==0&&N[12]==0&&N[13]==0&&N[14]==0&&N[15]==0&&N[16]==0&&N[17]==0&&N[18]==0&&N[19]==0&&N[20]==0&&N[21]==0&&N[22]==0&&N[23]==0&&N[24]==0){N[1]=N[1]*10;N[1]+=(N[0]-N[0]%100)/100;N[0]=(N[0]-(N[0]-N[0]%100))*10;PB();return;}
if(N[1]>=10&&N[1]<100&&N[2]==0&&N[3]==0&&N[4]==0&&N[5]==0&&N[6]==0&&N[7]==0&&N[8]==0&&N[9]==0&&N[10]==0&&N[11]==0&&N[12]==0&&N[13]==0&&N[14]==0&&N[15]==0&&N[16]==0&&N[17]==0&&N[18]==0&&N[19]==0&&N[20]==0&&N[21]==0&&N[22]==0&&N[23]==0&&N[24]==0){N[1]=N[1]*10;N[1]+=(N[0]-N[0]%100)/100;N[0]=(N[0]-(N[0]-N[0]%100))*10;PB();return;}
if(N[1]>=100&&N[2]==0&&N[3]==0&&N[4]==0&&N[5]==0&&N[6]==0&&N[7]==0&&N[8]==0&&N[9]==0&&N[10]==0&&N[11]==0&&N[12]==0&&N[13]==0&&N[14]==0&&N[15]==0&&N[16]==0&&N[17]==0&&N[18]==0&&N[19]==0&&N[20]==0&&N[21]==0&&N[22]==0&&N[23]==0&&N[24]==0){N[2]=(N[1]-N[1]%100)/100;N[1]=(N[1]-(N[1]-N[1]%100))*10+(N[0]-N[0]%100)/100;N[0]=(N[0]-(N[0]-N[0]%100))*10;PB();return;}
if(N[2]>0&&N[2]<10&&N[3]==0&&N[4]==0&&N[5]==0&&N[6]==0&&N[7]==0&&N[8]==0&&N[9]==0&&N[10]==0&&N[11]==0&&N[12]==0&&N[13]==0&&N[14]==0&&N[15]==0&&N[16]==0&&N[17]==0&&N[18]==0&&N[19]==0&&N[20]==0&&N[21]==0&&N[22]==0&&N[23]==0&&N[24]==0){N[2]=N[2]*10;N[2]+=(N[1]-N[1]%100)/100;N[1]=(N[1]-(N[1]-N[1]%100))*10+(N[0]-N[0]%100)/100;N[0]=(N[0]-(N[0]-N[0]%100))*10;PB();return;}
if(N[2]>=10&&N[2]<100&&N[3]==0&&N[4]==0&&N[5]==0&&N[6]==0&&N[7]==0&&N[8]==0&&N[9]==0&&N[10]==0&&N[11]==0&&N[12]==0&&N[13]==0&&N[14]==0&&N[15]==0&&N[16]==0&&N[17]==0&&N[18]==0&&N[19]==0&&N[20]==0&&N[21]==0&&N[22]==0&&N[23]==0&&N[24]==0){N[2]=N[2]*10;N[2]+=(N[1]-N[1]%100)/100;N[1]=(N[1]-(N[1]-N[1]%100))*10+(N[0]-N[0]%100)/100;N[0]=(N[0]-(N[0]-N[0]%100))*10;PB();return;}
if(N[2]>=100&&N[3]==0&&N[4]==0&&N[5]==0&&N[6]==0&&N[7]==0&&N[8]==0&&N[9]==0&&N[10]==0&&N[11]==0&&N[12]==0&&N[13]==0&&N[14]==0&&N[15]==0&&N[16]==0&&N[17]==0&&N[18]==0&&N[19]==0&&N[20]==0&&N[21]==0&&N[22]==0&&N[23]==0&&N[24]==0){N[3]=(N[2]-N[2]%100)/100;N[2]=(N[2]-(N[2]-N[2]%100))*10+(N[1]-N[1]%100)/100;N[1]=(N[1]-(N[1]-N[1]%100))*10+(N[0]-N[0]%100)/100;N[0]=(N[0]-(N[0]-N[0]%100))*10;PB();return;}
if(N[3]>0&&N[3]<10&&N[4]==0&&N[5]==0&&N[6]==0&&N[7]==0&&N[8]==0&&N[9]==0&&N[10]==0&&N[11]==0&&N[12]==0&&N[13]==0&&N[14]==0&&N[15]==0&&N[16]==0&&N[17]==0&&N[18]==0&&N[19]==0&&N[20]==0&&N[21]==0&&N[22]==0&&N[23]==0&&N[24]==0){N[3]=N[3]*10;N[3]+=(N[2]-N[2]%100)/100;N[2]=(N[2]-(N[2]-N[2]%100))*10+(N[1]-N[1]%100)/100;N[1]=(N[1]-(N[1]-N[1]%100))*10+(N[0]-N[0]%100)/100;N[0]=(N[0]-(N[0]-N[0]%100))*10;PB();return;}
}
//and so on all the way to the last int[24]

Is the whole part in question.
It is a function that I wrote up to have a keypad be able to input numbers that moves the last digit over one place value every time a number is input on the keypad.
There are other functions that change the data of the array, but that happens when someone presses the button, other than that, it stays as it is every frame, and every other function that uses those arrays is still working fine.

Zim
01-03-2013, 07:14 PM
bool MP(int tX,int tY,int upixels,int dpixels,int lpixels,int rpixels)
{if(tX+16+rpixels<=mX||tX-lpixels>=mX||tY+16+dpixels<=mY||tY-upixels>=mY){return false;}
if(tX+16+rpixels>mX&&tX-lpixels<mX&&tY+16+dpixels>mY&&tY-upixels<mY){return true;}}

void PB() //Phone Buttons
{if(MP(100,100,1,0,1,0)==true){N[0]+=1;return;}if(MP(116,100,1,0,0,0)==true){N[0]+=2;return;}
if(MP(132,100,1,0,0,1)==true){N[0]+=3;return;}if(MP(100,116,0,0,1,0)==true){N[0]+=4;return;}
if(MP(116,116,0,0,0,0)==true){N[0]+=5;return;}if(MP(132,116,0,0,0,1)==true){N[0]+=6;return;}
if(MP(100,132,0,1,1,0)==true){N[0]+=7;return;}if(MP(116,132,0,0,0,0)==true){N[0]+=8;return;}
if(MP(132,132,0,1,0,1)==true){N[0]+=9;return;}
}

Is the function that it calls, I see no errors with this scripting.. It just won't work on my game. See how the N[0] gets added the number the mouse is clicked on with the MP function over the area of the button 0-9.. This all worked just fine before I converted it to an array, and I made no mistakes in the conversion.. I can't see why it won't work other than I might've messed up my ZC by continuing the ZC game with new scripts or something..

Zim
01-03-2013, 07:16 PM
I think I might've just learned what the problem is.. I wrote N[24] thinking that it automatically counted 0 in the amount of numerals instead of N[25] representing 25 numerals from 0-24. Thanks!

Edit: Yes, that is exactly what my problem was. Thanks for your help!

Zim
01-03-2013, 07:57 PM
Don't mean to be a bugger, but this topic should probably be deleted now since it's not actually a bug, rather than my lack of knowledge that led to this post.

Gleeok
01-03-2013, 10:01 PM
A little late but you can avoid some things like this in the future by checking allegro.log for script errors/warnings.

Zim
01-07-2013, 06:35 PM
A little late but you can avoid some things like this in the future by checking allegro.log for script errors/warnings.
Oh yeah.. I got so used to my scripts being written correctly I forgot about checking that often.