Author Topic: Some questions: Toggle button, Buffers, Appvars  (Read 7379 times)

0 Members and 1 Guest are viewing this topic.

Offline MGOS

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +95/-0
    • View Profile
Some questions: Toggle button, Buffers, Appvars
« on: October 30, 2011, 07:28:39 am »
Planning my new project I'm going to make in axe, I came across some questions about how to do stuff in axe (V 1.0.5)

1. How can you make it that a variable toggles from 0 to 1 and vice versa if you press a special key, but it doesn't keep toggling when you hold it?
It shouldn't influence the other getkeys for movement, etc. in the same loop.

2. Is it possible to display two buffers on top of each other (or / xor) without having greyscale?

3. Is there a short way of letting to user chose from a bunch of saved files (appvars) to reload or chose the file to save the data, without having that many If-statements?

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: Some questions: Toggle button, Buffers, Appvars
« Reply #1 on: October 30, 2011, 08:46:08 am »
1. How can you make it that a variable toggles from 0 to 1 and vice versa if you press a special key, but it doesn't keep toggling when you hold it?
It shouldn't influence the other getkeys for movement, etc. in the same loop.
What I would do is something like this:
Code: [Select]
0→D
Repeat getKey(15)
getKey(9)→C
!If C
0→D
End
If C+D=1
1→D
End
....
End
I am not sure if this will work, but you should be able to use D to get the Enter key. It should only return 1 when you press it, but if you keep holding it, you should get 0.
*I have not tested this and I have almost no experience with Axe, so backup your data before using this code!
EDIT: Here is my attempt at further analysing my code XD Don't try this at home, kids O.O
Code: [Select]
0→D
Repeat getKey(15)
getKey(9)→C
C*D+C and 1→D
....
End

EDIT2:And even more O.O
Code: [Select]
0→D
Repeat getKey(15)
getKey(9)→C
C and D or C and 1→D
....
End
I think is the fastest method and smallest, but I am not sure...

Offline MGOS

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +95/-0
    • View Profile
Re: Some questions: Toggle button, Buffers, Appvars
« Reply #2 on: October 30, 2011, 09:07:38 am »
Thanks Xeda for your attempt solving my problem, but I think it isn't exactly that what I'm looking for.

I will explain what I need:
Let's say D is our toggle variable (at the beginning 0), and Enter the key.
So if I press Enter, D toggles to 1.
If I hold down the button, nothing should happen.
If I release the button, nothing should happen.
If I press Enter again, D toggles back to 0.
If I hold down the button, nothing should happen.
If I release the button again, nothing should happen.

Edit:
This is the way I do not want it:
Code: [Select]
0->D
Repeat getkey(15)
If getkey(9)
  If D
    0->D
  Else
    1->D
  End
End
...
End
« Last Edit: November 04, 2011, 08:49:57 am by MGOS »

Offline jacobly

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 205
  • Rating: +161/-1
    • View Profile
Re: Some questions: Toggle button, Buffers, Appvars
« Reply #3 on: October 30, 2011, 03:41:03 pm »
The easiest way would be to use another variable.
Code: [Select]
0➔D+1➔E .this stores 0 to D and 1 to E
Repeat getKey(15)
 If getKey(9) and E
  D xor 1➔D .this toggles D
  0➔E
 Else
  1➔E
 End
...
End
« Last Edit: October 30, 2011, 03:47:02 pm by jacobly »

Offline MGOS

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +95/-0
    • View Profile
Re: Some questions: Toggle button, Buffers, Appvars
« Reply #4 on: October 30, 2011, 05:27:12 pm »
Thanks jacobly. I will try that out.

Has someone any idea to solve the other problems?

Offline FinaleTI

  • Believe in the pony that believes in you!
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1830
  • Rating: +121/-2
  • Believe in the pony that believes in you!
    • View Profile
    • dmuckerman.tumblr.com
Re: Some questions: Toggle button, Buffers, Appvars
« Reply #5 on: October 30, 2011, 05:35:27 pm »
Perhaps this might:
Code: [Select]
Repeat getKey(15)
  getKey➔C
  If C=9
    D xor 1➔D
  End
End
getKey➔Var uses the same kind of getKey as BASIC, meaning only the arrows and DEL repeat, so D shouldn't toggle if ENTER is held, though I haven't actually tested this code yet.


Spoiler For Projects:

My projects haven't been worked on in a while, so they're all on hiatus for the time being. I do hope to eventually return to them in some form or another...

Spoiler For Pokemon TI:
Axe port of Pokemon Red/Blue to the 83+/84+ family. On hold.

Spoiler For Nostalgia:
My big personal project, an original RPG about dimensional travel and a few heroes tasked with saving the world.
Coding-wise, on hold, but I am re-working the story.

Spoiler For Finale's Super Insane Tunnel Pack of Doom:
I will be combining Blur and Collision Course into a single gamepack. On hold.

Spoiler For Nostalgia Origins: Sky's Story:
Prequel to Nostalgia. On hold, especially while the story is re-worked.

Offline MGOS

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +95/-0
    • View Profile
Re: Some questions: Toggle button, Buffers, Appvars
« Reply #6 on: October 30, 2011, 05:43:03 pm »
Ok, but then I cannot use the other keys the same time, right?

