Tween to the last open position of a Dynamic Array?

How do I tween to the last open position of a Dynamic Array?

What is the expected result

In my card drawing game, I want to tween 1 newly drawn card to the last open position of a dynamic array or dynamic matrix.

For example, if I already have 1 card (ie. object) in hand, then this object takes up the 1,1 position, and the newly drawn card would therefore tween to next open position in the array, the 1,2 position (see array image shown below).

But now instead let’s say I already have 2 cards in hand; these 2 cards take up the 1,1 and 1,2 positions, and the newly drawn card would therefore tween to the next open 1,3 position. etc. etc. for up to 9 cards in hand, at which point the dynamic object array would be filled with 9 objects displayed on the screen in a 3,3 array/matrix.

What is the actual result

Currently I am tweening newly drawn cards to known x,y positions, but this is clunky and doesn’t account for how many cards are already in hand. I want to change this line of code to tween to a dynamic object array or dynamic matrix. See the G-Develop forum link and syntax below which mentions how to dynamically declare dynamic arrays and access their values. Please enlighten this newby and help me make sense of this syntax. If an extension doesn’t exist, someone please make it and sell it for $20 in the asset store and make $$$ and help stop my brain from melting over this.

SYNTAX FROM G-DEVELOP FORUM
You can also declare it dynamically:
Do = 1 To Variable myStruct[VariableString(counter1)][VariableString(counter2)].childVar

And dynamically access to its value with the same syntax:
Do = Variable(myStruct[VariableString(counter1)][VariableString(counter2)].childVar) To Variable myVar

LINK TO G-DEVELOP FORUM ABOUT DYNAMIC ARRAYS

I made this guide about variable dynamic access syntax like a century ago.

I think there are better functions and tutorials by now?

Anyways, I’ll take a look a your issue.

Thank you :slight_smile:

Ok.

I think the issue is related to the fact the value inside the square brackets must be always a string because it represents the name of a child variable.

So, instead of:


GlobalVariableString[Group_A[GlobalVariable(RandomValue)]]


It should be:


GlobalVariableString[Group_A[GlobalVariableString(RandomValue)]]


In order to read the value as a string.

Please try this and let me know.

Hi Endo,

I’m talking about the line of code that says:

“Tween the position of Deck Cards to x: 360, 759”

I want to instead tween to a dynamic array.

The line of syntax you are currently referring to below creates a random card.
GlobalVariableString[Group_A[GlobalVariable (RandomValue)]]
I will try adding “String” where you said to and let you know what happens.

However, my question is:

How to I tween to a dynamic array?

Thank you

I don’t understand the array approach. If you really need the array or structure approach please provide a little more retail. The linked post is old and GD has changed a lot sinc then. It’s sometimes easier to use an object instead of a variable.

To do it with placeholder objects similar to the Pairs example.

Try me: Click the deal button. click the card to delete.
https://gd.games/keith_13579/deal-cards

Project (click the green [Code] then [download zip] extract and open JSON)
https://github.com/doug13579/gdevelop-deal-cards-to-placeholders

Create a grid of placeholder objects. Add an object variable name IsEmpty with a default value of true. Either manually or with the create copies extension. You can hide the placeholder objects.
(Important: the objects need to be arranged from first placed to last placed)

The card objects have the tween behavior.

It uses a Boolean variable on the placeholder to tell if the spot is available. I randomized the tint just to break it up. It needs a scene variable named Placed to track when the card was added.

You are a gentleman and a scholar Sir Keith.

1 Like