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

0 Members and 1 Guest are viewing this topic.

Offline persalteas

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 231
  • Rating: +44/-4
  • z80 poweeer
    • View Profile
    • Tout-82
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→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...


Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
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 ?

Offline persalteas

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 231
  • Rating: +44/-4
  • z80 poweeer
    • View Profile
    • Tout-82
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.


Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
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 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 :)

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
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). :P

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
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 >.>

Offline Yeong

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

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: What's wrong with this code ?
« Reply #7 on: February 11, 2013, 06:51:02 pm »
Xeda's on the roll again! :P
yay :D
And the falldown is looking awesome :P

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline persalteas

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 231
  • Rating: +44/-4
  • z80 poweeer
    • View Profile
    • Tout-82
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 :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 ;)
« Last Edit: February 12, 2013, 02:07:54 am by persalteas »


Offline blg_flg

  • LV0 Newcomer (Next: 5)
  • Posts: 3
  • Rating: +0/-0
    • View Profile
Re: What's wrong with this code ?
« Reply #9 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?
« 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! ;)

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
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.

Offline persalteas

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 231
  • Rating: +44/-4
  • z80 poweeer
    • View Profile
    • Tout-82
Re: What's wrong with this code ?
« Reply #11 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)


Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
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 :D The code wasn't that bad. At least it worked when the bugs were fixed :)

Offline blg_flg

  • LV0 Newcomer (Next: 5)
  • Posts: 3
  • Rating: +0/-0
    • View Profile
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! ;)

Offline persalteas

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 231
  • Rating: +44/-4
  • z80 poweeer
    • View Profile
    • Tout-82
Re: What's wrong with this code ?
« Reply #14 on: February 18, 2013, 04:33:28 am »
The first Return ?

If Grammer is not installed, the program exits.