# Card Zone placement problem

This topic is 1551 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I started an engine from the scratch for a custom YGO game, since there are no available tutorials, and i have decided to make something from scratch, not from engines

can i have a small assistance with this? when i try to add a card in different zones, just like what i did to the first card, the problem is either the condition or jump to position fails.
here's the code:

sprite_index=spr_mini
sound_play(snd_summon)
if not  collision_point(x, y, obj_mzone1,1,1)
{
x = 339;
y = 326;
}
else if not  collision_point(x, y, obj_mzone2,1,1) and collision_point(x, y, obj_mzone1,1,1)
{
x = 416;
y = 400;
}
I use Game Maker Pro for this

##### Share on other sites

You should probably follow some tutorials, because your approach is a bit misguided.

I could tell you straight away that collision checking is just a very bad approach to this problem, and that you should be using arrays here.

Edited by boblehest

##### Share on other sites

Chadook, can you explain your algorithm a little better for us? Walk us through it with pseudocode/english.

When does this code get called?

What are the x, y variables? Is it the position of the card? The position of the mouse? Something else?

I'm guessing obj_mzone1 is the far left pink square, and obj_mzone2 is the next pink square to the right. Correct me if I'm wrong.

- Eck

##### Share on other sites

Chadook, can you explain your algorithm a little better for us? Walk us through it with pseudocode/english.

When does this code get called?

What are the x, y variables? Is it the position of the card? The position of the mouse? Something else?

I'm guessing obj_mzone1 is the far left pink square, and obj_mzone2 is the next pink square to the right. Correct me if I'm wrong.

- Eck

yes, the pink zone is Obj_mzone_1 et 2

I'm trying to get the ability of adding the cards in the other Monster/Spell Zones, just like in this preview (usually like Yu Gi Oh! Rules)
as i stated above i tried to perform this action, but i failed.

The "pressed left button" performs the code, as it is supposed to move to the next zone if there is a collision with object obj_mzone1 the card should go to the object obj_mzone2

I'm relying on collision check conditions to perform this action, however the second card either goes to the same zone as the first one or stays in the same place.
and, I tried Grids and Arrays instead, but it still gives the same results.

##### Share on other sites

Ok, that's kinda what I assumed, it just didn't make sense to me that the 2 if blocks set different y values (I assume those are x/y values for the card position), since if they're on the same row, they should have the same y value, right?

sprite_index=spr_mini
sound_play(snd_summon)
if not  collision_point(x, y, obj_mzone1,1,1)
{
x = 339;
y = 326;
}
// The last part of this is redundant, you just checked if not collision_point for mzone1 above, if that failed, then there was a collision.
// There is no need to check again                             v
else if not  collision_point(x, y, obj_mzone2,1,1) and collision_point(x, y, obj_mzone1,1,1)
{
x = 416;
y = 400; // why is this not 326 as well?
}

First, I don't know why your code fails to work the way you intended, I don't think you provided all the relevant code (I don't know Game Maker though.)

Now for some pseudo code for a better approach:

// I don't know how you organize your objects in Game Maker, so I'm kinda coding while blind here.
// Somewhere, you should have stored information about zone sizes, and on screen positions.
// You should never use your objects' on screen positions to "store" information. I hope you can see the difference here.

// Store these variables somewhere..
spell_zone_slots = 5;
spell_zone_base_x = 339;
spell_zone_spacing = 80; // Horizontal space between cards
spell_zone_base_y = 326;
spell_zone_slots_taken = 0;

// card_id would be some identification for that specific card instance.
{
if (spell_zone_slots_taken >= spell_zone_slots) {
// No more room, do whatever
return;
}
? // In case you need to check which card is in slot x, you can check spell_zone_cards[x]. I don't know if you need to or not.
spell_zone_cards[spell_zone_slots_taken] = card_id;
card_id.x = spell_zone_base_x + spell_zone_spacing * spell_zone_slots_taken;
card_id.y = spell_zone_base_y;

spell_zone_slots_taken += 1;
}

I hope you get the concept here. Store the slot state in variables so you know what slots are taken, you should not have to check for any collision for this.

Edited by boblehest

##### Share on other sites

Ok, that's kinda what I assumed, it just didn't make sense to me that the 2 if blocks set different y values (I assume those are x/y values for the card position), since if they're on the same row, they should have the same y value, right?

sprite_index=spr_mini
sound_play(snd_summon)
if not  collision_point(x, y, obj_mzone1,1,1)
{
x = 339;
y = 326;
}
// The last part of this is redundant, you just checked if not collision_point for mzone1 above, if that failed, then there was a collision.
// There is no need to check again                             v
else if not  collision_point(x, y, obj_mzone2,1,1) and collision_point(x, y, obj_mzone1,1,1)
{
x = 416;
y = 400; // why is this not 326 as well?
}

First, I don't know why your code fails to work the way you intended, I don't think you provided all the relevant code (I don't know Game Maker though.)

Now for some pseudo code for a better approach:

// I don't know how you organize your objects in Game Maker, so I'm kinda coding while blind here.
// Somewhere, you should have stored information about zone sizes, and on screen positions.
// You should never use your objects' on screen positions to "store" information. I hope you can see the difference here.

// Store these variables somewhere..
spell_zone_slots = 5;
spell_zone_base_x = 339;
spell_zone_spacing = 80; // Horizontal space between cards
spell_zone_base_y = 326;
spell_zone_slots_taken = 0;

// card_id would be some identification for that specific card instance.
{
if (spell_zone_slots_taken >= spell_zone_slots) {
// No more room, do whatever
return;
}
? // In case you need to check which card is in slot x, you can check spell_zone_cards[x]. I don't know if you need to or not.
spell_zone_cards[spell_zone_slots_taken] = card_id;
card_id.x = spell_zone_base_x + spell_zone_spacing * spell_zone_slots_taken;
card_id.y = spell_zone_base_y;

spell_zone_slots_taken += 1;
}

I hope you get the concept here. Store the slot state in variables so you know what slots are taken, you should not have to check for any collision for this.

Well, i tried to set the second zone somewhere else to test, but it failed.

as for the second code, i use cards as Objects, i could rename them into cards id.

How to apply the second code on the room? i mean it works with arrays and grids.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633680
• Total Posts
3013304
×