|
| 19 Jul 2012 07:08 AM |
I'm making an inventory GUI and I want to be able to organize its contents.
So would I have to use a mouse target function? |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2012 07:11 AM |
| Most GuiObjects have a "Dragable" Boolean. |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2012 07:11 AM |
I'll probably just wiki it. I just prefer to rely on players with experience rather than instructions with no context towards what I'm trying to do.
So, anyone out there generous to spill the beans? :) |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2012 07:13 AM |
Yes I am aware, as well as I have an idea in which function to use.
However, (my apologies) the specific question I was going to ask, is if I use a mouse target function, does it recognize what I'm dragging? Is there a value of some sort? Is there a button for mouse hold, mouse release, and drag?
This is why I need advice. |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2012 07:26 AM |
Also, is there any way I can make the drag have boundaries? I know it's possible... I suppose script it with the UDim2...
I have an idea how to do this:
Value in the dragged object. True if clicked AND held Switches places with the object mouse has been left on, using this value. If left anywhere else, return position
Does this sound functional to you? |
|
|
| Report Abuse |
|
|
velibor
|
  |
| Joined: 24 Nov 2009 |
| Total Posts: 1003 |
|
|
| 19 Jul 2012 07:28 AM |
I would personally put in each Inventory item a NumberValue with his own ID.
Then when we drag we can check is the slot already taken or not.
The simple solution to do this is using the new DragStopped and DragBegin.
DragStopped returns x and y (in Pixels !) (The current location of the Mouse)
DragBegin returns a UDim2.new() this includes also the Scale.
Now you should be aware that we need to use a function that checks each backpack slot and return the name of the slot. After that we need to check is there a value inside it. If there is then we know it is already used and we abort the dragging. Else we will copy the dragged item.
NOTE : WE CAN'T USE SCALE IN THE POSITION OF A ITEM !
function CheckForItems(xpos, ypos) for _,v in pairs(Game.Players.LocalPlayer.PlayerGui.ScreenGui.Backpackslots:GetChildren()) do if v.Position = UDim2.new(0,xpos,0,ypos) then CheckForUsed(v) end end end
function CheckForUsed(Object) if Object:findFirstChild("ID") then return true else return false end end
The others part is easy so that you can do yourself ;-)
Glad to help, Velibor
|
|
|
| Report Abuse |
|
|
|
| 19 Jul 2012 07:38 AM |
I have the number value in the slot name. "Slot1" Ect. I use string.sub() to find the 'ID'.
Would you mind explaining to me these two functions?
The first one looks like it is the end of the dragging of an object? The second function looks like it is the search for an object that is already there or not.
Elaborate? :) |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2012 07:49 AM |
My bad if I'm a couple generations behind in scripting.
Not too fond of in pairs. Also, what value is the second function returning?
>return true or false? |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2012 07:51 AM |
So I'm assuming you replace the xpos and ypos with the mouse's target position? How would I convert the pixels into UDim2? This is starting to make sense, the second question is all I really need to know. |
|
|
| Report Abuse |
|
|
velibor
|
  |
| Joined: 24 Nov 2009 |
| Total Posts: 1003 |
|
|
| 19 Jul 2012 07:51 AM |
Alright let me explain and let's create on together. Step for step.
First we create a function that allows up to find the 'Slot' (Frame, ImageButton, TextButton, TextLabel or ImageLabel)
We put this in each ScreenGui ! Not inside a Frame but right inside the ScreenGui ! - ScreenGui -- Script -- Frame --- etc
function SlotFind(xpos, ypos, Object) -- This function gives us a x and a y of the Mouse and the Dragged object print(xpos, ypos) for _,v in pairs(script.Parent.Backpack:GetChildren()) do if v.Position == UDim2.new(0, xpos, 0, ypos) then -- Dragged position is equal to slot position if CheckUsed(v) == false then Object.Parent = script.Parent.Backpack -- Parents our object to the Frame Object.Position = v.Position -- Moves our object end end end end
function CheckUsed(Obj) -- Our object that we wish to test if Obj:findFirstChild("ID") then -- If we find a Value with ID then return true return true else return false -- Everthing is safe ! end end
That is our function. Also when a item is destroyed from our backpack then make sure you remove the ID Values !
|
|
|
| Report Abuse |
|
|
velibor
|
  |
| Joined: 24 Nov 2009 |
| Total Posts: 1003 |
|
|
| 19 Jul 2012 07:52 AM |
If you don't use Scale it is easy ;-)
Because then you can say script.Parent.Position = UDim2.new(0, xpos, 0, ypos)
else you need to get the scale of the position of the slot were we are dragging it to..
|
|
|
| Report Abuse |
|
|
|
| 19 Jul 2012 08:00 AM |
It is a box of boxes, basically. Would the dragged object have to be the exact position? My idea was for the dragged object, (position of the mouse in UDim2) were to be in the vicinity of another object, they would swap places. Obviously recording the dragged objects initial position.
Anything similar to what you were trying to do? This is not a backpack inventory. Each slot simply opens up a description option frame. I have a "ControlCenter" script for this whole ScreenGui. (There are more than one ScreenGui, each supplied with ControlCenters, to give you an idea of how I script GUIs)
So this script would going there. There are values in each slot that define what type of item it is, and once clicked, opening specific options and descriptions accordingly.
That was all for context.
So for this drag and drop, I think my initial idea would work? |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2012 08:14 AM |
| I'm left hopeless. I shall break my lazy self and try it on my own. |
|
|
| Report Abuse |
|
|