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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: how do i swap the positions of 2 guis

Previous Thread :: Next Thread 
Iegoadz is not online. Iegoadz
Joined: 13 Sep 2015
Total Posts: 4189
24 Oct 2017 05:28 PM
this is my code:

card_swap1 = script.Parent.Parent.Parent.Inventory.Selected
card_swap1.BackgroundTransparency = 95
card_swap1.Swap_first:Remove()

card_swap2 = script.Parent

script.Parent.Parent.Parent.pos1.Position = card_swap1.Position
script.Parent.Parent.Parent.pos2.Position = card_swap2.Position

card_swap1.Position = UDim2.new(script.Parent.Parent.Parent.pos2.Position)
card_swap2.Position = UDim2.new(script.Parent.Parent.Parent.pos1.Position)



the textbuttons are card_swap1 and card_swap2



pos1 and pos2 are two invisible imagelabels i created to try and save the UDim2 values to

however I find that the card_swap frames both are sent to (0,0), no matter what the value

why is this happening?


Report Abuse
Iegoadz is not online. Iegoadz
Joined: 13 Sep 2015
Total Posts: 4189
24 Oct 2017 05:29 PM
'card_swap1.BackgroundTransparency = 95
card_swap1.Swap_first:Remove()'

can be ignored.


there are no errors or anything showing up, I think I am just getting something wrong.

Essentially I just want to swap the positions of 2 guis idk how


Report Abuse
Iegoadz is not online. Iegoadz
Joined: 13 Sep 2015
Total Posts: 4189
24 Oct 2017 05:42 PM
help


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Oct 2017 05:42 PM
Set them on the same line. I think it's called multiple assignment.
thing1.Position,thing2.Position = thing2.Position,thing1.Position
Report Abuse
Iegoadz is not online. Iegoadz
Joined: 13 Sep 2015
Total Posts: 4189
24 Oct 2017 05:44 PM
handy trick, it seemed to work but still returns both to (0,0)


Report Abuse
Iegoadz is not online. Iegoadz
Joined: 13 Sep 2015
Total Posts: 4189
24 Oct 2017 05:45 PM
they are being positioned in scrolling frames, I don't know if this has any relevance


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Oct 2017 05:47 PM
Positioned within scrolling frames?
Are you organizing them with a UIListLayout or UIGridLayout?
Report Abuse
Iegoadz is not online. Iegoadz
Joined: 13 Sep 2015
Total Posts: 4189
24 Oct 2017 05:49 PM
essentially I have two scrolling frames full of cards, which are big buttons in the game you click to swap over the cards that you want to move from your inventory to #### #### (so they swap frames) im not using any of the uigrid layout etc, none of that im just swapping the parents of the two 'cards' and changing the positions, so that it seems as if the cards just swapped out
Report Abuse
Iegoadz is not online. Iegoadz
Joined: 13 Sep 2015
Total Posts: 4189
24 Oct 2017 05:50 PM
im organising them just by like coding it, i coded it so that the scrolling frame changes size depending on how many cards there are


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Oct 2017 05:52 PM
Make sure you're setting the parents first, and then the old position. You will need to keep the old position on record ################# = card1.Position,card2.Position card1.Parent,card2.Parent = card2.Parent,card1.Parent card1.Position,card2.Position = #################
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Oct 2017 05:53 PM
Make sure you're setting the parents first, and then the old position. You will need to keep the old position on record

oldCardP1,oldCardP2 = card1.Position,card2.Position
card1.Parent,card2.Parent = card2.Parent,card1.Parent
card1.Position,card2.Position = oldCardP2,oldCardP1
Report Abuse
Iegoadz is not online. Iegoadz
Joined: 13 Sep 2015
Total Posts: 4189
24 Oct 2017 05:55 PM
im confused

i kinda see what youre saying though, the positions change once i change the parent


this is the script:

card_swap1 = script.Parent.Parent.Parent.Inventory.Selected
card_swap1.BackgroundTransparency = 95
card_swap1.Swap_first:Remove()

card_swap2 = script.Parent

card_swap1.Parent = script.Parent.Parent
card_swap2.Parent = script.Parent.Parent.Parent.Inventory

card_swap1.Position, card_swap2.Position = UDim2.new(card_swap2.Position), UDim2.new(card_swap1.Position)



but yeah I think the positions change to (0,0) when I change the parent

idk what your wrote


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Oct 2017 05:56 PM
Like I said, just keep a record of the positions BEFORE you change the parents
Then change the parents
Then change the positions to the old position of the opposite card
Report Abuse
Iegoadz is not online. Iegoadz
Joined: 13 Sep 2015
Total Posts: 4189
24 Oct 2017 05:58 PM
this is the script now: card_swap1 = script.Parent.Parent.Parent.Inventory.Selected card_swap1.BackgroundTransparency = 95 card_swap1.Swap_first:Remove() card_swap2 = ############# ########## ######### = card_swap1.Position, card_swap2.Position card_swap1.Parent = script.Parent.Parent card_swap2.Parent = script.Parent.Parent.Parent.Inventory card_swap1.Position, card_swap2.Position = UDim2.new(oldCardP1), UDim2.new(oldCardP2) I think I need to keep a record in an object, like the image label, I'll attempt to do that again with the new code.
Report Abuse
Iegoadz is not online. Iegoadz
Joined: 13 Sep 2015
Total Posts: 4189
24 Oct 2017 05:59 PM
Still doesn't work, even when it's held in an object:

