Jump to content


Photo

Changing the parent to nothing?


  • Please log in to reply
19 replies to this topic

#1 Masterjohn74

Masterjohn74

    GMC Member

  • New Member
  • 358 posts

Posted 28 May 2012 - 06:53 PM

How do I change the parent so that it is no object.
I think the function is object_set_parent(Ind,obj), but i do not know how to use it. any suggestions?
  • 0

#2 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 17013 posts
  • Version:GM:Studio

Posted 28 May 2012 - 06:55 PM

If I remember rightly, you use -1 (but it may be -4!). So..

object_set_parent(Obj, -1);

Test it and see... Bare in mind that this changes the parent for ALL instances of any given object, and if there are instances already in the room when you change the parent there could be unpredictable results.
  • 0

#3 dannyjenn

dannyjenn

    GMC Member

  • GMC Member
  • 2233 posts
  • Version:Mac

Posted 28 May 2012 - 06:58 PM

If I remember rightly, you use -1 (but it may be -4!). So..

object_set_parent(Obj, -1);

Test it and see... Bare in mind that this changes the parent for ALL instances of any given object, and if there are instances already in the room when you change the parent there could be unpredictable results.

The correct value is noone (which is -4). I think that -1 is all so you don't want to be doing that (since an object can only have 1 parent then I have no idea what would happen if you did... probably either an error or it would just set it to none like you want... but still, noone is the correct built-in constant)

Edited by dannyjenn, 28 May 2012 - 06:59 PM.

  • 0

#4 Masterjohn74

Masterjohn74

    GMC Member

  • New Member
  • 358 posts

Posted 28 May 2012 - 07:03 PM


If I remember rightly, you use -1 (but it may be -4!). So..

object_set_parent(Obj, -1);

Test it and see... Bare in mind that this changes the parent for ALL instances of any given object, and if there are instances already in the room when you change the parent there could be unpredictable results.

The correct value is noone (which is -4). I think that -1 is all so you don't want to be doing that (since an object can only have 1 parent then I have no idea what would happen if you did... probably either an error or it would just set it to none like you want... but still, noone is the correct built-in constant)

Ok but what do i put for the obj?
  • 0

#5 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 17013 posts
  • Version:GM:Studio

Posted 28 May 2012 - 07:05 PM

The object that you want to remove the parent of... Posted Image

And it is -1 that you want (just tested).

Edited by Nocturne, 28 May 2012 - 07:08 PM.

  • 0

#6 Masterjohn74

Masterjohn74

    GMC Member

  • New Member
  • 358 posts

Posted 28 May 2012 - 07:10 PM

The object that you want to remove the parent of... Posted Image

i tried it and it doesn't seem to work.
Im trying to make a tractor beam that pull in something that is solid. I want to make it so that object is not solid anymore by taking off a parent (P_block). And since i want to have multiple objects like these i put this in a parent which is a parent of P_block.
  • 0

#7 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 17013 posts
  • Version:GM:Studio

Posted 28 May 2012 - 07:14 PM

You can't do it that way. The parent should not be changed of an object if there are instances of it in the room, and even if it did work, you will be removing the parent of ALL instances... The easy solution to your problem is to use a variable, or to use the solid flag itself. Foe example, you can do

solid=false;

and the INSTANCE of that object will no longer be flagged as solid.
  • 0

#8 dannyjenn

dannyjenn

    GMC Member

  • GMC Member
  • 2233 posts
  • Version:Mac

Posted 28 May 2012 - 07:15 PM

And it is -1 that you want (just tested).

Curious... did you also test -4? If -4 doesn't (also) work then I don't know what's up with that...
  • 0

#9 NukeTheCat

NukeTheCat

    GMC Member

  • GMC Member
  • 470 posts
  • Version:GM8.1

Posted 28 May 2012 - 07:15 PM

why not just use:
solid = false;
//this turns the object to a non-solid


Ninja'd by Nocturned :ninja:

Edited by Jlm07, 28 May 2012 - 07:15 PM.

  • 0

#10 Masterjohn74

Masterjohn74

    GMC Member

  • New Member
  • 358 posts

Posted 28 May 2012 - 07:16 PM

oh yeah :blink: im an idiot. forgot about that.
also a quick question how when i use mp_linear_step how can i deactivate it?
  • 0

#11 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 17013 posts
  • Version:GM:Studio

Posted 28 May 2012 - 07:19 PM

