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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Prints twice error?

Previous Thread :: Next Thread 
iLordOfAviation is online. iLordOfAviation
Joined: 23 Mar 2012
Total Posts: 1325
28 May 2017 08:54 PM
script.Parent.MouseButton1Down:Connect(function(player)
local passed = true
for i,v in pairs(script.Parent.Parent:GetChildren()) do
if v.Name ~= "Submit" and not v.TextBox.Text:match("%S") then
passed = false
print(passed)
break
end
end
print(passed)
end)

This checks to see if a bunch of textboxes are blank or not, if there's anything blank it prints false, if nothing's blank it prints true. But there's 1 problem, when it prints false it prints twice, when it prints true it only prints once. Any ideas why this happens? Thanks in advance!


Report Abuse
nullfeels is not online. nullfeels
Joined: 31 Mar 2017
Total Posts: 1215
28 May 2017 09:05 PM
No, it prints the second "passed" regardless.

if v.Name ~= "Submit" and not v.TextBox.Text:match("%S") then
--if so
else
--if not
end
Report Abuse
nullfeels is not online. nullfeels
Joined: 31 Mar 2017
Total Posts: 1215
28 May 2017 09:07 PM
Or am I just not understanding the problem?
Report Abuse
iLordOfAviation is online. iLordOfAviation
Joined: 23 Mar 2012
Total Posts: 1325
28 May 2017 09:08 PM
ya, I'm just stupid,

script.Parent.MouseButton1Down:Connect(function(player)
local passed = true
for i,v in pairs(script.Parent.Parent:GetChildren()) do
if v.Name ~= "Submit" and not v.TextBox.Text:match("%S") then
passed = false
print(passed)
break
elseif v.Name ~= "Submit" and v.TextBox.Text:match("%S") then
passed = true
print(passed)
break
end
end
end)

works


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
28 May 2017 09:10 PM
Structure it like this instead:

if v.Name ~= "Submit" then
if v.TextBox.Text:match("%S") then
else
end
end


Report Abuse
iLordOfAviation is online. iLordOfAviation
Joined: 23 Mar 2012
Total Posts: 1325
28 May 2017 09:11 PM
but that's more lines! :(


Report Abuse
nullfeels is not online. nullfeels
Joined: 31 Mar 2017
Total Posts: 1215
28 May 2017 09:13 PM
Yeah, no reason for that your if condition if clearly understandable as is.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
28 May 2017 09:14 PM
More lines is not necessarily less efficient. The text is being unnecessarily checked twice.


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
28 May 2017 09:15 PM
The name AND ##### ## addition to that, you're calling a function twice for no reason.
Report Abuse
iLordOfAviation is online. iLordOfAviation
Joined: 23 Mar 2012
Total Posts: 1325
28 May 2017 09:16 PM
owell, all I'm worried about is it looks nicer ;)


Report Abuse
nullfeels is not online. nullfeels
Joined: 31 Mar 2017
Total Posts: 1215
28 May 2017 09:23 PM
He is right about the elseif though it's redundant. A simple else will suffice.
Report Abuse
nullfeels is not online. nullfeels
Joined: 31 Mar 2017
Total Posts: 1215
28 May 2017 09:24 PM
As far as the " v.Name ~= "Submit" " that's not true. If the first check fails the second will not even be evaluated.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
28 May 2017 09:25 PM
Did you forget how conditional statements work? My point was that the second check for the Name property was redundant, and it is.

If the first "check" fails then the second WILL be evaluated, but if the first check succeeds then the second won't be evaluated.


Report Abuse
iLordOfAviation is online. iLordOfAviation
Joined: 23 Mar 2012
Total Posts: 1325
28 May 2017 09:27 PM
not sure why everyone's arguing about this, my code works and I'm happy with it lol


Report Abuse
nullfeels is not online. nullfeels
Joined: 31 Mar 2017
Total Posts: 1215
28 May 2017 09:29 PM
No, I've certainly not forgoten... He is checking if and ... if the first check fails the second wont be evaluated because both are required to be true for the condition to be true. I think you're thinking of "or".
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
28 May 2017 09:30 PM
It was miscommunication. I thought you were referring to different conditions, for example:

if false then
print("I won't print")
elseif true then
print("I will")
-- I thought you meant this wouldn't be evaluated which mind-$%^&ed me
end


Report Abuse
nullfeels is not online. nullfeels
Joined: 31 Mar 2017
Total Posts: 1215
28 May 2017 09:32 PM
OH, no we're on the same page with that :P
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
28 May 2017 09:34 PM
So back to your original statement, `string.match` will be unnecessarily called twice in the case of `v.Name` referring to "Submit" but `v.TextBox.Text` referring to a string that has a letter. That was why I suggested a different structure.


Report Abuse
nullfeels is not online. nullfeels
Joined: 31 Mar 2017
Total Posts: 1215
28 May 2017 09:36 PM
Yes, I agreed with that part.

"He is right about the elseif though it's redundant. A simple else will suffice."
Report Abuse
nullfeels is not online. nullfeels
Joined: 31 Mar 2017
Total Posts: 1215
28 May 2017 09:45 PM
Umm well actually no... I'm not trying to argue or anything, but if you're still referring to this "if v.Name ~= "Submit" and not v.TextBox.Text:match("%S") then" then the second check will only be evaluated if the first check is true.

So not v.TextBox.Text:match("%S") is only evaluated if if v.Name ~= "Submit" is true. This is called short-circuit evaluation.
Report Abuse
nullfeels is not online. nullfeels
Joined: 31 Mar 2017
Total Posts: 1215
28 May 2017 09:46 PM
Either way glad you got it working iLordOfAviation :P
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
29 May 2017 08:35 AM
That's not what I meant at all. Read my reply again.


Report Abuse
nullfeels is not online. nullfeels
Joined: 31 Mar 2017
Total Posts: 1215
29 May 2017 08:41 AM
I don't need to read it again, I've read it a couple times... I know what you're saying.
Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
29 May 2017 08:43 AM
just stop before a flame war starts


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
29 May 2017 08:44 AM
No. We agree on the same subjects but you're misinterpreting what I'm trying to say. I was giving an example that would result in `string.match` being unnecessarily called twice, further justifying re-constructing the layout of the conditional statements.


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