After a spate of problems running DBC and the notorious 'flashing screen' problem I was beginning to suspect that my machine was simply too fast for DBC.
Tonight, while working on my 2D Scroller Editor I had a problem when my program created an array of all the uniquely used tiles in a level.
My routine simply scanned the tile image numbers used in a level and added them to the array - only if that number was not already there.
But it just didn't work. As a test, I used the following code in the section which placed the image numbers in the array:
CLS
Inc TilesUsed
Print TilesUsed
Print CurrentTile
NumUsedTiles(TilesUsed) = CurrentTile
Print NumUsedTiles(TilesUsed)
End
The strange thing is that the correct values were printed out for TilesUsed and CurrentTile but it always printed 0 (zero) as the contents of NumUsedTiles(TilesUsed) - not the same as CurrentTile as it should have done.
I knew the code was correct, but after a considerable amount of hair pulling, I tracked down the problem...
When a level is loaded, I need to clear out the old contents of the array so I use:
Undim NumUsedTiles()
Dim NumUsedTiles(512)
And therein lies the problem. It seems that my machine runs so fast, DBC hasn't finished doing the Undim before the Dim line is reached and it was getting skipped. My array was being deleted but not created again!
So, to confirm this, I used:
Undim NumUsedTiles()
Wait 100
Dim NumUsedTiles(512)
...and the program started working perfectly. It seems that the faster your machine runs, the bigger the Wait you have to insert.
Having thought I'd stumbled across the possible reason for all my flashing screen problems, I went back and added a Wait 100 to the end of the Sync lines and hey presto - no more flashing screens since.
Now, the question is how many other commands are there in DBC that we don't know about take so long that they too need a Wait placing after them?
TDK_Man