Notifications
Clear all

[Closed] Accessing array elements by evaluation count

hello,
is it possible to access array elements(1,2,3…) through evaluation count ?

Eample : suppose, if we evaluate maxscript once the first element in the array should be accessible.Second time second element and so on.

2 Replies

You need a global variable to count the number of executions, that has to be initialized at the first script run:


(
	--	initialize the data array
	theArray = #("this", "is", "just", "a", "simple", "test")

	-- Create global if it doesn't exist or increment it by one if it exists	
	if (::globalCounter == undefined) then (global globalCounter = 1) else (globalCounter += 1)

	-- Function for accessing nth Array element: n
	fn nthArrayElement n = if (n <= ::globalCounter) then (theArray[n]) else (undefined)

	-- Getting the values
	for n = 1 to theArray.count do
	(
		myValue = nthArrayElement n
		format "myValue= theArray[%]= %
" n myValue
	)
)


But I’m not sure this is what you are looking for…

Thanks aaandres .
Your post was helpful.