Hello! First time here on GDevelop forum!
I was wondering, is there any way to make an event that can edit an objects position, without having to write a specific event for each and every object?
I’m working on a card-game, and I’m doing the “slotting” to the hand, when you stop grabbing a card, it automatically drops on the correct slot.
The event that I was wondering about should be something like this:
-If “card” is dropped on placeholder 1 - edit “card”'s coordinates to be the placeholder’s coordinates.
but, if “card 2” is dropped on placeholder 1 - edit “card 2”'s coordinates to be the placeholder’s.
I’m going to have 104 cards, hence not wanting to do 104 events per placeholder.
I was thinking I could do 12 events (12 placeholders) and in those events make something general that recognizes which card I’m dropping, to change THAT card’s coordinates.
I’m not sure about how GDevelop would recognize which card I’m using, so it could change THAT card’s coordinates…
I hope I make sense and that someone is willing to help me!
Thanks in advance.
Your easiest solution would be to set up an object group.
Basically, you would write the event as you normally would (targetting an object), but instead of targeting a specific Card (Card 1 or Card 2), you would target “Cards” (an object group that you’ve created, which Card 1 and Card 2 are both members of).
It will only target whichever card object matches based off the conditions you’ve set up.
Wow it worked! (Maybe, haven’t done that thorough testing yet)
I thought making groups would change already existing cards also, not just the one you are “controlling” at the moment.
Is it so really, do groups only target active objects?
In other words, why doesn’t this event make other cards change also?
(Cards is the name of the group)
This simplifies the code a lot.
Conditions Filter selected objects. So your actions may not work as expected since you’re not filtering the cards group. Is placeholder_card1 in the Cards group? Or how are you selecting which Card to activate?
This is how I’ve set up the code for the cards:
The code is similar for all placeholders, except targeting the next placeholder (e.g. placeholder_card2 etc.)
This is how it looks in-game:
Only the cards are in the group cards.
All cards are draggable (meaning I select them by dragging and dropping as the code above says)
When I drop a card on a placeholder it should “snap in place”, where I dropped the card.
This method above will change other cards too.
I’d need some way to make only the dragged object “snap in place” without other cards changing.
But, I would like to do this without having 100+ events…
When one of the cards is already snapped in place, when dropping the other, both cards move to that slot.
Your current logic should work, but you should probably also add some kind of object variable to the card you’ve picked up (Something like “Selected” = 1) and make it so the behavior/etc only activates if that variable is =1. Then when you drop the card, it goes back to 0.
That should avoid any conflict.
This does not work.
Even if I’d give “selected”-variable to the card that’s active -
all cards are going to move because I change the attributes of “Cards” and not the individual card.
There should be a check or something at the action:
Change the angle of Cards where selected=1: set to 343
Is this possible?
The second part of my recommendation, “and make it so the behavior/etc only activates if that variable =1” means you need to make a condition for it.
You’d want to use the “Object variable blah of Objectname = 1” condition.
And all Cards shouldn’t get the variable because you should be setting the variable based off selecting the card itself. Normally you’d do this with “The Mouse is on Objectname” and “Point is inside object” (and use the MouseX/Y expressions for the point). That way it only picks the one card, then you set The “selected” variable of that card to 1.
If I set
The variable selected of Club_1 = 1 as a condition, then it wouldn’t be able to check other cards and I would need to make an event for all cards using that manual strategy. Then there’s no idea for generalizing when you can’t check automatically.
Or am I stupid for not understanding what you mean?
If I do that what I mentioned above, I would need to make these events for each card I have. 100+ events would need to be created then…
I’m sorry if I don’t get what you are telling me right now.
No, you would do “The Variable selected of Cards = 1” not Club_1.
Again, object filtering when setting the variable (as mentioned above, by using a combination of “mouse is over” and “point is inside” conditions) would apply it only to the selected member of the Cards group. Not all of them.
I’m so sorry, but I don’t understand what you are saying.
Is there any chance you could make what you say as an example in GDevelop or tell me directly via this image what I’d need to change for it to work?
If you cannot, I fully respect you. I have used much of your time already.
What would I need to change here?:
The cards get the variable “selected=1” when dragged, I’ve managed to do that.
But, this code changes ALL cards in the group Cards because of:
Thanks in advance.
You need a completely separate event to set the initial variable. I’d even do some “double-safety” measures.
The cusor/touch is on cards | Change the variable selected of Cards = 1
MouseX("",0);MouseY("",0) is inside cards | Change the scene variable MouseClicked = 1
Left mouse button is pressed |
The variable selected of Cards = 0 |
The scene variable MouseClicked = 0 |
Trigger once |
This ensures that only the current card is given the selected variable (via the majority of conditions), and it only happens once (via the MouseClicked variable and trigger once). The Mouse is in side cards condition is “Point inside objects” in the condition list.
Then in your other events where you’re releasing the left mouse button, you’d just add the actions of
Change the variable selected of Cards = 0
Change the scene variable MouseClicked = 0
Thanks for the code - it works perfectly, but that code still doesn’t explain how only one card could get snapped in place. The code that I have now changes all cards to the new card-slot. As far as I know, your code only handles the variable “selected”, the code I really need is the one that alters these ONLY for the SELECTED card:
How would I change this part so it only changes the selected card?
In other words: How do I change position of a card that has the variable “selected=1”?
I think we have misunderstood each other in what I want to accomplish.
Though it still could be me who don’t get this…
This problem also applies to this:
When CardX is dropped on placeholder_cardX → change THAT card’s Z-order to X.
This uses the same mechanism in “recognizing” which is the active card.
Again, object selection happens via conditions.
By having the a condition of “The Variable selected of Cards = 1”, only the card object with the Selected value of 1 should be impacted by your actions. Conditions (and actions, and events) all happen from the top down. So you want the “Variable of selected of Cards = 1” to be the top condition in your events.
I was just going to get back at you:
After thorough testing - IT WORKS NOW!
Thanks a lot for your help and patience.