Author Topic: What's wrong with this code ?  (Read 8518 times)

0 Members and 1 Guest are viewing this topic.

persalteas

• Posts: 231
• Rating: +44/-4
• z80 poweeer
What's wrong with this code ?
« 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→S0→K31→Y47→XClrDrawReturn→ZWhile Y>055→ArandInt(0,86→CWhile A>0getKey→K If K=2X:-X>0:→XIf K=3X:+X<86:→XRect(0,A,7,C,8Rect(C+12,A,7,96,8DispGraphSprite(8,S,Y,X,1,8DispGraphY-1→YY+2*pxl-Test(Y+8,X→YDispGraphA-1→AEndClrDrawDispGraphGoto ZStop

Streetwalrus

• LV12 Extreme Poster (Next: 5000)
• Posts: 3821
• Rating: +80/-8
Re: What's wrong with this code ?
« Reply #1 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 ?

persalteas

• Posts: 231
• Rating: +44/-4
• z80 poweeer
Re: What's wrong with this code ?
« Reply #2 on: February 11, 2013, 01:46:55 pm »
Yes I don't see problems... I don't know while it doesn't work.

Xeda112358

• they/them
• Moderator
• LV12 Extreme Poster (Next: 5000)
• Posts: 4657
• Rating: +718/-6
• Calc-u-lator, do doo doo do do do.
Re: What's wrong with this code ?
« Reply #3 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 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 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]
Full1Is the same as:
Code: [Select]
Full
Code: [Select]
While Y>0Since 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=2If <86→XSay 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→S31→Y47→XWhile Y=abs(YClrDrawRect(0,55,7,96,8randInt(0,86Line(,55,7,12,9For(55getKey→KX+K=3-K=2If <86→XTangent(1,8              ;shift the graph buffer up 1 pixelSprite(10,S,Y,X          ;The last two arguments can be omitted if they are 1,8DispGraphSprite(10,S,Y,XY-!!Rect(X,Y,9,8,15→Y    ;Rect(X,Y,H,W,15) is a pxl-Test( for the border.EndEndStop
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

TIfanx1999

• ಠ_ಠ ( ͡° ͜ʖ ͡°)
• CoT Emeritus
• LV13 Extreme Addict (Next: 9001)
• Posts: 6173
• Rating: +191/-9
Re: What's wrong with this code ?
« Reply #4 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).

Xeda112358

• they/them
• Moderator
• LV12 Extreme Poster (Next: 5000)
• Posts: 4657
• Rating: +718/-6
• Calc-u-lator, do doo doo do do do.
Re: What's wrong with this code ?
« Reply #5 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 >.>

Yeong

• Not a bridge
• LV12 Extreme Poster (Next: 5000)
• Posts: 3739
• Rating: +278/-12
• Survivor of Apocalypse
Re: What's wrong with this code ?
« Reply #6 on: February 11, 2013, 06:37:32 pm »
Xeda's on the roll again!
Sig wipe!

Sorunome

• Fox Fox Fox Fox Fox Fox Fox!
• Support Staff
• LV13 Extreme Addict (Next: 9001)
• Posts: 7918
• Rating: +374/-13
• Derpy Hooves
Re: What's wrong with this code ?
« Reply #7 on: February 11, 2013, 06:51:02 pm »
Xeda's on the roll again!
yay
And the falldown is looking awesome
 THE GAMEAlso, check out my websiteIf OmnomIRC is screwed up, blame me!Click here to give me an internet!

persalteas

• Posts: 231
• Rating: +44/-4
• z80 poweeer
Re: What's wrong with this code ?
« Reply #8 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 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

This make Omnimaga a bit difficult to adopt
« Last Edit: February 12, 2013, 02:07:54 am by persalteas »

blg_flg

• LV0 Newcomer (Next: 5)
• Posts: 3
• Rating: +0/-0
Re: What's wrong with this code ?
« Reply #9 on: February 12, 2013, 02:51:57 pm »
Hello.

Bon bah euh... Nice to meet you.

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?
« Last Edit: February 12, 2013, 04:45:26 pm by blg_flg »
I'm French! Don't hesitate to correct my spelling mistakes; I would be pretty happy!

TIfanx1999

• ಠ_ಠ ( ͡° ͜ʖ ͡°)
• CoT Emeritus
• LV13 Extreme Addict (Next: 9001)
• Posts: 6173
• Rating: +191/-9
Re: What's wrong with this code ?
« Reply #10 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.

persalteas

• Posts: 231
• Rating: +44/-4
• z80 poweeer
Re: What's wrong with this code ?
« Reply #11 on: February 12, 2013, 05:00:10 pm »
He did it ! He registered ! 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)

Xeda112358

• they/them
• Moderator
• LV12 Extreme Poster (Next: 5000)
• Posts: 4657
• Rating: +718/-6
• Calc-u-lator, do doo doo do do do.
Re: What's wrong with this code ?
« Reply #12 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 The code wasn't that bad. At least it worked when the bugs were fixed

blg_flg

• LV0 Newcomer (Next: 5)
• Posts: 3
• Rating: +0/-0
Re: What's wrong with this code ?
« Reply #13 on: February 17, 2013, 11:44:16 am »
Xeda, can you post the code (or an .8xp) of your second falldown please? (That one.)

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).
« Last Edit: February 17, 2013, 04:17:38 pm by blg_flg »
I'm French! Don't hesitate to correct my spelling mistakes; I would be pretty happy!