First of all, apologies for the title, I couldn't think of a better one. What I want to do is to be able to reduce the amount of if statements in my code. Here is my code:
if var is "forwardThrustButton":
global forwardThrustButton
forwardThrustButton = res
elif var is "backThrustButton":
global backThrustButton
backThrustButton = res
elif var is "leftRotateButton":
global leftRotateButton
leftRotateButton = res
elif var is "rightRotateButton":
global rightRotateButton
rightRotateButton = res
elif var is "basicShootButton":
global basicShootButton
basicShootButton = res
elif var is "specialShootButton":
global specialShootButton
specialShootButton = res
elif var is "bombShootButton":
global bombShootButton
bombShootButton = res
As you can see I have a lot of if statements here, using a string that I have put into a function, and checking to see what that string is. This code works. What I want to do is to be able to pass the name of a variable into the function and just say var = res
. Thanks in advance.