Hello. I am trying to store the position of 100000 tiled sprites and remove the objects from the game. Then i want to load them as they become visible on screen. GDevelop does not come with an integrated 2d array object. So how would i store the locations without an array object or is there any other solution.
So, to be clear, I’m still not 100% understanding your goal based off this.
However, if you want to build an Array containing details on a large number of the same object, here’s how you can do that.
Create a basic global variable, such as “TestArray”. Leave it blank.
Create a basic global variable to count your array items, such as “TotalCount”. Leave it blank.
Then do some events like the following.
Repeat for each OBJECTNAME object Do +1 to GlobalVariable(TotalCount) Do = GlobalVariable(TotalCount) to the global variable TestArray[GlobalVariable(TotalCount)] Do = OBJECTNAME.X() to the global variable TestArray[GlobalVariable(TotalCount)].x Do = OBJECTNAME.Y() to the global variable TestArray[GlobalVariable(TotalCount)].y
This will do 3 things:
- Give you a count of all of the objects you have
- Create an array variable entry with the X/Y position of each of the objects
- Create an associated object (instance) number for each of the array variable entries.
You can then use this data and the “TotalCount” whenever you are restoring or deleting an object.
As an example, if you’re deleting an object, you’d do the above events again. This would store the most recently deleted object as the highest number in TotalCount (and all deleted objects are stored in reversed value).
This means if you’re restoring the last object, you KNOW that it’s the last number on TotalCount.
So you’d then be able to do something like
Condition: If Restore button is pressed Sub Condition: IF TestArray[GlobalVariable(TotalCount)].number = GlobalVariable(TotalCount) Event: Create Object at TestArray[GlobalVariable(TotalCount)].x and TestArray[GlobalVariable(TotalCount)].y
Note: You will need to decide what conditions you are using to add new entries or remove entries from the array. This is only an example of how to automatically populate/read from the array. Maybe do the first set of events above with “at start of scene”, then only do some variation of them when deleting/restoring an object?
What he wants to do is he saw that Terraria prevents lagging while rendering many times by putting them all in a 2d array and only accessing the keys that are in the FoV of the player and rendering them. The problem is GDevelop doesn’t work like that. Ok, he could delete instances of objects far and on each frame delete every item after saving their data depending on their positions in the array and recreating them by the data of the array, but it would cause just more lag. And I think it would be easier to learn Js and do it in Js than doing it in GDevelop.