|
| 10 Mar 2013 03:14 PM |
So while I was working on mah super awesome top secret project (yeh) I encountered an error in the conditional statements. I am certain it was a specific case, (because it worked elsewhere) so let me explain the situation.
I have two textbuttons that I want to ignore when iterating through a frame. So this is the basis of what the code looked like in the error:
for i, v in pairs(thatframeobject:GetChildren()) if v:IsA("TextButton") then if not v.Name == "TextButton1" and not v.Name == "TextButton2" then --Do stuff that I'm doing. end end end
The code registered the objects that are not TextButton1 and TextButton2, but those objects didn't pass the conditional statement. So this is what I did next:
for i, v in pairs(thatframeobject:GetChildren()) if v:IsA("TextButton") then if not v.Name == "TextButton1" then if not v.Name == "TextButton2" then --Do stuff that I'm doing. end end end end
Still, the objects passed the IsA() statement but didn't pass the name checking statement. So by then I was raging, so I did this:
for i, v in pairs(thatframeobject:GetChildren()) if v:IsA("TextButton") then if v.Name == "TextButton1" then else if v.Name == "TextButton2" then else --Do stuff that I'm doing. end end end end
And surprisingly, it worked. So I did some further tests to make sure I didn't mess up my previous if statement:
if not false and not false then print 'working' end
--> working
Am I not understanding something or is this a weird bug?
|
|
|
| Report Abuse |
|
|
| |
|
|
| 10 Mar 2013 03:21 PM |
I find that sometimes using 'not' can give you unexpected results. Try using ~= instead.
~KirkyTurky12, professional procrastinator.~ |
|
|
| Report Abuse |
|
|
coplox
|
  |
| Joined: 07 Jun 2008 |
| Total Posts: 3252 |
|
| |
|
|
| 10 Mar 2013 03:24 PM |
| Well thank you kirky, I will use that in the future. |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2013 03:28 PM |
| Try 'not (v.Name == "TextButton1" or v.Name == "TextButton2")' instead? |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2013 03:30 PM |
| I will go make ajustments right now. Thanks all, but any reasons why the not operator is working strangely? |
|
|
| Report Abuse |
|
|
Riderj
|
  |
| Joined: 15 Aug 2011 |
| Total Posts: 1534 |
|
|
| 10 Mar 2013 04:28 PM |
| It's not (see what I did there). Each conditional will be checked separately so if you want to check if something is NOT, you would have to check on both since they are separately read. The method shown above checks not with both of them. |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2013 04:37 PM |
@Rider That wasn't the issue, as this still didn't work correctly:
if not v.Name == "TextButton1" and not v.Name == "TextButton2" then |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2013 05:07 PM |
This is what it's doing:
if (not v.Name) == "TextButton1" and (not v.Name) == "TextButton2" then
This is what you want it to do:
if not (v.Name == "TextButton1") and not (v.Name == "TextButton2") then |
|
|
| Report Abuse |
|
|
| |
|
Riderj
|
  |
| Joined: 15 Aug 2011 |
| Total Posts: 1534 |
|
|
| 10 Mar 2013 05:14 PM |
| So there is not a shorthand way to add a 'not' to all the conditions in your if statement? |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2013 05:14 PM |
if false == "TextButton1" then
>Lua: derp |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2013 05:22 PM |
| Well like a previous person suggested, I'll just use '~=' |
|
|
| Report Abuse |
|
|