Calculator Community > Grammer

What's wrong with this code ?

(1/6) > >>

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

--- End code ---

Thanks for your answer...

Streetwalrus:
I don't know Grammer, sorry. :S
Though I don't see any algorithmic problems. Might be a Grammer bug ?

persalteas:
Yes I don't see problems... I don't know while it doesn't work.

Xeda112358:
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: ---Full1

--- End code ---
Is the same as:

--- Code: ---Full

--- End code ---


--- Code: ---While Y>0

--- End code ---
Since Grammer only has non-negative integers (0,1,2,3,4,...,65535), you can do:

--- Code: ---While Y

--- End code ---

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: ---X+K=3
-K=2
If <86
→X

--- End code ---
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: ---.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

--- End code ---

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:
Hey persaltes, you should try to encourage them to join. We're really nice people here, and we don't bite (usually). :P

Navigation

[0] Message Index

[#] Next page

Go to full version