Crafting

TyGamess

Member
If it seems like I post here a lot it’s because I can’t find the answer in the rest of the feed. I looked up “Crafting” before but they all had Questions on how to improve already Existing code.
Basicly saying is I need help and I didn’t find the answer. So I have a parent Object for a set of objects that are called item. I only have 2 at the moment: obj_itemA and obj_itemB, the parent being obj_itemParent. I would like to know how I would make a step check for when these two (item a and b) are colliding with each other but rather then adding 2 long strings of collision checks in both items (and all the others to come) just putting the code in the parent
Simply put after they are colliding if the play it’s the C button they both are distorted and a new object is created, that part I know how to do.
When I use the code:
GML:
if obj_itemA place_meeting(x,y,obj_itemB) {
keyboard_check_pressed(ord("C")) {
instance_destroy(near_itemA)
instance_destroy(near_itemB)
instance_create(x,y,"Items",obj_itemC)
}
}
this works, sorta. You see when I hit C, they automatically delete and create without them being collided with each other, on top of that if I hit C again, it crafts itemC without needing itemA or itemB, I’m starting to get a little Frustrated so I need some help.
 

TailBit

Member
Your code is read a bit wrong here
GML:
// this first part is living its own life and is not connected to the rest
// because it treat obj_itemA as the argument, and it is not connected to place meeting in any way
// obj_itemA will not compare it with the object_index of this instance, it only return the index of that object which will most likely be treated as true
if(obj_itemA) place_meeting(x,y,obj_itemB);

// so the rest happens without any collision check
{
    keyboard_check_pressed(ord("C")) // no if or just typo

    {
        instance_destroy(near_itemA)
        instance_destroy(near_itemB)
        instance_create(x,y,"Items",obj_itemC)
    }
}
it is better to do the keyboard check first, at it is less demanding then a collision check
GML:
if( keyboard_check_pressed(ord("C")) ){
    if( object_index == obj_itemA && place_meeting(x,y,obj_itemB) ){
        instance_destroy() // it is itemA .. no argument needed to delete self
        instance_destroy( instance_nearest(x,y,obj_itemB) )
        instance_create(x,y,"Items",obj_itemC)
    }
}
 

TyGamess

Member
So would that mean that I need to get rid of the parent object? Seeing that “Object_Index” is being used here?
 

TailBit

Member
No, it will work fine, the object_index will return obj_itemB or obj_itemA for the specific children object it is in ..

So that code bit will only be true if it is checked from obj_itemA

To get the parent object you would have to do: object_get_parent(object_index)
 
Top