|
| 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
|
  |
| 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
|
  |
| Joined: 31 Mar 2017 |
| Total Posts: 1215 |
|
|
| 28 May 2017 09:07 PM |
| Or am I just not understanding the problem? |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
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 |
|
|
|
| 28 May 2017 09:14 PM |
More lines is not necessarily less efficient. The text is being unnecessarily checked twice.
|
|
|
| Report Abuse |
|
|
|
| 28 May 2017 09:15 PM |
| The name AND ##### ## addition to that, you're calling a function twice for no reason. |
|
|
| Report Abuse |
|
|
|
| 28 May 2017 09:16 PM |
owell, all I'm worried about is it looks nicer ;)
|
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 31 Mar 2017 |
| Total Posts: 1215 |
|
|
| 28 May 2017 09:46 PM |
| Either way glad you got it working iLordOfAviation :P |
|
|
| Report Abuse |
|
|
|
| 29 May 2017 08:35 AM |
That's not what I meant at all. Read my reply again.
|
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 29 May 2017 08:43 AM |
just stop before a flame war starts
|
|
|
| Report Abuse |
|
|
|
| 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 |
|
|