[SOLVED] Create/copy instance from object

R

RisingKane

Guest
Hey there everyone

I'm trying to make something, but it's getting really difficult. I'd like to share it with you.

I have one button object on screen, called 'obj_button'. I made a piece of code so I can drag and drop it anywhere I want, and it's working fine. But what I'm trying to achieve next, is to, as soon as I press the left mouse button on 'obj_button', create/copy an instance of 'obj_button'. My current code is cloning the button from the original and the cloned instances, but I'd like it to happen only from the original (first) button that was on screen.

I tried to make it like this:

Code:
//This one is inside the 'Left Pressed' mouse button event for 'obj_button'
if ((mouse_x  >= initial button x position && mouse_x  <= final button x position) && mouse_y == button y position) {
      drag = true;
      instance_copy(true);
}
else {
      instance_copy(false);
}
I have created one variable called 'drag' in the create event for the 'obj_button' and initialized it as false.
I have also set 'drag' to false in the 'Left Released' event.

Do you have an idea why it's not working?
Thanks!
 
You are probably using a with statement ? In that case you need to target the instance, not the generic object name

Is there a reason for creating another instance instead of moving obj_button ?
 
T

titusthreex

Guest
If you want to copy the original object only, you must add a variable that indicates the object is either the original or a clone.

In your create event :
this_object="original"; // you can use boolean or anything

All duplicate instances should be labeled "clone" so as not to create a duplicate. In your left mouse button:

if (this_object="original")
{
with( instance_copy(true)) {this_object="clone"}
}
Not certain if instance_copy is a good choice as it creates a duplicate at the same x,y. Might wan to use instance_create.
 
R

RisingKane

Guest
It worked guys, sorry it took so long for me to answer, but I've been really busy lately. Thanks again for all your support!
 
Top