Again a variable. Have a variable that when true runs the mp_linear_step codes, and when false does nothing (or something else).

@dannyjem: I DID test -4 and guess what? It works, but it sets the parent to -1!!! I guessed this would happen simply because in GM if you set a sprite_index (for example) to -1, it means the instance has no sprite...
  • 0

#12 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 5211 posts
  • Version:GM8

Posted 28 May 2012 - 08:05 PM

I think the reason it's -1 is because people are forgetting noone, self and all aren't objects. They're designated constants with specific functions. Yes, they function as operands, but they're still not object indices and therefore setting an object index to anything negative is the same as saying no object. with(noone) isn't the same as with(object_index[-4]), it just tells GM to check the next expression and then checks if the operand after with can be used with the expression and if not it translates the operand. Or vice-versa. But still, I don't think Mark programmed it as simply as object_index[-1] or object_index[-4].
  • 0

#13 Masterjohn74

Masterjohn74

    GMC Member

  • New Member
  • 358 posts

Posted 28 May 2012 - 08:32 PM

K thank you
  • 0

#14 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 29 May 2012 - 02:33 AM

Well, a lot of guess, yet I'm surprised no one seem to have consulted the manual so far... The correct answer is right there.

object_set_parent(ind,obj) Sets the parent of the object. Use -1 to not have a parent. ...

Although testing is good, looking up the specification should come first. It is often quicker and more reliable. Some may claim that -4 (noone) also worked, but it worked by accident (depending on GM's internal implementation), not by design. It might only happen to work in some occasion and has no guarantee to work always.

Edited by torigara, 29 May 2012 - 03:40 AM.

  • 0

#15 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14446 posts
  • Version:GM:Studio

Posted 29 May 2012 - 03:11 AM

The object that you want to remove the parent of... Posted Image

And it is -1 that you want (just tested).



or noone right?
  • 0

#16 Masterjohn74

Masterjohn74

    GMC Member

  • New Member
  • 358 posts

Posted 29 May 2012 - 10:14 PM

I think the reason it's -1 is because people are forgetting noone, self and all aren't objects. They're designated constants with specific functions. Yes, they function as operands, but they're still not object indices and therefore setting an object index to anything negative is the same as saying no object. with(noone) isn't the same as with(object_index[-4]), it just tells GM to check the next expression and then checks if the operand after with can be used with the expression and if not it translates the operand. Or vice-versa. But still, I don't think Mark programmed it as simply as object_index[-1] or object_index[-4].

I put object_set_parent(noone,self)
i put self since this is a parent of another parent.
Why wont it work?
  • 0

#17 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14446 posts
  • Version:GM:Studio

Posted 29 May 2012 - 10:16 PM

I think it's
put object_set_parent(object_index,noone);

not self, and not in the order you had.

In GM6, if you had instances alive, it took like 100 steps for the change to take...

So why are you needing this?
  • 0

#18 Masterjohn74

Masterjohn74

    GMC Member

  • New Member
  • 358 posts

Posted 29 May 2012 - 10:36 PM

I think it's
put object_set_parent(object_index,noone);

not self, and not in the order you had.

In GM6, if you had instances alive, it took like 100 steps for the change to take...

So why are you needing this?

Im creating a force like spell in which it can attract an object.
The problem is that the object i am trying to move is using a parent O_block to make it so the player can walk onto it.
I want to set it since when attracted it will constantly push the player back.
  • 0

#19 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 30 May 2012 - 02:42 AM

The problem is that the object i am trying to move is using a parent O_block to make it so the player can walk onto it.
I want to set it since when attracted it will constantly push the player back.

Look back post #7, the correct way to accomplish your goal is already pointed out there. You don't have to change the parent but turn its solidity.
solid = false;
Just to repeat, your attempt of changing parent is never going to work for two reasons:
- it won't work if there already exits an instance of the object
- even if it works, it takes effect on all instances of the same object (not only existing ones but also those created later on.)
If you truly want to change it anyway, you can create another object that has no parent, then change the instance into that object with instance_change.

Edited by torigara, 30 May 2012 - 03:50 AM.

  • 0

#20 Big J

Big J

    GMC Member

  • GMC Member
  • 2825 posts
  • Version:GM8.1

Posted 30 May 2012 - 03:27 AM

It is my opinion that changing parents on-the-fly is Doing It Wrong. This defeats the entire purpose.

Edited by Big J, 30 May 2012 - 03:32 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users