Hello good folk of gdevelop community. Removing an index is not working for me here. I’m trying to move an alien for one cell to another in a world that has object culling
The old entry is not getting removed.
context
alien.id is the current cell number
alien.no is its number in the list of objects in that cell
alien.pcell is the new cell number based on it’s new position
alien.type is the number used to create it - if 4 create alien.
newworld[cell][objectnumber]. is the world array that logs everything about the object
so the new entrys are being created but the old one not being removed
1 - Don’t use while
Cause its not helping you and seems you don’t even understand how to use it
2 - Look closely what my logic is
I CLEAR all child vars from Array at beginning of the scene
Just so we are sure it have none
Then i am constantly printing to text how many child vars it have
Well obviously 0
3 - Press space
And only thing you want to pay attention to is last/only sub event
Where i check if child var at index 1 of array is greater than 0
4 - How many child vars does text variable show that Array have?
You can press tilde to reset scene
5 - AS SOON as you in any way check any Array variable or try reference it you are creating it
Imagine you want to check if i have 10$ in my wallet
In most engines you cannot go like zero does not exist so for sure there is 0$
NAH its like zero does not exist so i need to create zero to check how much money he have in wallet
And since we are checking here array child at index 1 then child at index 0 is also created automatically
That is why after you hit space text shows 2
Thanks Zero - I’ve done some experiments - while my use of while was a clumsy and idiosyncratic - the problem that I’m having is removing the old index. see experiment - works writing and deleting from [0] to [1] but not the other way. I want objects to move in the world from cell to cell and delete the old index. I’ve probably misunderstood things again.
IDK was your use of WHILE was clumsy or not
But let me ask you this
What is difference between
While these conditions are true
Variable MyArray[0] is greater than 0
Repet these
Play sound CoinPickup.mp3
VS
Condition
Variable MyArray[0] is greater than 0
Action
Play sound CoinPickup.mp3
?
BTW i don’t understand what is on gif and what you are doing exactly?
The while was creating a zero index if the cell was empty…but the main problem is deleting the objects old index. It’s like the episode of Futurama where he goes back in time in order to duplicate himself. It’s array array structure and Im probably not referring to it correctly.
I did the giff to illustrate things better but it might be just confusing things
You did not answer my question from previous message
And i did not ask what is happening but what you are trying to do
I don’t get it?
ok forget the giff, its just me experimenting - what i want to do is find the lastchild at newworld[C] - set D to that number then copy a structure at newworld[A][B] to newworld [C][D] and then remove index B of newworld [A] - its the removing the index thats the problem.
this is so that i have a fluid array with objects moving from cell to cell without any object duplication when the array is read - which happens when the player moves to a new cell.
the object culling works, but i really want the world to be fluid.
Your events for going from array[0] to array[1] look the same. Are sure you sure the array isn’t being changed. Maybe, it’s the events that are displaying the values. Take a look at that function and maybe the debugger to be sure.
If you’re moving an item from one place in an array of arrays to another place then you should be able to do it with 1 event just change the value of Sort and Sort2.
Something like
if one of the following v or b is released
… If v is pressed set Sort to the source and Sort2 to the destination
… If b is pressed then set the variables to the opposite arrays.
… Add Sort to Sort2 or swap or whatever.
Hi Keith - here’s the events to print
The events going from [0] to [1] look the same as pressing v and going from [1] to [0] - its the removing index that doesn’t work. I’m prone to errors doing this sort of thing and im still open to the possibility that this is the case. To me i can’t see a reason other than that you cant remove an index of an array of arrays the way im trying to do it. I looked at the debugger at the array and it looked like what you see is what you get …but again im no expert at looking at variables in the debugger
edit in the pic the two repeats at the top are at the beginning of the scene
I’m trying to create my own version. I just noticed that I’m having the same problem. For me, I believe it’s because GD is creating an array of structures instead of an array of arrays. I can’t delete a structure using remove by number.
Check your variable. See if it’s an array of arrays or an arrays of structures.
If so, the solution is to either make sure it’s an array of arrays or keep the structure and use Remove Child instead.
Thanks for looking at this keith…im feeling rough and off to bed now …but it’s array, array structure in the test project and the game
if you can’t delete an index containing a structure then ill need to think of another way of doing things
Yours seems to be an array of arrays. Mine wasn’t.
Here’s my project. I used 3 buttons and 2 text objects. I added an ID to the text objects and put them into the group NewTexts. This way the proper text object gets picked. My test array was simply a structure using the alphabet for the name and a number for an ID.
There are probably some leftover variables.
Events
Output after clicking the 1st button. It moves a random item from column 0 to the end of column 2
Hi Keith - so did it work pressing button ‘1 to 0’ as well? I really appreciate your effort here.
I think that later i’ll try to recreate the way that you’ve done it (i’m aware that my methods are sometimes clunky) as there’s things i can learn here. What i might have to do if i can’t remove the index is limit the number of indexes per cell to 10 and clear contents rather than delete index so that when an alien moves it checks for a free slot at newworld [cell][is this slot empty 0 to 10] and if they’re all full it’s id doesn’t change. That way it’ll keep things fluid but limit the total information in the world.
My version works in both directions.








