|
| 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
|
  |
| 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
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 33868 |
|
| |
|
| |
|
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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 33868 |
|
|
| 12 Aug 2015 04:52 PM |
@bad have u tried what i said?
|
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|