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 Discussion / Unusual features of DBC

Author
Message
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 5th Apr 2010 16:18
I've been playing about with DBC, and I've stumbled across a few things I didn't think it would allow:

1) Semi-dynamic arrays.
A function can alter the size (and perhaps also the number of dimensions) of an existing array. The array must have been dimmed at the top of the main code, otherwise DBC gives a compiler error, but this appears to work fine:



As expected, the Redim will erase any existing data. I've been using this in my DarkGUI project, without any trouble, but I wanted to ask - is this really safe and/or stable?


2) Functions can use Gosub.
The Subroutine must be located inside the function, but cannot be accessed by any other part of the program. I find it quite handy for simplifying my function code in DarkGui, but again - is it safe?



3) Arrays can hold more data than you'd think...


You can write data at each dimension of the array - Lightning Limbs used it to log the keyframe with the associated XYZ rotation/offset/scale of each limb!

"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 5th Apr 2010 17:47
Quote: "2) Functions can use Gosub."

thought that was strange from the begining.

Quote: "3) Arrays can hold more data than you'd think..."

not unusual.............

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 5th Apr 2010 22:33
Quote: "1) Semi-dynamic arrays."

Many BASIC languages have a REDIM statement that resizes an array. I could have sworn I read somewhere in the manual or on the forums that DIM acts as a REDIM statement. The only thing I would be worried about is because DBC has hidden glitches, the original memory for the first DIM may not be released properly unless an UNDIM is called. I wouldn't risk it. UNDIMming and DIMming aren't going to slow your program down enough to merrit a possible crash by just using DIM on the same array over and over without undimensioning it.

Quote: "2) Functions can use Gosub."

Functions as Complete Apps

Quote: "3) Arrays can hold more data than you'd think..."

When you write and read data only referencing the primary index slot of a multidimensional array, the implication is to use all of the first indeces in the array assoicated with the primary index.

dim array(5,5)
When you assign array(5) a value, you are actually assiging array(5,0) a value. That means:

array(5) is the same as array(5,0)



Enjoy your day.
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 6th Apr 2010 18:41
Quote: "1) Semi-dynamic arrays."

I was wondering about that - I'll have to try it out, and see if I can UnDim/Dim the Array insde the function. If not, I'll just modify my main arrays directly at the top of the code.

I must say I'm surprised that arrays made inside functions aren't truly global.

Quote: "2) Functions can use Gosub
3) Arrays can hold more data than you'd think..."

I suspected these would be known already. Dind't realise that array(5) is the same as array(5,0). You live and learn...

"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."

Login to post a reply

Server time is: 2024-03-29 11:51:26
Your offset time is: 2024-03-29 11:51:26