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