Jump to content

Photo

Can someone clarify the use of a Debounce bit and joy0fire for me?


6 replies to this topic

#1 disjaukifa OFFLINE  

disjaukifa

    River Patroller

  • 2,125 posts
  • Berzerker In Training
  • Location:Research Triangle North Carolina

Posted Thu Sep 29, 2011 11:07 AM

 
 
rem ************************
   rem My various bit variables
   rem ************************
   dim Bit0_Debounce_Reset = var47
   dim Bit1_Debounce_Fire = var47
   dim Bit2_Game_Mode = var47
 
 
   dim Master_Counter = var46
   dim Frame_Counter = var45
 
 
   goto titleScreen
 
   rem ************************
   rem Hard Reset. Takes user back
   rem to the title screen and clears out
   rem all the variables as well.
   rem ************************
Hard_Reset
   pfclear
   drawscreen
   for temp5 = 0 to 25 : a[temp5] = 0 : next
   for temp5 = 0 to 46 : var0[temp5] = 0 : next
   Bit0_Debounce_Reset{0} = 1
 
 
titleScreen
   gosub titledrawscreen bank7
   if !switchreset && !joy0fire then Bit0_Debounce_Reset{0} = 0 : goto titleScreen
   if Bit0_Debounce_Reset{0} then goto titleScreen
 
   goto GameSetup

I'm trying to wrap my head around using bits for booleans to control various aspects of game I'm working on, and I'm missing something. Can someone explain to me exactly how the above code works so I can use it in other places!

Essential what I want to do in my code is make sure that the fire button won't tigger an action until it has been release, but for whatever reason, I can't seem to wrap my head around this bit codes to act as booleans and check it.

Thanks

Edited by disjaukifa, Thu Sep 29, 2011 11:09 AM.


#2 disjaukifa OFFLINE  

disjaukifa

    River Patroller

  • Topic Starter
  • 2,125 posts
  • Berzerker In Training
  • Location:Research Triangle North Carolina

Posted Thu Sep 29, 2011 11:41 AM

Update. I've figured out the bit operater situation in the game I'm currently working on, but I would love some clarification otnh e coding example above which I know works, specifically how do you get out of the TitleScreen loop.

Thanks

Edited by disjaukifa, Thu Sep 29, 2011 11:45 AM.


#3 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 24,727 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Thu Sep 29, 2011 11:45 AM

Have you looked at the code here:

http://www.randomter...itching_example

#4 disjaukifa OFFLINE  

disjaukifa

    River Patroller

  • Topic Starter
  • 2,125 posts
  • Berzerker In Training
  • Location:Research Triangle North Carolina

Posted Thu Sep 29, 2011 11:53 AM

Have you looked at the code here:

http://www.randomter...itching_example


I have not looked at that specific example but I have been on that page most of last night and parts of this morning.

Edited by disjaukifa, Thu Sep 29, 2011 11:54 AM.


#5 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 24,727 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Thu Sep 29, 2011 11:56 AM


Have you looked at the code here:

http://www.randomter...itching_example


I have not looked at that specific example but I have been on that page most of last night and parts of this morning.

Take a look at it. Just about every line of code is explained using REM statements.

#6 ScumSoft OFFLINE  

ScumSoft

    Moonsweeper

  • 348 posts
  • Location:Polysorbate 60

Posted Thu Sep 29, 2011 5:12 PM

Basic flow control for debounce works like in the example, but that can look slightly confusing to those just getting introduced to bB.
Conceptualize it like this with:
rem if I press the fire button it should set the debounce bit and perform some bit of code
rem also I want to see if the debounce is still set to 1, if it is then dont proceed until debounce gets reset to 0
rem if the player is no longer holding down the fire button, then clear the debounce bit
 
  if joy0fire then bit_debounce = 1
wait_until_debounce_clear
  if !joy0fire then bit_debounce = 0
  if bit_debounce then goto wait_until_debounce_clear
When you say "if bit_blah then dosomething", your asking if the bit is 1, when you say "if !bit_blah then dosomething", your asking if the bit is 0
Hope this helped, RT's examples are good references to keep referring back to when you forget how things are supposed to work.

Edited by ScumSoft, Thu Sep 29, 2011 5:19 PM.


#7 disjaukifa OFFLINE  

disjaukifa

    River Patroller

  • Topic Starter
  • 2,125 posts
  • Berzerker In Training
  • Location:Research Triangle North Carolina

Posted Fri Sep 30, 2011 7:19 AM

Basic flow control for debounce works like in the example, but that can look slightly confusing to those just getting introduced to bB.
Conceptualize it like this with:

rem if I press the fire button it should set the debounce bit and perform some bit of code
rem also I want to see if the debounce is still set to 1, if it is then dont proceed until debounce gets reset to 0
rem if the player is no longer holding down the fire button, then clear the debounce bit
 
  if joy0fire then bit_debounce = 1
wait_until_debounce_clear
  if !joy0fire then bit_debounce = 0
  if bit_debounce then goto wait_until_debounce_clear
When you say "if bit_blah then dosomething", your asking if the bit is 1, when you say "if !bit_blah then dosomething", your asking if the bit is 0
Hope this helped, RT's examples are good references to keep referring back to when you forget how things are supposed to work.


Yep it did, the problem I was having was actually a typo in my code that I just completely missed, I was checking Bit3_Jump_Peak{3} however when I went to modify it to see if it hit its peak I was doing the following

if player0y == 35 && !Bit3_Jump_Peak{3} then Bit3_Jump_Peak{0} = 1

And I was using that boolean bit to help check for the toggle of my Debounce boolean bit as well, so it was messing up all my code.

Edited by disjaukifa, Fri Sep 30, 2011 7:19 AM.





0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users