Sep-11-2018, 10:24 AM
Can you tell me why my for loop isn't working?
I'm working on managing my input from my game-pad controller device.
I store most of the details in a list.
I was trying to reset/clear the button array section of the list that holds the button states.
I thought I could use "button_state =0" in a for loop, but its not working the way I hoped.
I'm working on managing my input from my game-pad controller device.
I store most of the details in a list.
I was trying to reset/clear the button array section of the list that holds the button states.
I thought I could use "button_state =0" in a for loop, but its not working the way I hoped.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
C_LIST_BUTTONS_ARRAY = 4 # This list represents data obtained from game-pad. controller = [ 0 , 0 , 0 , 0 , [ 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ]] print ( "Initial state of array." ) for button_index in range ( len (controller[C_LIST_BUTTONS_ARRAY])): button_state = controller[C_LIST_BUTTONS_ARRAY][button_index] print (button_state, end = "") # end for print () # --------------------------------------------------------------------------- print ( "\n\nResults of for loop using in object" ) # Reset all the button states in the button array. for button_state in controller[C_LIST_BUTTONS_ARRAY]: button_state = 0 # end for # _. for button_state in controller[C_LIST_BUTTONS_ARRAY]: print (button_state, end = "") # end for print () # --------------------------------------------------------------------------- print ( "\n\nResults of for loop using range." ) # Reset all the button states in the button array. for button_index in range ( len (controller[C_LIST_BUTTONS_ARRAY])): controller[C_LIST_BUTTONS_ARRAY][button_index] = 0 # end for # _. for button_state in controller[C_LIST_BUTTONS_ARRAY]: print (button_state, end = "") # end for print () |
Output:Initial state of array.
10000000000
Results of for loop using in object
10000000000
Results of for loop using range.
00000000000