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
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Is there anyway to determine what was clicked?

Previous Thread :: Next Thread 
badgraphix is not online. badgraphix
Joined: 26 Nov 2007
Total Posts: 22800
12 Aug 2015 04:05 PM
function SelectItem()
--what was clicked?
shop.InfoBox.ItemDesc.Text = script.Parent.Description.Value
shop.InfoBox.ItemTitle.Text = script.Parent.Name.Value
shop.InfoBox.BIG.Image = script.Parent.Image
end

shop.PurchaseDJ.MouseButton1Click:connect(SelectItem)

Basically in the SelectItem() function I wanna know how to reference the item that was clicked. Is there any built in reference like "hit" in onTouched scripts?

I'm doing this because a bunch of different objects are going to use this SelectItem function.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
12 Aug 2015 04:06 PM
shop.PurchaseDJ.MouseButton1Click:connect(function()
print(shop.PurchaseDJ.Name)
end)


"Talk is cheap. Show me the code." - Linus Torvalds
Report Abuse
Sasayaki is online. Sasayaki
Joined: 29 Jun 2007
Total Posts: 33868
12 Aug 2015 04:06 PM
Is this a gui? or a part.
Report Abuse
badgraphix is not online. badgraphix
Joined: 26 Nov 2007
Total Posts: 22800
12 Aug 2015 04:22 PM
It's a gui.
Report Abuse
Sasayaki is online. Sasayaki
Joined: 29 Jun 2007
Total Posts: 33868
12 Aug 2015 04:26 PM
put all the elements you want in this array

local allElementsThatRequireThis = {}

function SelectItem(whateverWasclicked)
print(whateverWasClicked.Name)
shop.InfoBox.ItemDesc.Text = script.Parent.Description.Value
shop.InfoBox.ItemTitle.Text = script.Parent.Name.Value
shop.InfoBox.BIG.Image = script.Parent.Image
end
for i, v in pairs(allElementsThatRequireThis) do
v.MouseButton1Click:connect(function() SelectItem(v) end)
end
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
12 Aug 2015 04:27 PM
Its the name of the object you clicked. You are calling the MouseButton1Click from the Purchase DJ so it will the the purchasedj you are clicking, nothing else.


"Talk is cheap. Show me the code." - Linus Torvalds
Report Abuse
badgraphix is not online. badgraphix
Joined: 26 Nov 2007
Total Posts: 22800
12 Aug 2015 04:51 PM
@TimeTicks

The thing is, let's say I call a different object to the function.

shop.PurchaseBoost.MouseButton1Click:connect(SelectItem)

All of these Guis have the same infastructure.
Report Abuse
Sasayaki is online. Sasayaki
Joined: 29 Jun 2007
Total Posts: 33868
12 Aug 2015 04:52 PM
@bad have u tried what i said?
Report Abuse
badgraphix is not online. badgraphix
Joined: 26 Nov 2007
Total Posts: 22800
12 Aug 2015 05:01 PM
I saw what you did but I think you misunderstand my issue.

Let me rephrase it.

I've got some code in the function here.

WHATEVERWASCLICKED is the placeholder variable for the object I'd like to change the values of.

Below, I have two lines of code. If I click on PurchaseDJ in the Gui, it will run the function. If I click on PurchaseBoost, it will also run the function. The only difference being the actual objects effected.

function SelectItem()
--what was clicked?
shop.InfoBox.ItemDesc.Text = WHATEVERWASCLICKED.Description.Value
shop.InfoBox.ItemTitle.Text = WHATEVERWASCLICKED.Name.Value
shop.InfoBox.BIG.Image = WHATEVERWASCLICKED.Image
end

shop.PurchaseDJ.MouseButton1Click:connect(SelectItem)
shop.PurchaseBoost.MouseButton1Click:connect(SelectItem)
Report Abuse
badgraphix is not online. badgraphix
Joined: 26 Nov 2007
Total Posts: 22800
12 Aug 2015 05:44 PM
Update: I got it working. I wasn't really sure what Sasayaki meant when they presented that code. It didn't seem to fix the problem but I didn't notice the "v" snugly thrown in as a parameter to the function call.


Here is my final code if anyone ends up seeing this thread, stuck:


shop = script.Parent


function SelectItem(gui)
--what was clicked?
shop.InfoBox.ItemDesc.Text = gui.Description.Value
shop.InfoBox.ItemTitle.Text = gui.Parent.Name.Value
shop.InfoBox.BIG.Image = gui.Parent.Image
end


array = {shop.PurchaseDJ, shop.PurchaseBoost}

for i, v in pairs(array) do

v.MouseButton1Click:connect(function()
SelectItem(v)
end)

end
Report Abuse
jimmysnow02 is not online. jimmysnow02
Joined: 25 Sep 2011
Total Posts: 20169
12 Aug 2015 05:52 PM
r u pged
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