### Author Topic: [casio-basic problem] Argument Error with Matrices and If Clauses  (Read 2208 times)

0 Members and 1 Guest are viewing this topic.

#### Spyro543

• LV9 Veteran (Next: 1337)
• Posts: 1189
• Rating: +74/-3
##### [casio-basic problem] Argument Error with Matrices and If Clauses
« on: March 21, 2013, 06:43:09 pm »
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: [Select]
{7,21}->Dim Mat CFill(0, Mat C)1->XRanInt#(3,6)->Y0->A0->B0->KWhile X<22Y+RanInt#(-1,1)->YIf Y>7Then 7->YIfEndIf Y<2Then 2->YIfEndLocate X,Y,"()"1->Mat C[Y,X]For Y+1->I to 7 Step 1Locate X,I,"[]"2->Mat C[Y,X]NextX+1->XWhileEndLocate 1,2,"I"9->Mat C[2,1]1->X2->YWhile K!=47Locate 1,1,"()"Locate 2,1,ALocate 6,1,BLocate 5,1,"[]"If Mat C[Y+1,X]=0Then Locate X,Y," "0->Mat C[Y,X]Y+1->Y9->Mat C[Y,X]Locate X,Y,"I"IfEndGetkey->KIf K=38 And X>1 And Mat C[Y,X+1]=0Then 0->Mat C[Y,X+1]Locate X,Y," "X+1->X9->Mat C[Y,X]Locate X,Y,"I"IfEndIf K=27 And X<27 And Mat C[Y,X-1]=0Then 0->Mat C[Y,X-1]Locate X,Y," "X-1->X9->Mat C[Y,X]Locate X,Y,"I"IfEndWhileEnd
I hand-typed this code while looking at my calc screen so if you see any weird typing mistakes just ignore them

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 )

I'm getting ARGUMENT ERROR at the line that says:
Code: [Select]
If K=27 And X<27 And Mat C[Y,X-1]=0
What is going on here? Everything should be OK...

Also, everything else works fine, the world generator and the player falling mechanism.

#### sjasogun1

• LV3 Member (Next: 100)
• Posts: 88
• Rating: +8/-1
##### Re: [casio-basic problem] Argument Error with Matrices and If Clauses
« Reply #1 on: April 02, 2013, 03:39:04 am »
Code: [Select]
{7,21}->Dim Mat CFill(0, Mat C)1->XRanInt#(3,6)->Y0->A0->B0->KWhile 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->XWhileEndLocate 1,2,"I"9->Mat C[2,1]1->X2->YWhile 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"   IfEndWhileEnd
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: [Select]
   For Y+1->I to 7 Step 1      Locate X,I,"[]"      2->Mat C[Y,X]   NextHas a mistake; Shouldn't it be
Code: [Select]
      2->Mat C[I,X]instead of
Code: [Select]
      2->Mat C[Y,X]
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.
« Last Edit: April 02, 2013, 04:46:11 am by sjasogun1 »
Veni, vidi, cecidi
(I came, I saw, I fell down dead)
MSPAFORUMS: http://www.mspaforums.com/