Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a function that fires when two buttons are selected?

Asked by 8 years ago

I'm making a GUI that is supposed to let you "breed" two animal AI, but I don't know how to tell the script to occur only when the two boxes (already created and named) are selected and the "Breed" button is clicked. I've tried to look at some other scripts to see how this is done for selecting one button, but I can't figure it out, especially for two separate buttons. I included my script below, and I am aware that it is incomplete and messy currently. Also some of the variables I have here may not make sense yet because I need them for stuff I'm gonna add in the future. Basically to clarify my question is, how can I signify that BOTH of the buttons are selected and the "Breed" button is clicked? Thanks for any and all help guys!!!

local BUTTON = script.Parent
local TOOL = script.Parent
local NAME1 = "Bull"
local NAME2 = "Cow"
local DEEDS = game.Lighting.Animals
local DEED1 = DEEDS:findFirstChild(NAME1)
local DEED2 = DEEDS:findFirstChild(NAME2)
local AFRAME = script.Parent.Parent.Parent
local NEWBUTTON = AFRAME.newButton

--not sure if i need multiple functions, maybe one for recognizing the two buttons being selected
--and one for the "Breed" button being selected? 
function on_button1_down()

NEWBUTTON.MouseButton1Down:connect(function()
            local current = NEWBUTTON

        end)
end
---------------------------------

2 answers

Log in to vote
0
Answered by 8 years ago

If you want to have it so when both buttons are pressed it fires, it should look something like this.


created = false name = false function click () if name and created then --Action would be here end end SCRIPT.MouseButton1Down:connect(click)

So created and name would be connect to a function, Say when the players types his name and presses "Enter". You would set created or name to true. If this didn't help you I apologize as I may have thought your question meant something different.

0
so could I make the action be when the Breed Button is clicked? and are "name" and "created" the names of the two buttons in this example? Gwolflover 80 — 8y
0
No, name and created would be the variables. You would say, "If the Part you want clicked is clicked, You would set the name variable to true. So when the brick is clicked, You would set the variable to true OpticalAce 49 — 8y
Ad
Log in to vote
-1
Answered by 8 years ago

So OpticalAce would this work as a base to work off of?

local BUTTON = script.Parent
local TOOL = script.Parent
local NAME1 = "Bull"
local NAME2 = "Cow"
local DEEDS = game.Lighting.Animals
local DEED1 = DEEDS:findFirstChild(NAME1)
local DEED2 = DEEDS:findFirstChild(NAME2)
local AFRAME = script.Parent.Parent.Parent
local NEWBUTTON = AFRAME.newButton
created = false
name = false


function click ()

if name and created then
    created = true
    name = true

function onMouseButton1Down()

print("complete")
    end
end
BUTTON.MouseButton1Down:connect(click)
BUTTON.MouseButton1Down:connect(on_button1_down)

Answer this question