instance_create_depth() in gamemaker 1.4

S

Scorpionlej

Guest
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?
 

BenRK

Member
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().
 
G

GmlProgrammer

Guest
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
 
S

Scorpionlej

Guest
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.
 
S

Scorpionlej

Guest
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.
 

TsukaYuriko

☄️
Forum Staff
Moderator
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.
 
S

Scorpionlej

Guest
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.
 

TsukaYuriko

☄️
Forum Staff
Moderator
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. ;)
 
S

Scorpionlej

Guest
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;
 
S

Scorpionlej

Guest
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
 

chamaeleon

Member
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
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?
 
S

Scorpionlej

Guest
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
 
Top