TinpotOps
|
  |
| Joined: 22 Jul 2012 |
| Total Posts: 813 |
|
|
| 22 Oct 2012 12:47 PM |
There's a few games that I've been to that have GUIs to where you click them once with the left mouse button (MouseButton1), and they'll do some type of operation, and then you're able to click them again with the same button (MouseButton1), and it'll go back to how it was origianlly before.
how to get this?
|
|
|
| Report Abuse |
|
|
|
| 22 Oct 2012 12:54 PM |
Like a show/hide toggle?
script.Parent.MouseButton1Down:connect(function() if gui.Visible then --blah else --blah end end) |
|
|
| Report Abuse |
|
|
1Topcop
|
  |
| Joined: 09 Jun 2009 |
| Total Posts: 6635 |
|
|
| 22 Oct 2012 12:55 PM |
Haven't tested this, just typed it now, but it should work.
Dub = 0 Button = script.Parent
function DoubleClicked() print(Button,"double clicked") end
Button.MouseButton1Click:connect(function() Dub = Dub+1 if(Dub==2)then DoubleClicked() end end)
while(wait(.1))do Dub = 0 end
|
|
|
| Report Abuse |
|
|
|
| 22 Oct 2012 12:56 PM |
some example code..
local lastClick = 0
function button1clicked() if lastClick - workspace.DistributedGameTime <= 0.7 then -- double click end lastClick = workspace.DistributedGameTime end
The concept here is to record the time of the last click, and find the time elapsed since then on the next click. If the difference is small enough, that means they clicked in rapid succession. |
|
|
| Report Abuse |
|
|
|
| 22 Oct 2012 12:57 PM |
@1topcop
Your code works, however the user could click once, wait 5 minutes, and click again and have it counted as a double click. |
|
|
| Report Abuse |
|
|
|
| 22 Oct 2012 12:58 PM |
| I think the title was misleading; not sure if he's after double-clicks or toggles. |
|
|
| Report Abuse |
|
|
1Topcop
|
  |
| Joined: 09 Jun 2009 |
| Total Posts: 6635 |
|
|
| 22 Oct 2012 12:59 PM |
No it wouldn't, I'm looping it to 0 every .1 seconds, figuring double click will take less then .1 seconds. Though, I like your code better, hadn't thought of doing that. |
|
|
| Report Abuse |
|
|
|
| 22 Oct 2012 01:00 PM |
Just re-read, and you're right. Sorry.
In that case, just have a variable store a bool-value to check if the first operation was completed or not, kinda like SourceLeak's example. |
|
|
| Report Abuse |
|
|
|
| 22 Oct 2012 01:04 PM |
And @1topcop
Apparently I'm blind on this thread, xD I seem to have skipped over your last few lines. But even still, I like to avoid using while loops wherever I can to reduce lag in the game. :) |
|
|
| Report Abuse |
|
|
| |
|
|
| 22 Oct 2012 01:05 PM |
@big
That barely begins to answer the question. |
|
|
| Report Abuse |
|
|
|
| 22 Oct 2012 01:07 PM |
| OP got either modbotted or floodchecked. |
|
|
| Report Abuse |
|
|
TinpotOps
|
  |
| Joined: 22 Jul 2012 |
| Total Posts: 813 |
|
|
| 22 Oct 2012 01:10 PM |
| Modbotted, won't even let me post a simple script. |
|
|
| Report Abuse |
|
|
|
| 22 Oct 2012 01:11 PM |
| Put it on pastebin and give us the id |
|
|
| Report Abuse |
|
|
| |
|
TinpotOps
|
  |
| Joined: 22 Jul 2012 |
| Total Posts: 813 |
|
| |
|
| |
|
TinpotOps
|
  |
| Joined: 22 Jul 2012 |
| Total Posts: 813 |
|
|
| 22 Oct 2012 01:22 PM |
| Alrighty, thanks man! +1 to you. |
|
|
| Report Abuse |
|
|
|
| 22 Oct 2012 02:22 PM |
local time=0 script.Parent.MouseButton1Down:connect(function() if time-tick()<1 then --code else time=tick() end end)
efficiency counts <: |
|
|
| Report Abuse |
|
|