News:

Function Finder  Find all the functions within source code files

Main Menu

how do i access an element of a typed array

Started by BlinkOk, December 01, 2015, 05:51:17 PM

Previous topic - Next topic

BlinkOk

i assumed the following was how you could point to an element of an array. clearly i assumed wrong. i don't want to be constantly referencing the array index
how should i define/set the "entry" variable to point to an individual element of "array"?

i also tried "dim entry as my_type pointer" and it crashed



Explicit

type my_type
x, y
endtype

dim array(10) as my_type
dim entry as my_type
global i


for i=1 to 10
array(i) = new my_type
entry = array(i) // i incorrectly assumed that this would create a pointer to the array element
entry.x = i
entry.y = i
next


for i=1 to 10
print str$(i)+". "+"x="+str$(array(i).x)+", y="+str$(array(i).y)
next

sync
waitkey

BlinkOk

after scouring the documentation and examples and finding exactly zero examples i guessed the following

type my_type
x, y
endtype

dim array(10) as my_type
dim entry as my_type pointer
global i

for i=1 to 10
array(i) = new my_type
entry = array(i).my_type
entry.x = i
entry.y = i
next

for i=1 to 10
print str$(i)+". "+"x="+str$(array(i).x)+", y="+str$(array(i).y)
next

sync
waitkey


kevin

  For everything types see  Help->About->Types.


BlinkOk

i did. there is no example of pointing to an array element