Offline chattahippie

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +27/-0
  • Super Member! :D
    • View Profile
Re: Some questions: Toggle button, Buffers, Appvars
« Reply #7 on: October 30, 2011, 05:52:33 pm »
2. Is it possible to display two buffers on top of each other (or / xor) without having greyscale?

Code: [Select]
For(Y,0,63)
For(X,0,95)
If pxl-test(X,Y)^r
Pxl-On(X,Y)      // Pxl-On for or, Pxl-Change for xor
End
End
End

This is slow, but it gets the task done

Offline jacobly

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 205
  • Rating: +161/-1
    • View Profile
Re: Some questions: Toggle button, Buffers, Appvars
« Reply #8 on: October 30, 2011, 06:19:24 pm »
Code: [Select]
For(A,L₃,L₃+767)
 {A} or {A−L₃+L₆}➔{A}
End

This is much faster!
Edit: even faster!
« Last Edit: October 30, 2011, 06:21:06 pm by jacobly »

Offline MGOS

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +95/-0
    • View Profile
Re: Some questions: Toggle button, Buffers, Appvars
« Reply #9 on: October 30, 2011, 06:29:47 pm »
Thanks a lot, jacobly! - I think that is fast enough, and you can use arbitary buffers too.

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
Re: Some questions: Toggle button, Buffers, Appvars
« Reply #10 on: October 30, 2011, 06:52:11 pm »
3. Is there a short way of letting to user chose from a bunch of saved files (appvars) to reload or chose the file to save the data, without having that many If-statements?

You have two options - you can either use Memkit to get the names of all the appvars in memory, and then display them as a scrolling list, and have the user choose between them, or you can use or write a custom input function, like the one in Firefall, that one's pretty good.
Completed Projects:
   >> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
   >> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.


Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)



Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Some questions: Toggle button, Buffers, Appvars
« Reply #11 on: October 30, 2011, 07:22:41 pm »
Code: [Select]
For(A,L?,L?+767)
 {A} or {A?L?+L?}?{A}
End

This is much faster!
Edit: even faster!
I believe this would do it even faster:
http://ourl.ca/4050/123594

Offline MGOS

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +95/-0
    • View Profile
Re: Some questions: Toggle button, Buffers, Appvars
« Reply #12 on: October 31, 2011, 05:05:08 am »
[...] I calculated that the following loop runs about 40 times per second at 6MHz:

Code: [Select]
Repeat getKey(15)
For(A,0,383)
.That ﹢ symbol is the 16-bit OR operator
{A*2+L₆}ʳ﹢{A*2+L₃}ʳ→{A*2+L₆}ʳ
End
C+1→C
End

Yeah, I will try that.

3. Is there a short way of letting to user chose from a bunch of saved files (appvars) to reload or chose the file to save the data, without having that many If-statements?

You have two options - you can either use Memkit to get the names of all the appvars in memory, and then display them as a scrolling list, and have the user choose between them, or you can use or write a custom input function, like the one in Firefall, that one's pretty good.
I think I'm going to make a custom menu with limited amout of Appvars - that's enough for the beginning - maybe I canm fix that later if Axe has new features to do that more easily.

Thanks a lot, guys!

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Some questions: Toggle button, Buffers, Appvars
« Reply #13 on: November 04, 2011, 08:17:58 am »
1. jacobly's solution is what I would do too.

2. You can do it even faster with the new speed loop: ;D
Code: [Select]
L₆
For(383)
 {➔A}ʳ﹢{A+L₃-L₆}ʳ➔{A}ʳ+1
End

3. If your saved data takes a standard form like "appvSAVE1", "appvSAVE2", "appvSAVE3", etc.  Then you can construct the first part of the string in some memory by doing copy("appvSAVE0",L1,7) and then make the string the Nth file by doing N+'0'➔{L1+5}.  Now all you have to do to load the file is just GetCalc(L1) which uses the string you just constructed.  If you want to list all the appvars on the calculator that start with your custom header and choose from those, you'll have to use memkit.
« Last Edit: November 04, 2011, 03:41:17 pm by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline MGOS

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +95/-0
    • View Profile
Re: Some questions: Toggle button, Buffers, Appvars
« Reply #14 on: November 04, 2011, 08:48:01 am »
1. jacobly's solution is what I would do too.
I did that and it works quite good.


Quote from: Quigibo
2. You can do it even faster with the new speed loop: ;D
Code: [Select]
L₆
For(383)
 {➔A}ʳ﹢{A+L₃-L₆}ʳ➔{A}ʳ+2
End
I just realized that there is this cool new loop. It might be useful for something, but for my problem I found another way avoiding drawing two buffers over each other.


Quote from: Quigibo
3. If your saved data takes a standard form like "appvSAVE1", "appvSAVE2", "appvSAVE3", etc.  Then you can construct the first part of the string in some memory by doing copy("appvSAVE0",L1,7) and then make the string the Nth file by doing N+'0'➔{L1+5}.  Now all you have to do to load the file is just GetCalc(L1) which uses the string you just constructed.  If you want to list all the appvars on the calculator that start with your custom header and choose from those, you'll have to use memkit.
Due to the big program size I reached I think it's better to use a simple way, so I will just have some default save files the user can choose from. But still thanks Quigibo.