Omnimaga

Calculator Community => TI Calculators => Grammer => Topic started by: persalteas on February 11, 2013, 01:09:42 pm

Title: What's wrong with this code ?
Post by: persalteas on February 11, 2013, 01:09:42 pm
Hi, I have a friend who is too shy to come and ask himself his questions...

And I have no idea too about what is wrong in this code. Try it, it's a falldown game, you may see the ball going left automatically, even if no key were pressed.

Code: [Select]
.0:
Full1
"3C72F3FFFFFF7E3C→S
0→K
31→Y
47→X
ClrDraw
Return→Z

While Y>0
55→A
randInt(0,86→C

While A>0
getKey→K
If K=2
X:-X>0:→X
If K=3
X:+X<86:→X
Rect(0,A,7,C,8
Rect(C+12,A,7,96,8
DispGraph
Sprite(8,S,Y,X,1,8
DispGraph
Y-1→Y
Y+2*pxl-Test(Y+8,X→Y
DispGraph
A-1→A
End

ClrDraw
DispGraph
Goto Z
Stop

Thanks for your answer...
Title: Re: What's wrong with this code ?
Post by: Streetwalrus on February 11, 2013, 01:25:35 pm
I don't know Grammer, sorry. :S
Though I don't see any algorithmic problems. Might be a Grammer bug ?
Title: Re: What's wrong with this code ?
Post by: persalteas on February 11, 2013, 01:46:55 pm
Yes I don't see problems... I don't know while it doesn't work.
Title: Re: What's wrong with this code ?
Post by: Xeda112358 on February 11, 2013, 06:01:13 pm
I did not have the problem you described, but I do see a big problem with the code and a bunch of smaller problems (maybe).
The big problem is that they never used End for one of their While loops D: And since they kept re-entering the While loop without finishing it with an End, it would eventually fill the stack causing a crash, most likely .__.
The little problems are just regular coding optimisations :P For example, Grammer does not use negative numbers, so Y>0 is the same as Y≠0. As well, there are so many extra DispGraph's and they are slowing down the program.

Code: [Select]
Full1
Is the same as:
Code: [Select]
Full

Code: [Select]
While Y>0
Since Grammer only has non-negative integers (0,1,2,3,4,...,65535), you can do:
Code: [Select]
While Y

Instead of 'X:-X>0:→X'you can just do X-X>0→X or even better, since Grammer doesn't have negative numbers, X-!X→X
In fact, for movement, this is better:
Code: [Select]
X+K=3
-K=2
If <86
→X
Say X=0 and you press [Left]. Then the first two lines do 0-1 which is 65535, and since 65535≥86, it isn't stored to X.


Here is how I optimised/fixed it:
Code: [Select]
.0:Return
"3C72F3FFFFFF7E3C→S
31→Y
47→X
While Y=abs(Y
ClrDraw
Rect(0,55,7,96,8
randInt(0,86
Line(,55,7,12,9
For(55
getKey→K
X+K=3
-K=2
If <86
→X
Tangent(1,8              ;shift the graph buffer up 1 pixel
Sprite(10,S,Y,X          ;The last two arguments can be omitted if they are 1,8
DispGraph
Sprite(10,S,Y,X
Y-!!Rect(X,Y,9,8,15→Y    ;Rect(X,Y,H,W,15) is a pxl-Test( for the border.
End
End
Stop

It is not perfect, but it works a lot faster (faster than before, even without Full). And more, it is now easy to add more barriers on the screen at once!


Here is the screenie of the version I made with better collision detection and variable speed and stuff :)
Title: Re: What's wrong with this code ?
Post by: TIfanx1999 on February 11, 2013, 06:09:41 pm
Hey persaltes, you should try to encourage them to join. We're really nice people here, and we don't bite (usually). :P
Title: Re: What's wrong with this code ?
Post by: Xeda112358 on February 11, 2013, 06:30:13 pm
Yes, you should bring him over ! Even if he only speaks french, it will make me have to get better at speaking/reading french ^^'

Also, I made another version >.>
Title: Re: What's wrong with this code ?
Post by: Yeong on February 11, 2013, 06:37:32 pm
Xeda's on the roll again! :P
Title: Re: What's wrong with this code ?
Post by: Sorunome on February 11, 2013, 06:51:02 pm
Xeda's on the roll again! :P
yay :D
And the falldown is looking awesome :P
Title: Re: What's wrong with this code ?
Post by: persalteas on February 12, 2013, 02:05:15 am
Hahaha x)
Waow !
This is beyond my expectations !!

Quote
Say X=0 and you press
. Then the first two lines do 0-1 which is 65535, and since 65535≥86, it isn't stored to X.
Oh yes, terrific !

I know he is reading the topic :P blg_flg, if you have questions, ask, you are in the wonderful land of ponies, lobsters and calc nerds, nobody would eat you ! Wou can even speak french.

HS:
In any case, someone may have already told you, Omnimaga is uninviting for newbies.
I have been personnally registered for 2 years now (since Axe v0.4.5, yeah ! ), but active for... several months only, since I use Grammer.
- The retro theme is not cool when you are not accustomed (I use the theme v3, now)
- Members have biiiiig signatures (and it invades TI-Planet now, step by step...)
- We speak bad english (and when topics are posted in the french sub-forum, nobody cares)
- You can met here very famous coders like Xeda, calc84, thepenguin and I forget thousands :D

This make Omnimaga a bit difficult to adopt ;)
Title: Re: What's wrong with this code ?
Post by: blg_flg on February 12, 2013, 02:51:57 pm
Hello.  ;D

Bon bah euh... Nice to meet you. :P

I'm sorry: my code hurts the eyes, and I speak English as well as I speak Grammer. ^^

And thank you for your help!  :)


Ps: @Xeda: Do you still want to make a TI-83 Grammer?
Title: Re: What's wrong with this code ?
Post by: TIfanx1999 on February 12, 2013, 04:27:26 pm
Hello blg_flg. Welcome to Omnimaga! Don't worry to much if your code isn't perfect. We were all beginners once. :) We also have many people who have English as a second language, so don't worry about that too much either.
Title: Re: What's wrong with this code ?
Post by: persalteas on February 12, 2013, 05:00:10 pm
He did it ! He registered ! :D Nice to meet you too.
Well, congratulations. I will give you a cookie on TI-Planet.

Quote
Ps: @Xeda: Do you still want to make a TI-83 Grammer?
I +1 the question, and I hope that yes... (but this is a bit off-topic)
Title: Re: What's wrong with this code ?
Post by: Xeda112358 on February 12, 2013, 07:41:46 pm
I still would like to at some point, but I don't know when I would do that .__. Also, welcome blg_flg :D The code wasn't that bad. At least it worked when the bugs were fixed :)
Title: Re: What's wrong with this code ?
Post by: blg_flg on February 17, 2013, 11:44:16 am
Xeda, can you post the code (or an .8xp) of your second falldown please? (That one.) (http://ourl.ca/18326;msg=283896)

I would be interested in that, because I didn't already see many Grammer codes and it seems to be the best version in between. Thanks in advance.  :)


Edit: and can you explain to me the purpose of the "Return" in your code (the first line).
Title: Re: What's wrong with this code ?
Post by: persalteas on February 18, 2013, 04:33:28 am
The first Return ?

If Grammer is not installed, the program exits.
Title: Re: What's wrong with this code ?
Post by: Xeda112358 on February 18, 2013, 07:57:55 am
Yep, if Grammer isn't installed and you try to run the program, it will be run as a BASIC program, so it exits. If it is run as a Grammer program, the first "." tells it that it is a label, so it skips the line.


And here is the code:
Code: [Select]
:.0:Return
:31→Y
:47→X
:0→L
:30→M
:1→P
:ClrDraw
:While Y=abs(Y
:Line(0,59,5,96,1
:randInt(0,86
:Line(,59,5,12,2
:1→F
:For(A,1,M
:getKey→K
:If K=10
:Full
:If K=11
:Full0
:K=3
:-K=2
:+Ans+X
:If <86: and !Line(Ans,Y,6,6,15
:→X
:If Y<52: and !Line(X,Y+6,1,6,14
:IS>(Y
:Repeat 1
:Return→Z
:Line(X,Y+1,4,6,2
:Line(X+1,Y,6,4,2
:End
:DispGraph
:prgmZ
:If P xor 1→P
:Tangent(1,8:Y-!!Line(X,Y,7,6,15→Y
:End
:If L+1→L=5: and M>14
:Then
:0→L
:M-1→M/30
:If θ': and P>0
:P-1→P
:End
:End
:Stop
Title: Re: What's wrong with this code ?
Post by: blg_flg on February 18, 2013, 10:36:14 am
Ok. Thank you very much! :) But what's the prgmZ?

Edit: Ah ok the hooks were not activated... --'
Title: Re: What's wrong with this code ?
Post by: persalteas on February 18, 2013, 11:14:34 am
Xeda has not activated his hooks.

"prgm" is "call", so, it means "call Z"


Spoiler For Take a look at the wonderful humor of Adriweb:
(17:17:08) Adriweb: Yes, Xeda is not a hooker.
(17:17:13) Adriweb: that's it.
(17:17:13) Adriweb runs very far......
Title: Re: What's wrong with this code ?
Post by: Xeda112358 on February 18, 2013, 12:47:52 pm
Yes, sorry, I always forget to activate the token hook XD 'prgm' turns into 'call '

Also, very funny Adriweb >.> :P
Title: Re: What's wrong with this code ?
Post by: persalteas on February 19, 2013, 12:10:08 pm
Quote
:If <86: and !Line(Ans,Y,6,6,15

By this, do you mean "If Ans=/=0 and Ans<86:Line(Ans,etc..." ?
Title: Re: What's wrong with this code ?
Post by: Xeda112358 on February 19, 2013, 01:01:32 pm
Quote
:If <86: and !Line(Ans,Y,6,6,15

By this, do you mean "If Ans=/=0 and Ans<86:Line(Ans,etc..." ?
The "If <86" part would translate to TI-BASIC as:
Code: [Select]
If Ans<86 and Ans≥0Then Line(Ans,Y,6,6,15 is used to pixel-test the rectangular region, so !Line(Ans,Y,6,6,15 means in TI-BASIC:
Code: [Select]
not(Line(Ans,Y,6,6,15    ;pretend this still pixel tests the region
Remember that ':' can be used in an If statement to separate different parts. So the line translates to:
Code: [Select]
:If (Ans<86 and Ans≥0) and not(Line(Ans,Y,6,6,15
Title: Re: What's wrong with this code ?
Post by: persalteas on February 19, 2013, 01:16:06 pm
Oh. yes.

I have forgotten that Line could have a pixel-test role. (cf my question in Grammer 3 ideas).

Thanks.
Title: Re: What's wrong with this code ?
Post by: DJ Omnimaga on February 20, 2013, 04:48:40 pm
I still would like to at some point, but I don't know when I would do that .__. Also, welcome blg_flg :D The code wasn't that bad. At least it worked when the bugs were fixed :)
It probably depends of how large grammer is in terms of flash app page memory taken. If it fills an entire page (16 KB), then it might be fine (leaving 11 KB to the user), but if it takes 2 pages, the 82 Stats/83 only has 27 KB of memory.
Title: Re: What's wrong with this code ?
Post by: Xeda112358 on February 20, 2013, 08:39:50 pm
I was thinking about it this morning and I would probably make a version that didn't have as many features. It would still have many more features than Grammer 1, but it would probably be about 6000 bytes and use more OS routines. Currently, Grammer uses mostly custom routines to make things faster, so if I used OS routines, I could probably save about 1000 bytes of code :) Also, I have optimised many routines to be even faster than the Grammer 1 routines (and smaller) so that should help.
Title: Re: What's wrong with this code ?
Post by: persalteas on February 21, 2013, 04:47:10 am
That's a very good news ;)
even if it has less features, it will be very appreciated, for now, there is no intermediary between Basic and Asm on TI-83s...
Title: Re: What's wrong with this code ?
Post by: DJ Omnimaga on February 21, 2013, 09:15:16 am
Cool to hear. Just make sure that the most used features are still there and it should be fine. And I agree Persalteas. Also if someone make Grammer programs for the TI-83 maybe he could read them on a 83+ too, since you can send 83p files to them as well.