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 / array's in a type

Author
Message
Benjames8
16
Years of Service
User Offline
Joined: 6th Jan 2010
Location: Your Nightmares
Posted: 20th Apr 2010 21:44 Edited at: 21st Aug 2010 00:51
I tryed to make an array in a type but it gave me "cannot declare an array within a type"

I am wondering can I still use arrays with a type, using someother method? for example xx.d(y)=something

[edit] nevermind I am just going to use like a double array. example d(x,y)=something. Although it would still be nice to know.
[edit]perhaps not
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 20th Apr 2010 21:59


Rawwrr. Sig Fail.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 20th Apr 2010 22:15
No he wants this.


If it hasn't exploded yet, I haven't touched it.
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 21st Apr 2010 00:22
Lee wrote a work around in one of the newsletters.

Rawwrr. Sig Fail.

Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 23rd Apr 2010 05:03
I have the same complaint! I discovered early on with great dissapointment that I had to re-think how I do classes (types). The only way I have found to accomplish this is to make seperate arrays that I index to my types:


Obviously, this would be simpler if you could define, within the type, a pointer that would represent another array to be diminsioned later.... I have done C++ for a few years and the defining of classes with pointers to undifined arrays is a staple.... This has got to be the single worst thing about DBP! Not to say I don't like DBP, but if the developers would change that one thing, it would catapult DBP to the front of the best languages (for DX) EVER!!!

The fastest code is the code never written.
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 23rd Apr 2010 14:58
I think the work around was something like...

instead of enemies(5).weapons(1)

just do this...

enemiesweapons(5,1)

practically the same

Rawwrr. Sig Fail.
Newcastle is awesome
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 23rd Apr 2010 15:02 Edited at: 23rd Apr 2010 15:02
Quote: "practically the same "

Not really because '.weapons(1)' cannot inherit attributes from Enemies(), which makes the weapons type much bigger than need be and entities cannot share data simply.

My signature is NOT a moderator plaything! Stop changing it!
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 23rd Apr 2010 15:11
Sorry, I don't know what attributes you mean

I find it works just as well.

Rawwrr. Sig Fail.
Newcastle is awesome
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 23rd Apr 2010 15:51
you cannot declare array within a type in DBpro. I have one advise to you is to get the unity package were you could do that in the scripting.
veltro
User Banned
Posted: 23rd Apr 2010 18:17
Quote: "
practically the same "


That's not true

With.

Type Enemy
x, y, z as single
Dim Weapons(5) as integer
EndType

E1 as Enemy

if E1.Weapons(1) = laser then bla bla bla

Realtion between Enemy and its weapons is clean and simple.

Without.

Type Enemy
x, y, z as single
EndType

E1 as Enemy

Dim E1_Weapons(5) as integer

If E1_Weapons(1) = laser then bla bla

The relation between Enemy and its weapons is at least clumsy and weak.

It works, but it is a WORKAROUND, i.e not the optimal solution
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 23rd Apr 2010 18:23
Read it again veltro.

Rawwrr. Sig Fail.
Newcastle is awesome
veltro
User Banned
Posted: 23rd Apr 2010 18:34 Edited at: 23rd Apr 2010 18:37
Then ?

Sorry I didn' understand what you mean.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 23rd Apr 2010 18:42


veltro
User Banned
Posted: 23rd Apr 2010 18:53
Again the relation between Enenmy an Weapons is weak!

Because is based on an index in an array that is not part of the Enemy type. I didn't say that it doesn't work, I only state that is a workaround.

In the same fashion you can also do

dim EnemyX(100) as float
dim EnemyY(100) as float
dim EnemyZ(100) as float

It's a good solution?
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 23rd Apr 2010 18:57
Veltro, you're really missing the point.

Rawwrr. Sig Fail.
Newcastle is awesome
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 23rd Apr 2010 19:13 Edited at: 23rd Apr 2010 19:13
Quote: "
dim EnemyX(100) as float
dim EnemyY(100) as float
dim EnemyZ(100) as float"


That would be highly inefficient.

Quote: "the relation between Enenmy an Weapons is weak!"


How so? Everything is based on an index everywhere you look. You just have to code for it. In fact, another way to do it would be to add an id member to the weapons, and set that to the Enemy id like so.



It just depends on what makes more sense to you. The first method I mentioned would be more efficient than this though.

veltro
User Banned
Posted: 23rd Apr 2010 19:20 Edited at: 23rd Apr 2010 19:21
Quote: "Veltro, you're really missing the point."


Please explain me, I really don't understand

@Kistech
If it's so good, why other main languages allow to use array in type or classes?
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 23rd Apr 2010 19:33
Quote: "If it's so good, why other main languages allow to use array in type or classes?"


There are plenty that don't. I couldn't say how far back you would have to go to find the first one to introduce arrays in types, but of all the languages I've used I can say Pascal might have been the first to have it.

I know none of the BASICs that I've used over the years ever had it until VB came along.

My job in 1993 would have been MUCH easier if COBOL had them.

veltro
User Banned
Posted: 23rd Apr 2010 19:59 Edited at: 23rd Apr 2010 20:04
Quote: "My job in 1993 would have been MUCH easier if COBOL had them."


I agree. Probably you find a WORKAROUND, as I usually do when a language is missing a feature I would like it to have.

Believe me, I'm a professional programmer and in every languge I've used, from earlier 8080 & 6500 assembler to basic family, pascal family (pascal, modula ,oberon, delphi), c family (C, C++), busness family (cobol, RPG, abap), java, C#, eiffel I was always missing some features.

I wrote my own language and compiler (yes I can) and even then I'm missing something...

So i don't blame DBPro for not having array in type (and many other things).
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 23rd Apr 2010 20:06
Yup.

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 24th Apr 2010 00:56
IanM's plugins let you work with array pointers That way you could have a pointer to an array in your UDT. You would have to make sure you freed the array when you remove the array element though

BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Apr 2010 11:25
Quote: "instead of enemies(5).weapons(1)

just do this...

enemiesweapons(5,1) "


This isn't the same. In a type, I could have strings, integers and floats. A multi-dimensional array can only have one data type. In addition, you can't resize a multi-dimensional array easily, or have different numbers of elements per primary element.

Benjames8
16
Years of Service
User Offline
Joined: 6th Jan 2010
Location: Your Nightmares
Posted: 21st Aug 2010 00:50
Im about to go to school for c++ and I was wondering if array's can be declared within types/structs whataver in someother language compiler.
Im thinking perhaps it can be used through the GDK or something.

Until I figure it out im gonna do somthing like this.


Im intrested in your compiler sir veltro
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 21st Aug 2010 01:24 Edited at: 21st Aug 2010 01:26
c++ is object oriented, so everything exists inside an object (meaning you can have arrays in an object).

So you could have a class hierarchy like this:

Now ipiddyda_foo contains an array of arrrr's, which contain two arrays. There are methods and all sorts of stuff also. Its a whole different format than procedural coding (like that DBPro is).


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
Benjames8
16
Years of Service
User Offline
Joined: 6th Jan 2010
Location: Your Nightmares
Posted: 21st Aug 2010 03:05
I will keep that in mind sir.

Login to post a reply

Server time is: 2026-07-25 17:49:33
Your offset time is: 2026-07-25 17:49:33