Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Munchor on December 18, 2010, 06:44:30 am

Title: Appvariables for Highscores
Post by: Munchor on December 18, 2010, 06:44:30 am
Some of you may have heard of my difficulty with appvars in Axe at Cemetech, I decided to post it here too, because Omnimaga's community is more Axy.

So, if you wanna see the main thread, check it here (http://cemetech.net/forum/viewtopic.php?t=5492).

What I need to do:
> I have an easy and a hard mode and need a highscore for each one;
> The first time the game is opened the highscore needs to be 0;
> In the title screen, I need to display the highscore for easy/hard (the user chooses which);
> is not working, the highscore displayed is always 110, but it creates an Appvar;

What I have done:
> I created an Appvar.

What I have understood;
> If I use GetCalc(NAME,SIZE) twice, the second time it will delete the previous one;
> How to create an Appvar.

My Code:

Code: [Select]

GetCalc("appvPONGhs",Y0)
{Y0}->W

GetCalc("appvPONGhs",Y1)
{Y1}->K

If sub(CS,"<easy>",Str4
Text(29,42,"Highscore:",W>Dec
Else
Text(29,42,"Highscore:",K>Dec
End


. OTHER CODE

If sub(CS,"<easy>",Str4
GetCalc("appvPONGhs",16)->C
S->{C}
End

If sub(CS,"<hard>",Str4
GetCalc("appvPONGhs",16)->C
S->{C+1}
End

This code:
> I could use an Else, but I'll optimize in the end;
> sub(CS compares two strings, thanks to player1537 for publishing it :D.
> The first part of the code is the title screen.

Well, I need a way to create an Appvar if it is the first time the game is being opened, but don't know how to do it :S
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 18, 2010, 09:38:53 am
Code: [Select]
Getcalc(NAME)->H
!If H
Getcalc(NAME,SIZE)->H
For(A,0,SIZE)
0->{H+A}
End

My first post!
Title: Re: Appvariables for Highscores
Post by: Munchor on December 18, 2010, 09:40:34 am
Code: [Select]
Getcalc(NAME)->H
!If H
Getcalc(NAME,SIZE)->H
For(A,0,SIZE)
0->{H+A}
End

My first post!

^^ In your first post you give me my precious code?

Code: [Select]
Getcalc(NAME)->H
!If H
Getcalc(NAME,SIZE)->H
For(A,0,SIZE)
0->{H+A}
End

Your second post will be to explain the For Loop, I hope. The beginning I understand :)
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 18, 2010, 09:45:32 am
I'm french and only 15, so my english won't be perfect  :P

For the loop, it fills bytes of the appvar with 0, because if you don't do that, it will return a random number ( for me that's 219  ;D )

and to save your highscores with different difficulties, store easy highscore in {H} , the hard in {H+1}.

If the highscore can be higher than 255, do {H}r and {H+2}r .
Title: Re: Appvariables for Highscores
Post by: Munchor on December 18, 2010, 09:50:43 am
I'm french and only 15, so my english won't be perfect  :P

For the loop, it fills bytes of the appvar with 0, because if you don't do that, it will return a random number ( for me that's 219  ;D )

and to save your highscores with different difficulties, store easy highscore in {H} , the hard in {H+1}.

If the highscore can be higher than 255, do {H}r and {H+2}r .

So.... In the beginning of the program:

Code: [Select]
Getcalc(NAME)->H
!If H
Getcalc(NAME,SIZE)->H
For(A,0,SIZE)
0->{H}
End

Then when saving highscore:

Code: [Select]
. Check if game is easy
S->{H}
End
.Check if game is hard
S->{H+1}
End

This, I hope works fine. The highscore can be >255 and would need two bytes to store the value, but nobody will get that many points.

So, right now I understood how to store the highscore.


Now, I need to read it and display it, which I think I can do like this:

Code: [Select]
{H}->W
Text(0,0,W
{H+1}->C
Text(0,10,C

Is it done like that? Or like this:

Code: [Select]
GetCalc("appvNAME",Y0)->W
Text(0,0,W
GetCalc("appvNAME",Y1)->C
Text(0,10,C

/me wonders

Thanks!
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 18, 2010, 10:00:50 am
Dont forget in the loop
Code: [Select]
For(A,0,SIZE)
0->{H+A}
End

Don't forget {H+A}

well, for your highscores you need 2 bytes numbers, so you could do like this (you can use it directly in your program) :
Code: [Select]
For(A,0,3)
0->{H+A}
End


You can also display the pointers

Code: [Select]
Text(0,0,{H}rDec
Text(0,10,{H+2}rDec

At the start of the game, for example, if you choosed easy difficulty do 0->D, if that's hard 2->D

And to store it simply do this
Code: [Select]
If S>{H+D}r
S->{H+D}r
End
Title: Re: Appvariables for Highscores
Post by: Munchor on December 18, 2010, 10:03:29 am
Code: [Select]
Text(0,0,{H}rDec
Text(0,10,{H+2}rDec

rDec is >Dec, right?

This is what I'm going for, it's very optimized!
Code: [Select]
Getcalc(NAME)->H
!If H
Getcalc(NAME,SIZE)->H
For(A,0,SIZE)
0->{H+A}
End

And this is the loop at the start of the code. I will try it now :)


Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 18, 2010, 10:05:53 am
that's r>Dec if you prefer
you've got to add after the pointer "r" (in the angles menu) to get the 2 bytes.
Title: Re: Appvariables for Highscores
Post by: Munchor on December 18, 2010, 10:08:14 am
that's r>Dec if you prefer
you've got to add after the pointer "r" (in the angles menu) to get the 2 bytes.

Done!! Now I'm gonna test the hardware, while you go to the introduce yourself thread, OK? :D
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 18, 2010, 10:09:48 am
I'm playing civilization V so it will be later  :D
Title: Re: Appvariables for Highscores
Post by: Runer112 on December 18, 2010, 10:15:28 am
Instead of a For() loop, you can use the Fill() command to fill a section of memory with a value. That, and a few other optimizations:

Code: [Select]
!If GetCalc(NAME)→H
Fill(0→{GetCalc(NAME,SIZE)→H},SIZE-1)
End

It might be a good idea to check whether or not creating the appvar was successful, though. You wouldn't want the game to proceed, thinking that the appvar exists when it really doesn't.
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 18, 2010, 10:21:23 am
wow nice  :D
I think i'll use it in all my games  :)
Title: Re: Appvariables for Highscores
Post by: Munchor on December 18, 2010, 12:28:43 pm
I'm playing civilization V so it will be later  :D

Hum... OK.

It didn't work, the appvar is created, but the HS is always 0, both for easy and hard.

Code: [Select]
!If GetCalc(NAME)→H
Fill(0→{GetCalc(NAME,SIZE)→H},SIZE-1)
End

I gotta try that too :)

Runner always optimizing :D
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 18, 2010, 12:30:03 pm
 can you watch me the part of the program where you use the appvar?

the code of runer do exactly the same thing, but that's more optimized
Title: Re: Appvariables for Highscores
Post by: Munchor on December 18, 2010, 12:31:43 pm
can you watch me the part of the program where you use the appvar?

Send me*
Give me*
Lend me*
Let me see*
Instead of "Can you watch me" :D

I can send you the whole program, because they are separated by about 200 lines of code that can ruin the process. (PM/e-mail)
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 18, 2010, 12:34:12 pm
So "send me" your program ;D
Title: Re: Appvariables for Highscores
Post by: Munchor on December 18, 2010, 12:35:33 pm
So "send me" your program ;D

I already did, if you have any doubts, reply to e.mail, not here, because the code will not be public :S

Maybe one day :)
Title: Re: Appvariables for Highscores
Post by: Deep Toaster on December 18, 2010, 12:59:34 pm
I'm playing civilization V so it will be later  :D

Hum... OK.

It didn't work, the appvar is created, but the HS is always 0, both for easy and hard.

Code: [Select]
!If GetCalc(NAME)→H
Fill(0→{GetCalc(NAME,SIZE)→H},SIZE-1)
End

I gotta try that too :)

Runner always optimizing :D

That leaves the pointer in the Fill( statement at zero, so you're basically copying size-1 bytes starting at address $0000, instead of the address of your appvar, which is definitely not what you want.

Try
Code: [Select]
!If GetCalc(NAME)
0→{GetCalc(NAME,SIZE)→H}
Fill(H,SIZE-1)
End
instead.
Title: Re: Appvariables for Highscores
Post by: Munchor on December 18, 2010, 01:03:27 pm
Code: [Select]
!If GetCalc(NAME)
0→{GetCalc(NAME,SIZE)→H}
Fill(H,SIZE-1)
End

Well, I decided to make the code come public, to make this easier :S

The game is an edit of Quigibo's Axe Example, PONG:

Code: [Select]
.UPONG

"<easy>"->Str4

"SCORE:"->Str2
[6363636363633F1F]->Pic3
[FCFEC6C6FEFCC0C0C0]->Pic4
[3C7EE7C3C3E77E3C]->Pic5
[00CEDFF3E3C3C3C3]->Pic6
[3F7FC3C37F3F037FFE]->Pic7
[FF00000000000000]->Pic8


DiagnosticOff
Lbl 1
ClrDraw
ClrHome
Fix 5
.Code for image
Pt-On(25,10,Pic3   
Pt-On(34,9,Pic4   
Pt-On(34,10,Pic4+1
Pt-On(42,10,Pic5   
Pt-On(51,10,Pic6   
Pt-On(60,9,Pic7   
Pt-On(60,10,Pic7+1

Pt-On(0,19,Pic8
Pt-On(8,19,Pic8
Pt-On(16,19,Pic8
Pt-On(24,19,Pic8
Pt-On(32,19,Pic8
Pt-On(40,19,Pic8
Pt-On(48,19,Pic8
Pt-On(56,19,Pic8
Pt-On(64,19,Pic8
Pt-On(72,19,Pic8
Pt-On(80,19,Pic8
Pt-On(88,19,Pic8
Pt-On(96,19,Pic8


Text(32,21,"2nd:play
Text(35,28,Str4
Text(29,35,"clear:quit

Getcalc("appvPongHS")->H
!If H
Getcalc("appvPongHS,8)->H
For(A,0,18)
0->{H+A}
End

If sub(CS,"<easy>",Str4
Text(29,42,"Highscore:",{H}>Dec
Else
Text(29,42,"Highscore:",{H+1}>Dec
End



Fix 3
Text(0,49,"             made by: David Gomes           
Text(0,55,"                                           Quigibo                           
Fix 2

DispGraph



Repeat getKey->theta
End

If getKey(3) or getKey(19)
104->{Str4+1}
114->{Str4+3}
100->{Str4+4}
End

If getKey(2) or getKey(35)
101->{Str4+1}
115->{Str4+3}
121->{Str4+4}
End

If theta=15
Fix 4
ClrHome
ClrDraw
Return
End

.THIS IS THE START OF THE GAME CODE
If theta=54
ClrDraw
0->S-1->D
44->Z*256->X
10->Y
sub(HT)

Repeat getKey(15)

If sub(CS,"<hard>",Str4)
5->M
Else
2->M
End

.MOVE LEFT CODE
If getKey(2) or getKey(35) and (Z!=0
Z-M->Z
End

.MOVE RIGHT CODE
If getKey(3) or getKey(19) and (Z!=88
Z+M->Z
End

.RANDOM POSITION FOR BALL
X+V->X
Y+D->Y

.LOSING CODE
If Y>70
Goto D
End

.RANDOM POSITION FOR BALL WHEN HIT UPPER BARRIER
If Y=0
sub(HT)
End

.HIT IMAGE CODE
If Y=54 and (abs(X/256-Z)<8
sub(HT)
S+1->S
End
If X/256=0 or (X/256=88
~V->V+X->X
End



ClrDraw
[000000000000FFFF]->Pic1
[0000182C3C180000]->Pic2
If sub(CS,"<easy>",Str4
Line(0,0,96,0)
Line(0,0,0,64)
Line(95,0,95,63)
Line(0,63,95,63)
End
Pt-On(Z,54,Pic1
Pt-On(X/256,Y,Pic2
DispGraph

End

.LOSE LABEL
Lbl D
ClrDraw
ClrHome
Fix 5
.Code for image
Pt-On(25,25,Pic3   
Pt-On(34,24,Pic4   
Pt-On(34,25,Pic4+1
Pt-On(42,25,Pic5   
Pt-On(51,25,Pic6   
Pt-On(60,24,Pic7   
Pt-On(60,25,Pic7+1

Pt-On(0,35,Pic8
Pt-On(8,35,Pic8
Pt-On(16,35,Pic8
Pt-On(24,35,Pic8
Pt-On(32,35,Pic8
Pt-On(40,35,Pic8
Pt-On(48,35,Pic8
Pt-On(56,35,Pic8
Pt-On(64,35,Pic8
Pt-On(72,35,Pic8
Pt-On(80,35,Pic8
Pt-On(88,35,Pic8
Pt-On(96,35,Pic8


If S>9
Text(33,38,Str2,S>Dec
Else
Text(35,38,Str2,S>Dec
End


If sub(CS,"<easy>",Str4
S->{H}
End

If sub(CS,"<easy>",Str4
S->{H+1}
End







DispGraph

Pause 1500
Repeat getKey->U
End
Goto 1




.ROUTINES
Return
Lbl CS
0->r3
Repeat {r2+r3}->r4 != {r1+r3} or ({r1+r3}->r5 = 0) or (r4 = 0)
::r3+1->r3
End
If r4 or r5=0
::1
::Return
End
0
Return

Lbl HT
rand^512-256->V
~D->D

Else
Goto 1
End
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 18, 2010, 01:04:55 pm
i sent you back the code. How do you use str4? i didn't understand it...
Title: Re: Appvariables for Highscores
Post by: Munchor on December 18, 2010, 01:06:26 pm
i sent you back the code. How do you use str4? i didn't understand it...

The code you gave me crashed the calculator and does not work. I can't evem press 2nd or clear, only right and left in the title screen.

Str4 is '<easy>' or '<hard>', and sub(CS,'<easy>',Str4  checks if the the game is easy.
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 18, 2010, 01:10:17 pm
really? i only changed the code of the picture to make it more optimized, nothing else. Check if you made an error...
Title: Re: Appvariables for Highscores
Post by: Munchor on December 18, 2010, 01:13:47 pm
really? i only changed the code of the picture to make it more optimized, nothing else. Check if you made an error...

You did change the loop and made parentheses optimizations, I think :S
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 18, 2010, 01:15:12 pm
yes because your code created a 8 bytes appvar when you need only 4 bytes. After that i did nothing.
Title: Re: Appvariables for Highscores
Post by: Munchor on December 18, 2010, 01:15:55 pm
yes because your code created a 8 bytes appvar when you need only 4 bytes. After that i did nothing.

You also made it 2 bytes for each highscore and I only want 1 :S
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 18, 2010, 01:17:05 pm
we cannot get a score better than 255?  :P
Title: Re: Appvariables for Highscores
Post by: Munchor on December 18, 2010, 01:18:15 pm
we cannot get a score better than 255?  :P

You can but you need to play for about 4 hours and I don't want to even make it possible
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 18, 2010, 01:20:34 pm
ah... much people will get same score  ;D

so do
Code: [Select]
0->{H}r
instead of the loop
Title: Re: Appvariables for Highscores
Post by: Munchor on December 18, 2010, 01:21:41 pm
ah... much people will get same score  ;D

so do
Code: [Select]
0->{H}r
instead of the loop

They won't. My problem is that it does not correctly read the appvar!! That's my problem :(

Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 18, 2010, 01:23:34 pm
I don't see why, you just have do do {H} and {H+1}

check if that's not an other part of your game who fails.
Title: Re: Appvariables for Highscores
Post by: Munchor on December 18, 2010, 01:24:39 pm
I don't see why, you just have do do {H} and {H+1}

check if that's not an other part of your game who fails.

It isn't, actually, I am letting 2 bytes in my code and it works fine, it will not be like that in the final version, though :/
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 18, 2010, 01:29:42 pm
make some others little programs to test the appvar or other things, because if you run the entire program each times you'll never see where the problem(s) comes from.
Title: Re: Appvariables for Highscores
Post by: Munchor on December 18, 2010, 01:37:48 pm
I may also check the code of other Axe games :)
Title: Re: Appvariables for Highscores
Post by: Runer112 on December 18, 2010, 02:12:43 pm
I'm playing civilization V so it will be later  :D

Hum... OK.

It didn't work, the appvar is created, but the HS is always 0, both for easy and hard.

Code: [Select]
!If GetCalc(NAME)→H
Fill(0→{GetCalc(NAME,SIZE)→H},SIZE-1)
End

I gotta try that too :)

Runner always optimizing :D

That leaves the pointer in the Fill( statement at zero, so you're basically copying size-1 bytes starting at address $0000, instead of the address of your appvar, which is definitely not what you want.

Try
Code: [Select]
!If GetCalc(NAME)
0→{GetCalc(NAME,SIZE)→H}
Fill(H,SIZE-1)
End
instead.

Storing the value to a static pointer would return 0, but storing it to a variable pointer returns the pointer. For example, whereas 0→{Str1} would return 0, 0→{A} would return A.

EDIT: And just a side note, storing a two-byte value to a variable pointer, like 0→{A}r, would return A+1.
Title: Re: Appvariables for Highscores
Post by: DJ Omnimaga on December 18, 2010, 03:11:18 pm
I'm playing civilization V so it will be later  :D
Starcraft II!!! :love: J/k

Welcome on the forums. ;D
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 19, 2010, 06:00:05 am
Merci, et tu peut me parler français tu sais  :P

Scout David, can you "send me" the 8xp? I could work on your program easely because i could test it.
Title: Re: Appvariables for Highscores
Post by: Munchor on December 19, 2010, 06:49:43 am
Je parle français aussi, pas de problème, mais dans ce forum nous devons parler anglais, parce que il ya des forums pour le français dans Omnimaga.

Anyways, I was given this code, looks really code:

Quote from: ScoutDavid
Quote from: shmibs
here is a good was to deal with highscore appvars:

place this at the beginning of your program:
Code: [Select]
:"appvNAME"→Str1
:GetCalc(Str1)→θ
:!If θ
:UnarchiveStr1
:GetCalc(Str1)→θEnd
:!If θ
:GetCalc(Str1,[desired size])→θEND

this first checks to see if appvNAME exists in RAM. if not, it attempts to unarchive appvNAME. if it is not found in the archive, the appv is created and made [desired size] bytes long. the pointer to the beginning of appvNAME is stored in theta, so accessing/storing is as easy as {θ+[n]} or S→{θ+[n]}

at the end of your program simply add
:Archive Str1
for safe-keeping

I gotta try that too!! Oh my god, it looks good, thank you!

At cemetech, i'll try it right away!
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 19, 2010, 07:57:34 am
yea, that's easy.
You can directly let at the beginning of the program :
Code: [Select]
Unarchive str1
Getcalc(Str1)->H
Ect...

if the appvar doesn't exist, it will do nothing.

Title: Re: Appvariables for Highscores
Post by: Munchor on December 19, 2010, 11:23:34 am
yea, that's easy.
You can directly let at the beginning of the program :
Code: [Select]
Unarchive str1
Getcalc(Str1)->H
Ect...

if the appvar doesn't exist, it will do nothing.



Nice optimization!

To display it, how would I do?

Code: [Select]
{H}->B
Text(0,0,B

or

Code: [Select]
Text(0,0,{H}
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 19, 2010, 11:46:13 am
the second, more optimized. Don't forget the >Dec  :)

If you send me the 8xp i could work on it and make many optimizations  :D
Title: Re: Appvariables for Highscores
Post by: DJ Omnimaga on December 19, 2010, 11:48:29 am
Yeah it's best to use English in the english forum, so people who only know english can understand. In the French section it's best to only use french too if possible. We can translate our posts but then it takes a while. X.x
Title: Re: Appvariables for Highscores
Post by: Munchor on December 19, 2010, 01:51:08 pm
the second, more optimized. Don't forget the >Dec  :)

If you send me the 8xp i could work on it and make many optimizations  :D

Don't worry with optimizations, i've got it handled xD

Also, thanks for remembering me to put the >Dec, i always forget that stuff :s
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 19, 2010, 02:32:20 pm
I don't think you saw all optimizations. I saw many others that i could do but i would have to test it to see if it works.
Title: Re: Appvariables for Highscores
Post by: Munchor on December 19, 2010, 03:03:09 pm
I don't think you saw all optimizations. I saw many others that i could do but i would have to test it to see if it works.

Fast Crash, after I finish my program maybe you can, trust me I know a lot of optimizations xD
Title: Re: Appvariables for Highscores
Post by: Fast Crash on December 20, 2010, 04:03:51 am
lol i hope that  :)

It's just that some parts of your program are very hard when it can be simple, just like for the string "easy" and "hard".
Title: Re: Appvariables for Highscores
Post by: DJ Omnimaga on December 20, 2010, 04:11:24 am
Mind about showing him exactly how to make them simpler? Also, Fast Crash, check your forum inbox.
Title: Re: Appvariables for Highscores
Post by: Munchor on December 20, 2010, 05:51:18 am
Mind about showing him exactly how to make them simpler? Also, Fast Crash, check your forum inbox.

DJ, don't worry.


@Fast Crash: My code is written so that only I can read it, stupid names for variables, very crazy ways of doing things, it may look a 'wrong' and non-functional code, but it's good sometimes. However, when I program in team, which is not the case, I make things simpler and full of comments so that others can get it :D