card_swap1 = script.Parent.Parent.Parent.Inventory.Selected
card_swap1.BackgroundTransparency = 95
card_swap1.Swap_first:Remove()

card_swap2 = script.Parent


script.Parent.Parent.Parent.pos1.Position, script.Parent.Parent.Parent.pos2.Position = card_swap1.Position, card_swap2.Position

card_swap1.Parent = script.Parent.Parent
card_swap2.Parent = script.Parent.Parent.Parent.Inventory

card_swap1.Position, card_swap2.Position = UDim2.new(script.Parent.Parent.Parent.pos1.Position), UDim2.new(script.Parent.Parent.Parent.pos2.Position)


Report Abuse
Iegoadz is not online. Iegoadz
Joined: 13 Sep 2015
Total Posts: 4189
24 Oct 2017 06:01 PM
this is one of those times when programming drives me nuts, where something logical doesn't work at all, probably due to some dumb little syntax error


Report Abuse
Iegoadz is not online. Iegoadz
Joined: 13 Sep 2015
Total Posts: 4189
24 Oct 2017 06:10 PM
this is driving me crazy because it should work

why does it not work


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Oct 2017 06:10 PM
No reason to hold the values in in value objects, that can all be done through variables.

I'm also not sure what this is
UDim2.new(script.Parent.Parent.Parent.pos1.Position)

But I don't recall any UDim2Value, and if you're using anything else, I almost guarantee it's non-transmutable
Report Abuse
Iegoadz is not online. Iegoadz
Joined: 13 Sep 2015
Total Posts: 4189
24 Oct 2017 06:14 PM
UDim2Value? idk what that is

And the problem with variables as they'll change along with the positions of the cards

whereas setting it to an object it won't change, it'll be assigned once and left alone


'UDim2.new(script.Parent.Parent.Parent.pos1.Position)'


script.Parent.Parent.Parent.pos1.Position, where pos is the image label which has been assigned the position of where the 'card' was.

so I was thinking that 'UDim2.new(script.Parent.Parent.Parent.pos1.Position)' would set the position to where the position of the image label is


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Oct 2017 06:15 PM
No they won't change with the position of the cards.
Do exactly what I did up above
Report Abuse
Iegoadz is not online. Iegoadz
Joined: 13 Sep 2015
Total Posts: 4189
24 Oct 2017 06:16 PM
i did it and it didnt make a difference, it still returned to (0,0) and I have no idea why


Report Abuse
Iegoadz is not online. Iegoadz
Joined: 13 Sep 2015
Total Posts: 4189
24 Oct 2017 06:19 PM
ok i see that it doesnt change with the position, i guess i learn something new everyday

here is the code:

card_swap1 = script.Parent.Parent.Parent.Inventory.Selected
card_swap1.BackgroundTransparency = 95
card_swap1.Swap_first:Remove()

card_swap2 = script.Parent


oldp1, oldp2 = card_swap1.Position, card_swap2.Position

card_swap1.Parent = script.Parent.Parent
card_swap2.Parent = script.Parent.Parent.Parent.Inventory

card_swap1.Name = "DIS CARD"
card_swap2.Name = "DIS CARD"

print(oldp1)
print(oldp2)

card_swap1.Position, card_swap2.Position = UDim2.new(oldp1), UDim2.new(oldp2)


it still returns to (0,0)


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Oct 2017 06:20 PM
I just did, and they didn't
oldCardP1,oldCardP2 = card1.Position,card2.Position
card1.Parent,card2.Parent = card2.Parent,card1.Parent
card1.Position,card2.Position = oldCardP2,oldCardP1

Aside from that, I think your code could use a cleanup, there shouldn't be so many parent.parent.parent.parent-blah blah
You should take a downward approach, instead, and rely less on value objects and more on variables within the code itself
Report Abuse
Iegoadz is not online. Iegoadz
Joined: 13 Sep 2015
Total Posts: 4189
24 Oct 2017 06:22 PM
yea it's a bit messy, but i still don't know why it doesn't work, why should it return to (0,0)??? it makes no sense at all.


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Oct 2017 06:28 PM
You're saying
card_swap1.Position, card_swap2.Position = UDim2.new(oldp1), UDim2.new(oldp2)

It should be
card_swap1.Position, card_swap2.Position = oldp1,oldp2

It's already a UDim2 value. You're trying to put a UDim2 inside of a UDim2

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