Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: boot2490 on September 25, 2011, 06:06:22 pm

Title: Homescreen Invaders Bug!!! Matrix rendering system broken
Post by: boot2490 on September 25, 2011, 06:06:22 pm
So, in homescreen invaders, the alien fleet is rendered by the program reading from a 3X5 matrix and drawing a V in the appropriate position.
Howver, it doesn't draw anything.
Also, the matrix is appropriately filled with 1's for the example.
Here is the code:
Code: [Select]
1→M
1→X
1→Y
While M≤15
If X≤5
Then
If Y≤3
Then
If [I](Y,X)=1
Output(Y+3,X+3,"V"
If [I](Y,X)=0
Output(Y+3,X+3," "
Else
Goto Z
End
Else
X+1→X
Y+1→Y
End
M+1→M
End
Title: Re: Homescreen Invaders Bug!!! Matrix rendering system broken
Post by: BlakPilar on September 25, 2011, 06:20:05 pm
Nevermind whatever I had here at first. I was being stupid. Um... I'm going to use my own method (but retain some of the same things of yours) because I despise while loops unless I'm reading from a file on the computer... This method will also allow you to change the size of the matrix at any time.

Code: [Select]
dim([I]→L1
Ans(1→H
L1(2→W
For(Y,1,H)
For(X,1,W)
If [I](Y,X)=1
Output(Y+3,X+3,"V
If not([I](Y,X
Output(Y+3,X+3," "
End
End
DelVar L1
Title: Re: Homescreen Invaders Bug!!! Matrix rendering system broken
Post by: ztrumpet on September 25, 2011, 06:47:23 pm
Please don't put a loop after a DelVar.  It will then be skipped if something like an if statement surrounds it. ;)
Also, if you close the parenthesis on the For loops, it'll run faster (because TI fails).
Title: Re: Homescreen Invaders Bug!!! Matrix rendering system broken
Post by: boot2490 on September 25, 2011, 06:48:17 pm
That is a lot of less lines. How does it work? Must know...
Title: Re: Homescreen Invaders Bug!!! Matrix rendering system broken
Post by: BlakPilar on September 25, 2011, 06:49:17 pm
@ztrumpet, Ahh. I haven't really done anything with TI-BASIC in a looong time, so sorry about that lol. I just did it the way Is do it on the computer.
Title: Re: Homescreen Invaders Bug!!! Matrix rendering system broken
Post by: Broseph Radson on October 03, 2011, 04:27:17 pm
Woo I'm late to this thread. That code works like this:
the outer for increments once each time the inner for finishes, so it reads the matrix row by row. The conditionals use the values in the for loops to correspond to coordinates in the matrix, and the outputs use those coordinates to place the characters where they belong on screen in relation to the current y,x of the loops.
Title: Re: Homescreen Invaders Bug!!! Matrix rendering system broken
Post by: meishe91 on October 06, 2011, 03:15:20 pm
Code: (BlakPilar's Code Optimized) [Select]
dim([I]
For(Y,1,Ans(1
For(X,1,Ans(2
If [I](Y,X
Then
Output(Y+3,X+3,"V
Else
Output(Y+3,X+3,"_
End
End
End
DelVar L1
Title: Re: Homescreen Invaders Bug!!! Matrix rendering system broken
Post by: BlakPilar on October 06, 2011, 04:15:53 pm
Perhaps you can clarify for me then, meishe. Does the calculator pre-determine the min and max values for for loops?
Title: Re: Homescreen Invaders Bug!!! Matrix rendering system broken
Post by: meishe91 on October 06, 2011, 04:27:54 pm
Do you mean it that it determines the variables then store them somewhere?
Title: Re: Homescreen Invaders Bug!!! Matrix rendering system broken
Post by: BlakPilar on October 06, 2011, 04:51:03 pm
Basically, yeah. Like, if I do
Code: [Select]
5
For(A,1,Ans
2
End
will it use 5 as the max instead of 2?
Title: Re: Homescreen Invaders Bug!!! Matrix rendering system broken
Post by: Broseph Radson on October 06, 2011, 04:51:41 pm
Code: [Select]
Dim([I]
Returns the dimensions of matrix I in ans in list format so the length and width can be recalled as ans(#
Title: Re: Homescreen Invaders Bug!!! Matrix rendering system broken
Post by: BlakPilar on October 06, 2011, 05:00:29 pm
I know that (if that was meant for me), but my question was if the calculator remembers that as Ans for the for loop instead of something inside of the loop.
Title: Re: Homescreen Invaders Bug!!! Matrix rendering system broken
Post by: meishe91 on October 06, 2011, 05:06:38 pm
Ya, I believe it will. I mean it works in my example anyways :P I believe the only way to effect how the For() counts is if you modify the variable it uses. So say you have For(A,1,100):A+1→A:End, I believe it will actually be counting by two instead of by one. (Note: I haven't actually tested that, so I could be wrong. But the principle remains the same.)
Title: Re: Homescreen Invaders Bug!!! Matrix rendering system broken
Post by: ztrumpet on October 06, 2011, 05:57:14 pm
Perhaps you can clarify for me then, meishe. Does the calculator pre-determine the min and max values for for loops?
I'm actually not sure.  Meishe's example works because Ans is never changed during the loops.
Title: Re: Homescreen Invaders Bug!!! Matrix rendering system broken
Post by: BlakPilar on October 06, 2011, 06:10:02 pm
Quick Wabbit test shows that
Code: [Select]
5
For(A,1,Ans
2
Disp Ans
End
Displays "2" five times. So maybe? :D