ID:157119
 
Is there a way to do this? I'm trying to find out a good way to drag something around. It's really easy to do with a single tile object, but with a multitile object it gets a bit more difficult.

obj
TestScreen
icon='icon3.dmi'
MouseDrag(over_object,src_location,over_location,src_control,over_control,params)
world<<"MouseDrag is in effect; the mouse is over [over_object]"
if(!over_object:x||!over_object:y)
return
var/a=((over_object:x)-(usr.x)+6)
var/b=((over_object:y)-(usr.y)+6)
src.screen_loc="[a],[b]"


That's what I did to move a single object. The problem is that if I have a multitile object on the screen and I want to move the rest of the parts of it, I can't think of a good way without comparing the screen_locs. If you can think of a better option than comparing screen_locs, I would appreciate that too.


Edit: I think I'm just going to try to use images instead of worrying about screen_loc.

Edit2: It doesn't look like BYOND is able to handle that, unfortunately.
I'm not exactly sure what you're having trouble with. The one suggestion I have is that, instead of trying to derive where it should be based on the player's x,y coordinates and the over_object's x,y coordinates, you should instead be looking at the screen_loc parameter of params. See: http://www.byond.com/ members/?command=reference&path=DM%2Fmouse
In response to Garthor (#1)
The thing I'm having problems with is comparing screen_locs. Is this possible?

What I mean is, can I compare the screen_loc x value of one instance on the client's screen to the screen_loc x value of another instance on the screen? If so, how would I go about this?

If you're wondering why I want to do this, I'm trying to make large windowish things I can move around at my own discretion on the screen. I tried doing the same thing with images but they would end up moving incorrectly in any large/quick movement.
In response to 167981728 (#2)
Yes, you can compare the screen_loc of two objects. You will need to parse the string to get numbers out of it, however:

var/x
var/px
var/y
var/py

var/pos1 = findtext(screen_loc, ":")
var/pos2 = findtext(screen_loc, ",")
var/pos3 = findtext(screen_loc, ":", pos2)

if(!pos1) pos1 = pos2

x = copytext(screen_loc, 1, pos1)
if(pos1 != pos2)
px = copytext(screen_loc, pos1+1, pos2)
y = copytext(screen_loc, pos2+1, pos3)
if(pos3 != 0)
py = copytext(screen_loc, pos3+1)

x = text2num(x)
px = text2num(px)
y = text2num(y)
py = text2num(py)
In response to Garthor (#3)
Thank you! This is awesome. I'm gonna test this out right now.

Hell yeah! It works. This is really going to help out now that I can move large stuff across the screen. I appreciate the help.