Calculator Community > Casio Calculators |
[casio-basic problem] Argument Error with Matrices and If Clauses |
(1/1) |
Spyro543:
First off, here's my code: In The code, you'll see me writing [] and (). These correspond to the filled square character and the empty square character. --- Code: ---{7,21}->Dim Mat C Fill(0, Mat C) 1->X RanInt#(3,6)->Y 0->A 0->B 0->K While X<22 Y+RanInt#(-1,1)->Y If Y>7 Then 7->Y IfEnd If Y<2 Then 2->Y IfEnd Locate X,Y,"()" 1->Mat C[Y,X] For Y+1->I to 7 Step 1 Locate X,I,"[]" 2->Mat C[Y,X] Next X+1->X WhileEnd Locate 1,2,"I" 9->Mat C[2,1] 1->X 2->Y While K!=47 Locate 1,1,"()" Locate 2,1,A Locate 6,1,B Locate 5,1,"[]" If Mat C[Y+1,X]=0 Then Locate X,Y," " 0->Mat C[Y,X] Y+1->Y 9->Mat C[Y,X] Locate X,Y,"I" IfEnd Getkey->K If K=38 And X>1 And Mat C[Y,X+1]=0 Then 0->Mat C[Y,X+1] Locate X,Y," " X+1->X 9->Mat C[Y,X] Locate X,Y,"I" IfEnd If K=27 And X<27 And Mat C[Y,X-1]=0 Then 0->Mat C[Y,X-1] Locate X,Y," " X-1->X 9->Mat C[Y,X] Locate X,Y,"I" IfEnd WhileEnd --- End code --- I hand-typed this code while looking at my calc screen so if you see any weird typing mistakes just ignore them :P This is a world generation program that I will be using for my secret project (even though it's not so secret, because you now see my source code :P) I'm getting ARGUMENT ERROR at the line that says: --- Code: ---If K=27 And X<27 And Mat C[Y,X-1]=0 --- End code --- What is going on here? Everything should be OK... Also, everything else works fine, the world generator and the player falling mechanism. |
sjasogun1:
--- Code: ---{7,21}->Dim Mat C Fill(0, Mat C) 1->X RanInt#(3,6)->Y 0->A 0->B 0->K While X<22 Y+RanInt#(-1,1)->Y If Y>7 Then 7->Y IfEnd If Y<2 Then 2->Y IfEnd Locate X,Y,"()" 1->Mat C[Y,X] For Y+1->I to 7 Step 1 Locate X,I,"[]" 2->Mat C[Y,X] Next X+1->X WhileEnd Locate 1,2,"I" 9->Mat C[2,1] 1->X 2->Y While K!=47 Locate 1,1,"()" Locate 2,1,A Locate 6,1,B Locate 5,1,"[]" If Mat C[Y+1,X]=0 Then Locate X,Y," " 0->Mat C[Y,X] Y+1->Y 9->Mat C[Y,X] Locate X,Y,"I" IfEnd Getkey->K If K=38 And X>1 And Mat C[Y,X+1]=0 Then 0->Mat C[Y,X+1] Locate X,Y," " X+1->X 9->Mat C[Y,X] Locate X,Y,"I" IfEnd If K=27 And X<27 And Mat C[Y,X-1]=0 Then 0->Mat C[Y,X-1] Locate X,Y," " X-1->X 9->Mat C[Y,X] Locate X,Y,"I" IfEnd WhileEnd --- End code --- I put some tabs in your code so it's easier to read, and I noticed that X-1 is not a valid matrix value at that point in the code. Before that you assigned 1 to X but didn't change it afterwards. So this IF-statement is trying to check whether Mat C[Y,0]=0, but Mat C[Y,0] is not a valid Matrix element. I can't tell you how to prevent this since I don't know what you want to count the 'borders' of the screen (since that's what I assume you have there) as, but the rest of your code looks fairly advanced so you should be able to figure out how to prevent X from being 1 at that point in the code. EDIT: I also noticed that this part: --- Code: --- For Y+1->I to 7 Step 1 Locate X,I,"[]" 2->Mat C[Y,X] Next --- End code --- Has a mistake; Shouldn't it be --- Code: --- 2->Mat C[I,X] --- End code --- instead of --- Code: --- 2->Mat C[Y,X] --- End code --- EDIT2: Also, in the two IF-statements for horizontal movement you assign 0 to the matrix element you just checked to be 0 (Y,X+1 and Y,X-1, specifically). Looking at the IF-statement for the falling you probably meant that to be Y,X for both of them, otherwise the "I" won't delete properly. Also, I just realized that this program is the MCLite thingy you have already posted so presumably you have already fixed those problems and I am just wasting my time explaining stuff you already figured out. |
Spyro543:
Lol yeah, I already fixed these problems. Thanks anyway :D |
Navigation |
Message Index |