User:Outofspace/ON-OFF Button: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Outofspace
No edit summary
 
>Outofspace
No edit summary
Line 1: Line 1:
Coming Soon!
==Simple Toggle Utility==
Insert a Brick in the Workspace.  Insert a BoolValue into that Brick.  Name that BoolValue "OnOff".
Just as before, you have a Hopperbin object in the StarterPack, and a script in the HopperBin.  Insert the following into that script:
 
<pre>
brickName = "Toggle"
valueName = "On/Off"
 
function onButton1Down(mouse)
local targ = mouse.Target
if targ~=nil then
if targ.Name == brickName then
if targ:findFirstChild(valueName)~=nil then
if targ[valueName].Value == true then
targ[valueName].Value = false
print("one")
else
targ[valueName].Value = true
print("two")
end
end
end
end
end
 
function onSelected(mouse)
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end
 
script.Parent.Selected:connect(onSelected)
</pre>
 
Upon clicking the mouse on the brick in Solo Mode, you can see the Output toggle between "one" and "two".
You can easily manipulate this script to work for anything.  {{User:Mindraker/sig}} 05:28, 27 August 2008 (CDT)

Revision as of 01:20, 28 August 2008

Simple Toggle Utility

Insert a Brick in the Workspace. Insert a BoolValue into that Brick. Name that BoolValue "OnOff". Just as before, you have a Hopperbin object in the StarterPack, and a script in the HopperBin. Insert the following into that script:

brickName = "Toggle"
valueName = "On/Off"

function onButton1Down(mouse)
	local targ = mouse.Target
	if targ~=nil then
		if targ.Name == brickName then
			if targ:findFirstChild(valueName)~=nil then
				if targ[valueName].Value == true then
					targ[valueName].Value = false
print("one")
				else
					targ[valueName].Value = true
print("two")
				end
			end
		end
	end
end

function onSelected(mouse)
	mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end

script.Parent.Selected:connect(onSelected)

Upon clicking the mouse on the brick in Solo Mode, you can see the Output toggle between "one" and "two". You can easily manipulate this script to work for anything. MINDRAKER 05:28, 27 August 2008 (CDT)