2022-09-08 03:30 PM - last edited on 2022-09-26 10:41 PM by Daniel Kassai
Hello,
I'm trying to define an array by an integer. I want my array to have an equal amount of fields as an integer. I want to be able to use the array fields to define positions of elements so they need to hold the values while more are added or removed based on the integer.
This is what I have currently, however it locks the value to 0 as I would expect. I'm just not sure how to achieve what I'm after.
DIM num_position_x2[]
DIM num_position_y2[]
if (glob_modpar_name = "num_steps") or (glob_modpar_name = "total_distance") then
for i=1 to num_steps2
num_position_x2[i] = 0
num_position_y2[i] = 0
next i
parameters num_position_x2=num_position_x2
parameters num_position_y2=num_position_y2
endif
Thanks!
2022-09-08 04:42 PM - edited 2022-09-08 04:43 PM
You're on the right track!
You will need to shadow the parameters. I have prepared a small but working example, which can be easily extended to suit all your needs.
dim EMPTYARRAY[]
if GLOB_MODPAR_NAME = "n_steps" then
if n_steps_shadow < n_steps then
! We have more steps than before
for i=(n_steps_shadow+1) to n_steps
! init those values
x_pos[i] = 0.0
next i
else
! Less steps then before
dim _newx[]
for i=1 to n_steps
_newx[i] = x_pos[i]
next i
x_pos = EMPTYARRAY
x_pos = _newx
endif
n_steps_shadow = n_steps
endif
parameters \
x_pos = x_pos,
n_steps_shadow = n_steps_shadow