Author Topic: Controll routine question  (Read 4103 times)

0 Members and 1 Guest are viewing this topic.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Controll routine question
« on: August 03, 2011, 06:35:51 am »
Been struggling with this for a while now; the principle I'm looking for is simple and straightforward: react to the last button pressed, regardless of whatever else might be pressed or released.
So if you press '1', it perorms 'Label1' once, even if you have 2-9 held down at the same time already, or release random other buttons that were being held down before. Push the button, perform thát routine once. Nóthing more, nothing less.  ;)
I'm sure there must be a simple way to do this, but... I'm newby.  :-[
If anyone has any tips on how to do this, it'd be greatly appreciated!

Thanks alot in advance.


79% of all statistics are made up randomly.

Offline chattahippie

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +27/-0
  • Super Member! :D
    • View Profile
Re: Controll routine question
« Reply #1 on: August 03, 2011, 06:39:16 am »
Been struggling with this for a while now; the principle I'm looking for is simple and straightforward: react to the last button pressed, regardless of whatever else might be pressed or released.
So if you press '1', it perorms 'Label1' once, even if you have 2-9 held down at the same time already, or release random other buttons that were being held down before. Push the button, perform thát routine once. Nóthing more, nothing less.  ;)
I'm sure there must be a simple way to do this, but... I'm newby.  :-[
If anyone has any tips on how to do this, it'd be greatly appreciated!

Thanks alot in advance.

What language, Axe?

For something like this in Axe, I would do:
Code: [Select]
Repeat getKey(15)
If getKey(34) and A=/=1     //getKey(34) is the one button
sub(1)
End
If getKey(26) and A =/=1   //getKey(26) is the 2 button
sub(2)
End
.Repeat If loop for getKeys# 18 (3), 35 (4), 27 (5), 19 (6), 36 (7), 28 (8), 20 (9), Then finish it with
!If getKey and A=1
0->A
End
End
Return    //Keeps the program from running the subroutines from after the Repeat loop is cancelled

Lbl 1
blah   //This should include a 1->A also, to keep from repeating
End
Lbl 2
blah    //Same here
End
.Write the rest of subroutines, make sure they have 1 ->A

It's not very optimized, but it should work :P
« Last Edit: August 03, 2011, 06:52:45 am by chattahippie »

Ashbad

  • Guest
Re: Controll routine question
« Reply #2 on: August 03, 2011, 07:50:33 am »
It's in the assembly subforum, so axe code won't help him..

I suggest you can keep something like a key table that keeps track of all keys currently pressed, and updates when a new one is pressed.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: Controll routine question
« Reply #3 on: August 03, 2011, 08:32:24 am »
It's in the assembly subforum, so axe code won't help him..

I suggest you can keep something like a key table that keeps track of all keys currently pressed, and updates when a new one is pressed.
Assembly indeed, and a Key table, eh? I'll look into how to make/work with those then. Thank you for the advice.


79% of all statistics are made up randomly.

Offline chattahippie

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +27/-0
  • Super Member! :D
    • View Profile
Re: Controll routine question
« Reply #4 on: August 03, 2011, 08:40:49 am »
I guess you could compile axe, then just optimize it a lot... but that seems inefficient

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: Controll routine question
« Reply #5 on: August 03, 2011, 09:57:57 am »
I guess you could compile axe, then just optimize it a lot... but that seems inefficient
I... have zilch experience with Axe, sorry. Q_Q

EDIT:
Oh, and it doesn't really concern the 1-9 keys; it's just for 5 keys of the same group (namely Yequ-Graph). I had this other idea on how to accomplish this; will post the (probably waay to long and inefficient) routine later. <-- Failed. Using this now, but it's still not what I wanted, plus I bet it could be optimized, ghehe (BIG thanks to ThePenguin for this):
Code: [Select]
tracePressed:
push af
set 0, c
bit 0, b
PUSH BC
jr nz, traceIsHeld
LD A, 58
LD (CheckYequ), A
LD (CheckWindow), A
LD (CheckZoom), A
LD (CheckTrace), A
LD (CheckGraph), A
LD A, -58                                    ;
LD (ButtonPressed), A                   ;
CALL CheckYSprites                         ;you can ignore these in each loop, I just want this to be performed with the appropriate number stored in (ButtonPressed)
jp graphDone
traceIsHeld:
    LD A, 58                                      ;
    LD (xpos), A                                 ;
CALL sprendcall                                ; also ignore this, it's just something for the rest of the script.
LD A, (CheckTrace)
CP 58
JP z, graphdone
LD A, 58
LD (CheckTrace), A
LD A, -58
LD (ButtonPressed), A
CALL CheckYSprites
jr graphDone
zoomPressed:
push af
set 0, c
bit 0, b
PUSH BC
jr nz, zoomIsHeld
LD A, 44
LD (CheckYequ), A
LD (CheckWindow), A
LD (CheckZoom), A
LD (CheckTrace), A
LD (CheckGraph), A
LD A, -44
LD (ButtonPressed), A
CALL CheckYSprites
jr graphDone
zoomIsHeld:
    LD A, 44
    LD (xpos), A
CALL sprendcall
LD A, (CheckZoom)
CP 44
JR z, graphdone
LD A, 44
LD (CheckZoom), A
LD A, -44
LD (ButtonPressed), A
CALL CheckYSprites
jr graphDone
graphPressed:
push af
set 0, c
bit 0, b
PUSH BC
jr nz, graphIsHeld
LD A, 72
LD (CheckYequ), A
LD (CheckWindow), A
LD (CheckZoom), A
LD (CheckTrace), A
LD (CheckGraph), A
LD A, -72
LD (ButtonPressed), A
CALL CheckYSprites
jr graphDone
graphIsHeld:
CALL graphsprshow
LD A, (CheckGraph)
CP 72
JR z, graphdone
LD A, 72
LD (CheckGraph), A
LD A, -72
LD (ButtonPressed), A
CALL CheckYSprites
graphDone:
pop bc
pop af
ret
windowPressed:
push af
set 0, c
bit 0, b
PUSH BC
jr nz, windowIsHeld
LD A, 30
LD (CheckYequ), A
LD (CheckWindow), A
LD (CheckZoom), A
LD (CheckTrace), A
LD (CheckGraph), A
LD A, -30
LD (ButtonPressed), A
CALL CheckYSprites
jr graphDone
windowIsHeld:
    LD A, 30
    LD (xpos), A
CALL sprendcall
LD A, (CheckWindow)
CP 30
JR z, graphdone
LD A, 30
LD (CheckWindow), A
LD A, -30
LD (ButtonPressed), A
CALL CheckYSprites
jr graphDone
YequPressed:
push af
set 0, c
bit 0, b
PUSH BC
jr nz, YequIsHeld
LD A, 16
LD (CheckYequ), A
LD (CheckWindow), A
LD (CheckZoom), A
LD (CheckTrace), A
LD (CheckGraph), A
LD A, -16
LD (ButtonPressed), A
CALL CheckYSprites
jr graphDone
YequIsHeld:
    LD A, 16
    LD (xpos), A
CALL sprendcall
LD A, (CheckYequ)
CP 16
JR z, graphdone
LD A, 16
LD (CheckYequ), A
LD A, -16
LD (ButtonPressed), A
CALL CheckYSprites
jp graphDone
Works álmost perfectly, except that when you, lets say, hold Yequ then press the other four remaining buttons (while still holding Yequ) it won't react to any keypress untill you've released áll buttons. Then it resets.
So 'Hold Yequ' --works--> 'Press Window' --works--> 'Release Window' --works--> 'Press Window' --ignores last press :(--> ...
Sorry for being wordy, but hopefully someone gets it as it shouldn't be too difficult (yet I'm clueless).
« Last Edit: August 04, 2011, 01:30:20 pm by Jerros »


79% of all statistics are made up randomly.