generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: ??? RBX.Lua is Acting Strange

Previous Thread :: Next Thread 
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
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
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
10 Mar 2013 03:19 PM
hullo?
Report Abuse
kirkyturky12 is not online. kirkyturky12
Joined: 30 Apr 2010
Total Posts: 1915
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 is not online. coplox
Joined: 07 Jun 2008
Total Posts: 3252
10 Mar 2013 03:22 PM
Correction.
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
10 Mar 2013 03:24 PM
Well thank you kirky, I will use that in the future.
Report Abuse
RenderSettings is not online. RenderSettings
Joined: 16 Aug 2010
Total Posts: 2560
10 Mar 2013 03:28 PM
Try 'not (v.Name == "TextButton1" or v.Name == "TextButton2")' instead?
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
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 is not online. 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
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
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
Prehistoricman is not online. Prehistoricman
Joined: 20 Sep 2008
Total Posts: 12490
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
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
10 Mar 2013 05:12 PM
@Prehistoric
Excactly.
Report Abuse
Riderj is not online. 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
Prehistoricman is not online. Prehistoricman
Joined: 20 Sep 2008
Total Posts: 12490
10 Mar 2013 05:14 PM
if false == "TextButton1" then

>Lua: derp
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
10 Mar 2013 05:22 PM
Well like a previous person suggested, I'll just use '~='
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image