esplonky #1 Posted June 17, 2012 is there any way to make my score go up by one when the fire button is pressed, as in joy0fire is pressed, score goes to 1, joy0fire is pressed again, score goes to 2, etc. Quote Share this post Link to post Share on other sites
+Random Terrain #2 Posted June 17, 2012 Looks like you are asking for a fire button debounce: ex_debounce_2012y_06m_16d_2328t.bas ex_debounce_2012y_06m_16d_2328t.bin 1 Quote Share this post Link to post Share on other sites
esplonky #3 Posted June 17, 2012 it compiles and all, but didn't do squat. Quote Share this post Link to post Share on other sites
+Random Terrain #4 Posted June 17, 2012 it compiles and all, but didn't do squat. Do you see the score? Is it increasing by one every time you press the fire button? Quote Share this post Link to post Share on other sites
MausGames #5 Posted June 17, 2012 (edited) You need to use a variable, or flag. I'm sure what RT posted is considerably better, but something like: if joy0fire && a = 0 then a = 1 if a = 1 then score = score + 1 : a = 2 if !joy0fire && a <> 0 then a = 0 Edited June 17, 2012 by MausGames 1 Quote Share this post Link to post Share on other sites
esplonky #6 Posted June 17, 2012 RT, no, it just keeps going up up up as i hold down the fire button. Quote Share this post Link to post Share on other sites
+Random Terrain #7 Posted June 17, 2012 RT, no, it just keeps going up up up as i hold down the fire button. So when you run the .bin file I also uploaded, does it do the same thing? It works for me. You have to press and release the fire button for it to add one to the score. Quote Share this post Link to post Share on other sites
esplonky #8 Posted June 17, 2012 I know, it works with your .bin, and I put everything in my code exactly how it was in yours, i put the dim at the header, before all the other code, I put the other code in my main_loop and then the skip_fire i put right after my main_loop Quote Share this post Link to post Share on other sites
+Random Terrain #9 Posted June 17, 2012 I know, it works with your .bin, and I put everything in my code exactly how it was in yours, i put the dim at the header, before all the other code, I put the other code in my main_loop and then the skip_fire i put right after my main_loop Here's the code again: rem **************************************************************** rem * rem * Create aliases for variables. rem * rem **************************************************************** rem ' rem ' (You can have more than one alias for each variable.) rem ' rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' rem ' BitOp variable for debouncing the fire button. rem ' dim _Bit0_Debounce_Fire = d __Main_Loop rem @# Main Loop rem **************************************************************** rem **************************************************************** rem * rem * rem * Main Loop rem * rem * rem **************************************************************** rem **************************************************************** rem **************************************************************** rem * rem * Score color. rem * rem ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' scorecolor = $1A rem **************************************************************** rem * rem * Debounce fire button. rem * rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' rem ' If fire button not pressed, clear debounce bit and skip. rem ' if !joy0fire then _Bit0_Debounce_Fire{0} = 0 : goto __Skip_Fire rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' If fire button is pressed, but debounce bit is on, skip. rem ' if _Bit0_Debounce_Fire{0} then goto __Skip_Fire rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' Turn on fire button debounce bit. rem ' _Bit0_Debounce_Fire{0} = 1 rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' Add one to score. rem ' score = score + 1 __Skip_Fire rem **************************************************************** rem * rem * Draw the screen. rem * rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' drawscreen goto __Main_Loop This part needs to be inside of your main loop: rem **************************************************************** rem * rem * Debounce fire button. rem * rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' rem ' If fire button not pressed, clear debounce bit and skip. rem ' if !joy0fire then _Bit0_Debounce_Fire{0} = 0 : goto __Skip_Fire rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' If fire button is pressed, but debounce bit is on, skip. rem ' if _Bit0_Debounce_Fire{0} then goto __Skip_Fire rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' Turn on fire button debounce bit. rem ' _Bit0_Debounce_Fire{0} = 1 rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' Add one to score. rem ' score = score + 1 __Skip_Fire Quote Share this post Link to post Share on other sites
esplonky #10 Posted June 17, 2012 that's what is in my main_loop. and I just solved it. I forgot to take out: if joy0fire then score = score + 1 so now it works. thanks! Quote Share this post Link to post Share on other sites
MausGames #11 Posted June 17, 2012 This is why I hate bit flags. I know the squeeze is supposed to be part of the fun, but I'm too dim for dim, it ends up being too much. Quote Share this post Link to post Share on other sites
+Random Terrain #12 Posted June 17, 2012 This is why I hate bit flags. I know the squeeze is supposed to be part of the fun, but I'm too dim for dim, it ends up being too much. That's why I use: _Bit0_Blah_Blah{0} _Bit1_Blah_Blah{1} _Bit2_Blah_Blah{2} _Bit3_Blah_Blah{3} _Bit4_Blah_Blah{4} _Bit5_Blah_Blah{5} _Bit6_Blah_Blah{6} _Bit7_Blah_Blah{7} The bit number at the beginning tells me what goes between the curly brackets. I never have to scroll back up and look what I put in a REM statement that describes it. What I need to know is right in front of me. Quote Share this post Link to post Share on other sites
esplonky #13 Posted June 17, 2012 bit ops confuse me to hell Quote Share this post Link to post Share on other sites
+Random Terrain #14 Posted June 17, 2012 bit ops confuse me to hell Everything confused me all to hell at the beginning. I didn't even understand how you could play a sound effect while other things happened at the same time until it was explained to me. I didn't know how to do an attract mode and a lot of other stuff until I got answers from better programmers in this forum. Bits are easy if you think of them as 8 tiny variables inside of a normal variable. A lot of things can be done with these 'bit variables' instead of wasting an entire normal variable. As long as your aliases are descriptive, it's hard to mess up. Here's an example: rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' BitOp variables. rem ' dim BitOp_01 = q rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' Player is falling if on. rem ' dim Bit0_Fall_in_Progress = q rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' Player moved to the left if on. rem ' dim Bit1_Slide_Left_in_Progress = q rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' Player moved to the right if on. rem ' dim Bit2_Slide_Right_in_Progress = q rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' Player can't hold down fire button to repeatedly jump. rem ' dim Bit3_Fire_Debounce = q rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' Flips player sprite when necessary. rem ' dim Bit4_Flip_P1 = q rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' Lets player slide when direction changes. rem ' dim Bit5_Ground_Slide_in_Progress = q rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' Allows player to slide while ducking. rem ' dim Bit6_Duck_in_Progress = q 1 Quote Share this post Link to post Share on other sites
esplonky #15 Posted June 17, 2012 ah, so instead of only having 26 variables, I can have 208? Quote Share this post Link to post Share on other sites
+Random Terrain #16 Posted June 17, 2012 ah, so instead of only having 26 variables, I can have 208? Yeah, I have this on the bB page: http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#bit Accessing the bits of a variable is almost like turning it into 8 separate variables. Instead of having only 26 variables, you potentially have 208. You just have to remember that these itty-bitty variables can only hold 0 or 1. Quote Share this post Link to post Share on other sites
esplonky #17 Posted June 17, 2012 oh, i read up on bit ops there, guess i didn't see that. Quote Share this post Link to post Share on other sites
+Random Terrain #18 Posted June 17, 2012 oh, i read up on bit ops there, guess i didn't see that. Maybe I should move it higher in that section or make a did you know box. Quote Share this post Link to post Share on other sites
esplonky #19 Posted June 17, 2012 I miss a lot of things when I read. so no worries Quote Share this post Link to post Share on other sites
+Gemintronic #20 Posted June 18, 2012 (edited) Programmers sometimes use a single bit as a "boolean" value. You don't really need to know what "boolean" means besides that 0 is false and 1 is true. This saves alot of space because instead of 1 0-255 value now you have 8 true or false variables. So instead of a = 0-255 we have a{0} = 0 or 1 (true or false) a{1} = 0 or 1 (true or false) a{2} = 0 or 1 (true or false) a{3} = 0 or 1 (true or false) a{4} = 0 or 1 (true or false) a{5} = 0 or 1 (true or false) a{6} = 0 or 1 (true or false) a{7} = 0 or 1 (true or false) There are many things in a game that are only true or false. If you use binary variables to represent 2 states (true or false) then you are using them as a boolean variable. I just wanted to clarify what "bit ops" or "flags" are in this thread Edited June 18, 2012 by theloon 1 Quote Share this post Link to post Share on other sites
esplonky #21 Posted June 19, 2012 I just wanted to clarify what "bit ops" or "flags" are in this thread and that's probably the best way to tell me Quote Share this post Link to post Share on other sites