Posts: 68
Threads: 7
Joined: Dec 2004
I woukd like to ask you guys about this possible feature that I found very useful to simplify coding or values assignment into UDTs or Arrays. Would you guys agree it's useful if something like this exist in FB?
It's like fitting a 'rpg room' data into a complex UDT or arrays. For game, opengl or dx programing should be a relief if we got this feature.
[syntax="QBasic"]
Type AXIS
X AS SINGLE
Y AS SINGLE
Z AS SINGLE
End Type
Type LIGHT
Ambients AS AXIS
SunLight AS AXIS
Fog AS AXIS
End Type
'...
DIM DayLight AS LIGHT
DayLight = { 0.3, 0.3, 0.3, _
3, 3, 3, _
1.5, 1.5, 1.5 }
DIM a(7) AS BYTE
a() = { 0,1,2,3,4,5,6 }
'...
[/syntax]
Any thoughts?
= inc(¢)
Posts: 242
Threads: 29
Joined: Dec 2004
It might be a good feature. I doubt I would use it, I tend to build everything in DATA blocks:
Code: ' DayLight
DATA 0.3, 0.3, 0.3,
DATA 3, 3, 3,
DATA 1.5, 1.5, 1.5
' Byte array info
DATA 0, 1, 2, 3, 4, 5, 6
And then READ everything in a FOR..NEXT loop, it seems easier for me to keep track of the information that way.
... I've found myself hopelessly lost on occasion attempting to break-down a four level array in C and trying to keep all of the brackets straight for which level goes where...
ature has its way of warning a person away from danger: The distinct black and white coloration on a skunk, the chilling buzz of a rattlesanke, a redneck handing you his beer and saying "Watch this!"
Posts: 1,774
Threads: 62
Joined: Aug 2003
I've seen it done that way in C, but honestly, I hate it. :barf:
I'd rather store the DATA for each light/object in a seperate file read it in with a LoadLight sub... It stays more BASIC like that way to me.
Posts: 6,419
Threads: 74
Joined: Mar 2002
It's "more BASIC", but it's also a bummer. You know, you have to set the DATAs, then set a RESTORE, then perform a loop... bufff.
Way easier the C way.
Posts: 1,272
Threads: 36
Joined: Feb 2003
FreeBASIC can already do this: Code: type twoDee
x as integer
y as integer
end type
dim p as twoDee
with p
.x = 5
.y = 10
end with
Is that close enough?
Posts: 6,419
Threads: 74
Joined: Mar 2002
Nope. Imagine having to fill this:
Code: DIM alienPooEradicator(10) as twoDee
Posts: 3,522
Threads: 189
Joined: Dec 2003
Posts: 62
Threads: 0
Joined: Dec 2004
I like array literals, too.
BTW, what you've suggested is way more powerfull than what you can do in C. In C you can only initialize this way. You've suggested generally useable literals if I got you right.
Posts: 68
Threads: 7
Joined: Dec 2004
Yes, helium. it's a universal data feeder for structural variables such as udt and arrays. Logically, each array and udt built in block of memory space and arranged in it's order. Having such {..} data feeder is like copying over the variable location.
It's like having READ a() from DATA without FOR..NEXT loop but filling all the array elements according it's size. In OOP capable compiler the idea can be extended to read external data source from CSV file such as:
[syntax="QBasic"]
a().LoadFromFile ("File.csv")
' or
a().LoadFromFile ("File.dat")
' or
a().LoadFromFile ("File.txt")
[/syntax]
But in FB, a new syntax can be used for external data retrieval, such as:
[syntax="QBasic"]
a() = LoadCSV("File.txt")
' and for UDT:
DayLight = LoadCSV("File.txt")
' and reading from DATA:
DayLight = LoadCSV(1) ' 0,1,2,.. DATA lines
[/syntax]
The methods still the same like you code it in the source for the data structure. How about mixed values like number and string? Let we look at this example:
[syntax="QBasic"]
TYPE CREATURE
Name AS STRING*10
Group AS LONG
END TYPE
'...
DIM Animal(3) AS CREATURE
Animal() = { "Snake", 1, _
"Cat", 3, _
"Fish", 2 }
'...
[/syntax]
= inc(¢)
Posts: 1,439
Threads: 15
Joined: Apr 2003
Quote:Possible Additions to Later Versions:
o Variable initializers:
DIM MyVariable AS SomeType = { InitialValue, ... }
RTFM...
|