Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Dynamic Array...A Better Way?

Author
Message
Game pro
20
Years of Service
User Offline
Joined: 21st Mar 2004
Location: Usa
Posted: 26th Sep 2008 07:01 Edited at: 26th Sep 2008 07:34
Sorry about the Rhyme :p . Anyways, I'm currently working on a map generator script for a 2d tile based map editor. However, I've run into yet another problem I can't seem to solve. Alright, so at the beginning of my code, I define this Dynamic Array:


This is defined with all my globals of course at the beginning of the source file. The array will hold data for each individual Tile on the map.

The user is suppose to choose the screen width and height X x Y and then the code divides the X and Y by 16 to get the number of tiles (variable local_TotalTiles). The code to do this happens within a Function as well, which is why I can't (I think) define a global Array thatI can access in any function.



However, if I try to create anything with say 1000+ tiles the program just completely locks up. I just think there has to be another way to accomplish what I want. Perhaps I'm not using the dynamic arrays correctly? Any ideas?

Check out my dev forums at:
http://z15.invisionfree.com/ProjectRWP
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Sep 2008 15:07
Each time you add an element to an array, it creates a new array, copies everything from the old array to it, then deletes the old array - that can be slow as you are finding out, so don't do that.

Instead of using the ADD TO QUEUE command, use either the ARRAY INSERT AT BOTTOM command (this allows you to specify the number of items to add after the array name), or use the DIM command on the array with the new size - either one would be faster than what you are doing currently.

Game pro
20
Years of Service
User Offline
Joined: 21st Mar 2004
Location: Usa
Posted: 26th Sep 2008 21:02 Edited at: 26th Sep 2008 21:05
Awesome, I used the Array Insert At Bottom and it works perfectly . Part of the problem was that I was using the wrong variable names for the tile calculation as well XD . So it was returning a value like 40384932(yeah, over-exaggerated) for the local_TotalTiles variable. Which would have taken forever to have the Add to QUEUE command go through.

Thanks again Ianm.

Check out my dev forums at:
http://z15.invisionfree.com/ProjectRWP

Login to post a reply

Server time is: 2024-11-24 19:53:35
Your offset time is: 2024-11-24 19:53:35