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

0 Members and 1 Guest are viewing this topic.

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
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 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

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: [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.

Offline sjasogun1

  • LV3 Member (Next: 100)
  • ***
  • Posts: 88
  • Rating: +8/-1
    • View Profile
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 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

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]
   Next
Has 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/
HOMESTUCK: http://www.mspaintadventures.com/?s=6&p=001901

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: [casio-basic problem] Argument Error with Matrices and If Clauses
« Reply #2 on: April 04, 2013, 09:34:37 am »
Lol yeah, I already fixed these problems. Thanks anyway :D