Dim array manipulation?

Blitz3D Forums/Blitz3D Beginners Area/Dim array manipulation?

Drekinn(Posted 2004) [#1]
Firstly, if anyone is familiar with Macromedia Director Lingo scripting then you'll know what I'm talking about. I programmed in Lingo for many years, but now find it horribly clunky and slow. (Blitz made all my dreams come true. ;))
Though there is one element of Lingo programming that I liked and used a lot - Linear and Property Lists.
With these lists I was able to manipulate values within variable 'lists'. I could add and subtract values as I pleased and also count the number of values in the list.

Is this possible with Blitz? I know the Dim command is the closest match, but it doesn't allow me to add or subtract values without having to redim the array and lose all the existing values in the process. If someone knows of a way to achieve my 'list' approach then please let me know!

Thank you.


semar(Posted 2004) [#2]
Have a look at the Types structure.

Type t_list
field num
field name$
end Type
Global list.t_list

;create some new element
for n = 1 to 10
list.t_list = new t_list
list\num = n
list\name = "something fun_" + n
next


;now scroll the list using the dedicated for .. each loop
for list.t_list = each t_list
print list\n * " = " + list\name
next

;delete an element from the list
for list.t_list = each t_list
if list\name = "something fun_5" then
delete list
exit
endif
next

;count the element of the list
for list.t_list = each t_list
count = count + 1
next
print "the list contains " + count + " elements"

;delete all the element from the list
delete each t_list

Hope this helps,
Sergio.


Drekinn(Posted 2004) [#3]
Thanks semar. Looks like Types will prove triumphant after all. :)


Shifty Geezer(Posted 2004) [#4]
You can also dim an array of type. eg.
Type vector
  Field x#
  Field y#
  Field z#
End Type

Dim enemies.vector(100)



Drekinn(Posted 2004) [#5]
Shifty, yes, another useful combo. :) Thanks.


hed(Posted 2005) [#6]
Hey Shifty, I'm using Blitz about a year now and have'nt
found out a way to do *ecaxctly this* - thanks a ton...

It's the little things, that help most :)

Just to complete this little example, this would be the way
how to access the enemy-array then:

Type vector
Field x#
Field y#
Field z#
End Type

Dim enemies.vector(100)

; initialise array
For i=0 To 100
enemies(i) = New vector
Next

; example access
enemies(50)\x# = 99.99
Print enemies(50)\x#


Right?

Is'nt that an array of typecollections then?
Would it be good practice to use a structure like this?

greez,
hed