1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

instance_create_depth() in gamemaker 1.4

Discussion in 'Programming' started by Scorpionlej, Jan 21, 2020.

  1. Scorpionlej

    Scorpionlej Member

    Joined:
    Jan 17, 2020
    Posts:
    8
    Hello there gamemaker community
    This is my first post ever so i hope i put it in the right place.

    Some time ago i got gamemaker 1.4 in a humble bundle pack and recently i thought i would try to use it. So i look up a tutorial on how to make a card game. Now I have come to a point where the tutorial tells me to use the function instance_create_depth() and after looking it up on the web I understand that function doesn't exist in gamemaker 1.4. Is there another function in gamemaker 1.4 that does the same job or is there another work around that people know about?
     
  2. BenRK

    BenRK Member

    Joined:
    Jun 21, 2016
    Posts:
    6
    If I had to guess, they are using instance_create_depth because they don't understand the new layer system in GMS2. Game Maker Studio 1.4 does not have a layer system, so all you need to do is use the function instance_create().
     
  3. Scorpionlej

    Scorpionlej Member

    Joined:
    Jan 17, 2020
    Posts:
    8
    Well if you want to see the tutorial is here:
     
  4. GmlProgrammer

    GmlProgrammer Member

    Joined:
    Oct 12, 2016
    Posts:
    28
    You can create your own
    Code:
    ///instance_create_depth(x,y,depth,obj)
    
    var xx = argument0;
    var yy = argument1;
    var d = argument2;
    var a = instance_create(xx,yy,argument3);
    a.depth = d;
    
    return a;
    
    
    That'll do it
     
  5. Scorpionlej

    Scorpionlej Member

    Joined:
    Jan 17, 2020
    Posts:
    8
    Thank you very much. Both of you. I probaly be back later with even more question. I only taking one class about programing in C# so i probaly incounter many problems.
     
  6. Scorpionlej

    Scorpionlej Member

    Joined:
    Jan 17, 2020
    Posts:
    8
    Welp i was a bit to fast. Seems it will only show the lowest card in the deck (Club 2) if i create a scrip with the code you wrote GmlProgrammer.
     
  7. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,925
    Are you creating instances on top of each other? If so, instances with lower depth will be drawn last (in front). If you are changing the depth between creations, make sure you increment it in the correct direction, so that things that should be on top of others have a lower depth.
     
  8. Scorpionlej

    Scorpionlej Member

    Joined:
    Jan 17, 2020
    Posts:
    8
    Yes i think i am. I am a bit new to all this. Sorry
    What happen is that no matter how many cards i draw it will always show Club 2 on the pile evendo it is suppose to show the card i am about to draw.
     
  9. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,925
    So, are you changing depth in between creation of instances? If so, did you try flipping it in the other direction?

    If that doesn't resolve it, what else are you doing that might affect this? In the first place, what are you doing? Unless you tell us and show us the code involved, we won't know. ;)
     
  10. Scorpionlej

    Scorpionlej Member

    Joined:
    Jan 17, 2020
    Posts:
    8
    Well what i am trying to do is to make the card i am about to draw in the deck show on top of the deck. Then when clicked it should move over to the pile. When clicked it will show club 2 but i draw ace of spade. And i can click to draw all 52 cards and it will always show club to. My code is a big mess but i will try and post what probaly the important part:

    Scrip to draw:
    var num = argument0;
    //condition to not draw a card
    if(Deckcount - num < 0)return 0;
    if(Pilecount == MAXPILE)return 0;

    for(i = 0; i < num; i++){
    if instance_exists(Pile){
    pile[Pilecount++] = deck[--Deckcount];
    deck[Deckcount] = 0;

    handCard[Pilecount - 1] = scr_instance_create_depth(Deck_x, Deck_y, -Pilecount -2,obj_card);
    with(handCard[Pilecount -1]){
    card_drawn = true;
    pile_position = player.Pilecount -1;
    cardNum = player.pile[pile_position];
    }
    }
    }

    Scrip for scr_instance_create_depth:
    var xx = argument0;
    var yy = argument1;
    var d = argument2;
    var a = instance_create(xx,yy,argument3);
    a.depth = d;

    return a;
     
  11. Scorpionlej

    Scorpionlej Member

    Joined:
    Jan 17, 2020
    Posts:
    8
    Probaly also have to post the drawing event from the card:

    draw_self();
    if(cardNum < 0){sprite_index = sprite_array[cardNum]}

    Where the sprite_array is an array of all the cards i have added to the game
     
  12. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    1,097
    You're only trying to access the sprite array when you have a negative index? One, that would be wrong, and two, is cardNum ever less than 0?
     
    TheouAegis likes this.
  13. Scorpionlej

    Scorpionlej Member

    Joined:
    Jan 17, 2020
    Posts:
    8
    Omg. Yep. I just look back in the tutorial. It should be :

    if(cardNum > 0){sprite_index = sprite_array[cardNum]}

    Not:
    if(cardNum < 0){sprite_index = sprite_array[cardNum]}
    I just tried it an it works now.
    Thank you so much both of you
     

Share This Page