cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
Developer forum

Defining an array based on an integer parameter

JGoode
Advocate

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!

ArchiCAD 23

Windows 10
1 REPLY 1

runxel
Ace

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

 

 

Mostly AC 26 on Mac | Author of SelfGDL | Developer of the GDL plugin for Sublime Text |
«Furthermore, I consider that Carth... yearly releases must be destroyed»

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!