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.

DarkBASIC Professional Discussion / multi-dimensional array with UDT

DBPro Master
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 16th Oct 2020 06:38 Edited at: 16th Oct 2020 21:51
I feel like I'm taking crazy pills here, this makes no sense.

I don't really use multidimensional arrays much but ran into some really strange behavior

this code gives the following output:

I would expect it to instead produce this output:

basically, when setting a UDT value to the 3rd dimension in an index, it applies that value to ALL of the indices within the 1st dimension,

so what am I missing here?


edit: after further testing, it happens with basic data types also on a 3 dimensional array. it all works as expected just fine on a 2 dimensional array. just wacky.


well, it looks like it is specifically an issue with jagged arrays... dim array(3,0,3) has issues, dim array(3,3,3) works as expected. whatever, the more you know!

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Kevin Picone
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 17th Oct 2020 04:06
Just tested your program logic in PB for comparison.

So you may well have uncovered some legacy behavioral issue.

You could use a 1D array and treat it as if it was 3D.

PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 17th Oct 2020 05:09
This is and isn't a bug...
Basically the issue is that the DB3 Compiler assumes when you create 1 Element Array., that it's actually a Zero Element Dynamic Array.
As such the 0 Element doesn't actually exist but instead is a Pointer to the Vector List for said Array.
If you instead create it with 2 Elements (1) or more then it instead creates a Static Array and behaves as you'd expect...

Remember that Dynamic Arrays and Pointers weren't part of the original v2.0 Compiler., they were added to the v3.0 Compiler but that was more-or-less just a Feature expanded version of v2.0
It's the same with the 64bit Support... while it has it, it's essentially hacked in to the original 32bit approach; and so you gets some "Funky" behaviour.
Once you get used to the quirks they're usually easy enough to work around, and it's still a very fast (and powerful) language in the right hands.

Would be better if it were re-written from the ground up to natively support many of the later "hacked in" additions., but finding someone willing, skilled enough or with the free time to do such is difficult.

Login to post a reply

Server time is: 2020-10-27 09:10:26
Your offset time is: 2020-10-27 09:10:26