Changing the parent to nothing?
#1
Posted 28 May 2012 - 06:53 PM
I think the function is object_set_parent(Ind,obj), but i do not know how to use it. any suggestions?
#2
Posted 28 May 2012 - 06:55 PM
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.
#3
Posted 28 May 2012 - 06:58 PM
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)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.
Edited by dannyjenn, 28 May 2012 - 06:59 PM.
#4
Posted 28 May 2012 - 07:03 PM
Ok but what do i put for the obj?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)
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.
#5
Posted 28 May 2012 - 07:05 PM
And it is -1 that you want (just tested).
Edited by Nocturne, 28 May 2012 - 07:08 PM.
#6
Posted 28 May 2012 - 07:10 PM
i tried it and it doesn't seem to work.The object that you want to remove the parent of...
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.
#7
Posted 28 May 2012 - 07:14 PM
solid=false;
and the INSTANCE of that object will no longer be flagged as solid.
#8
Posted 28 May 2012 - 07:15 PM
Curious... did you also test -4? If -4 doesn't (also) work then I don't know what's up with that...And it is -1 that you want (just tested).
#9
Posted 28 May 2012 - 07:15 PM
solid = false; //this turns the object to a non-solid
Ninja'd by Nocturned
Edited by Jlm07, 28 May 2012 - 07:15 PM.
#10
Posted 28 May 2012 - 07:16 PM
also a quick question how when i use mp_linear_step how can i deactivate it?
#11
Posted 28 May 2012 - 07:19 PM
@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...
#12
Posted 28 May 2012 - 08:05 PM
#13
Posted 28 May 2012 - 08:32 PM
#14
Posted 29 May 2012 - 02:33 AM
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.object_set_parent(ind,obj) Sets the parent of the object. Use -1 to not have a parent. ...
Edited by torigara, 29 May 2012 - 03:40 AM.
#15
Posted 29 May 2012 - 03:11 AM
The object that you want to remove the parent of...
And it is -1 that you want (just tested).
or noone right?
#16
Posted 29 May 2012 - 10:14 PM
I put object_set_parent(noone,self)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 self since this is a parent of another parent.
Why wont it work?
#17
Posted 29 May 2012 - 10:16 PM
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?
#18
Posted 29 May 2012 - 10:36 PM
Im creating a force like spell in which it can attract an object.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?
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.
#19
Posted 30 May 2012 - 02:42 AM
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.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.
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.
#20
Posted 30 May 2012 - 03:27 AM
Edited by Big J, 30 May 2012 - 03:32 AM.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











