Author Topic: Appvariables for Highscores  (Read 13406 times)

0 Members and 1 Guest are viewing this topic.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Appvariables for Highscores
« 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.

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
« Last Edit: December 18, 2010, 06:46:27 am by ScoutDavid »

Offline Fast Crash

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 192
  • Rating: +45/-7
  • Virus of tomorrow
    • View Profile
Re: Appvariables for Highscores
« Reply #1 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!
« Last Edit: December 18, 2010, 09:39:30 am by Fast Crash »

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Appvariables for Highscores
« Reply #2 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 :)
« Last Edit: April 19, 2011, 01:20:55 pm by Scout »

Offline Fast Crash

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 192
  • Rating: +45/-7
  • Virus of tomorrow
    • View Profile
Re: Appvariables for Highscores
« Reply #3 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 .
« Last Edit: December 18, 2010, 09:46:03 am by Fast Crash »

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Appvariables for Highscores
« Reply #4 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

* scoutdavid wonders

Thanks!
« Last Edit: April 19, 2011, 01:19:29 pm by Scout »

Offline Fast Crash

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 192
  • Rating: +45/-7
  • Virus of tomorrow
    • View Profile
Re: Appvariables for Highscores
« Reply #5 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

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Appvariables for Highscores
« Reply #6 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 :)



Offline Fast Crash

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 192
  • Rating: +45/-7
  • Virus of tomorrow
    • View Profile
Re: Appvariables for Highscores
« Reply #7 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.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Appvariables for Highscores
« Reply #8 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

Offline Fast Crash

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 192
  • Rating: +45/-7
  • Virus of tomorrow
    • View Profile
Re: Appvariables for Highscores
« Reply #9 on: December 18, 2010, 10:09:48 am »
I'm playing civilization V so it will be later  :D

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Appvariables for Highscores
« Reply #10 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.

Offline Fast Crash

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 192
  • Rating: +45/-7
  • Virus of tomorrow
    • View Profile
Re: Appvariables for Highscores
« Reply #11 on: December 18, 2010, 10:21:23 am »
wow nice  :D
I think i'll use it in all my games  :)

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Appvariables for Highscores
« Reply #12 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
« Last Edit: December 18, 2010, 12:29:28 pm by ScoutDavid »

Offline Fast Crash

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 192
  • Rating: +45/-7
  • Virus of tomorrow
    • View Profile
Re: Appvariables for Highscores
« Reply #13 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
« Last Edit: December 18, 2010, 12:31:53 pm by Fast Crash »

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Appvariables for Highscores
« Reply #14 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)
« Last Edit: December 18, 2010, 12:33:52 pm by ScoutDavid »