drgn42
|
  |
| Joined: 11 Feb 2010 |
| Total Posts: 3231 |
|
|
| 16 Nov 2014 06:26 PM |
| I was wondering if I could change a bool value to the opposite of what it is without using an if statement to check to see what it is. I have a constantly changing bool value, and I need to make it so when you click, it changes 3 bool values to the opposite of what they are, but I don't want to have to use 6 if statements to check each possible scenario. Help would be appreciated. |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 16 Nov 2014 06:28 PM |
bool = true
bool = not bool |
|
|
| Report Abuse |
|
|
drgn42
|
  |
| Joined: 11 Feb 2010 |
| Total Posts: 3231 |
|
|
| 16 Nov 2014 06:30 PM |
Well duh. But I'd still need to do this
if bool1 == true then bool1 = false return end if bool1 == false then bool1 = true return end
if bool2 == true then bool2 = false return end if bool2 == false then bool2 = true return end
if bool3 == true then bool3 = false return end if bool3 == false then bool3 = true return end
What I'd rather do is
bool1 = opposite value bool2 = opposite value bool3 = opposite value
I just dont know how to do it. |
|
|
| Report Abuse |
|
|
drgn42
|
  |
| Joined: 11 Feb 2010 |
| Total Posts: 3231 |
|
|
| 16 Nov 2014 06:31 PM |
| Unless you were saying bool = not bool was the answer. I think I see what you were saying now. |
|
|
| Report Abuse |
|
|
drgn42
|
  |
| Joined: 11 Feb 2010 |
| Total Posts: 3231 |
|
|
| 16 Nov 2014 06:33 PM |
| Oh... Thanks. It does work. |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 16 Nov 2014 06:34 PM |
bool1 = not bool1 bool2 = not bool2 bool3 = not bool3
"not" negates boolean values. print(not true) >false print(not false) >true
So: bool = true bool = not bool print(bool) >false
|
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 16 Nov 2014 06:34 PM |
| You're welcome and sorry I was late :P |
|
|
| Report Abuse |
|
|