Notifications
Clear all

[Closed] [MaxScript] Calling 2d array

I’m trying to create an array of cameras that contains an array of details for each camera.
My script seems to work, but when I try to call the array, it just returns the last camera and it’s details, x number of times (x being the number of cameras in the array)
Obviously there’s something I’m missing but I just can’t see it.
The script is dependent on the naming convention of the cameras. The cameras in my scene are named in the following way:
‘Cam 7500 front crew seat – F0’
‘Cam 7500 front 23in seat – F3’

global arr_sceneCams = for cam in cameras where classof cam != targetobject collect cam.name
global arr_netDetails = #()
global arr_netCams = #()
global seatAngle = “unknown”
global framePerCam = 0
global seatPos = “unknown”

for c=1 to arr_sceneCams.count do
(
–string finder
local remover = arr_sceneCams[c]
local flength = 5
local ac = “Cam 7500”

framePerCam = substring remover (remover.count) 1 – last character of cam name
remover = replace remover (remover.count – (flength-1)) flength “”–subtring removes frame stuff

if (matchPattern remover pattern:“front” == true) then seatAngle = “front”
else seatAngle = “Back”

remover = replace remover (findstring remover seatAngle) seatAngle.count “”

remover = replace remover (findstring remover ac) ac.count “”

seatPos = remover

messagebox (arr_netCams[c] as string)
arr_netDetails[1] = arr_sceneCams[c]
arr_netDetails[2] = seatAngle
arr_netDetails[3] = seatPos
arr_netDetails[4] = framePerCam

arr_netCams[c] = arr_netDetails
)
messagebox (arr_netCams as string) – this gives me all the same camera will all that one camera’s details.

If someone could help me figure out what I’m doing wrong here, it would be most appreciated.

5 Replies

I don’t know if this will help you:

(

    arr_sceneCams = for cam in cameras where classof cam != targetobject collect cam.name
    
    arr_netCams = #()
    seatAngle = "unknown"
    framePerCam = 0
    seatPos = "unknown"

    for c=1 to arr_sceneCams.count do
    (
		--string finder
		remover = arr_sceneCams[c]
		flength = 5
		ac = "Cam 7500"

		framePerCam = substring remover (remover.count) 1 -- last character of cam name
		remover = replace remover (remover.count - (flength-1)) flength ""--subtring removes frame stuff

		if (matchPattern remover pattern:"*front*" == true) then seatAngle = "front"
		else seatAngle = "Back"

		remover = replace remover (findstring remover seatAngle) seatAngle.count ""

		remover = replace remover (findstring remover ac) ac.count ""

		seatPos = remover

-- 		messagebox (arr_netCams[c] as string)
-- 		arr_netDetails[1] = arr_sceneCams[c]
-- 		arr_netDetails[2] = seatAngle
-- 		arr_netDetails[3] = seatPos
-- 		arr_netDetails[4] = framePerCam

		arr_netCams[c] = #(arr_sceneCams[c],seatAngle,seatPos,framePerCam)
    )
	print arr_netCams
--     messagebox (arr_netCams as string) -- this gives me all the same camera will all that one camera’s details.
)

Thanks for the reply. Unfortunately, that didn’t quite work. Now I get nothing in the array. Although it does seem a bit cleaner than what I had originally.

This works:

global arr_sceneCams = for cam in cameras where classof cam != targetobject collect cam.name
global arr_netDetails = #()	
global arr_netCams = #()
global seatAngle = "unknown"
global framePerCam = 0
global seatPos = "unknown"

for c=1 to arr_sceneCams.count do
(
	--sting finder
	local remover = arr_sceneCams[c]
	local flength = 5
	local ac = "Cam 7500"

	framePerCam = substring remover (remover.count) 1 -- last character of cam name
	remover = replace remover (remover.count - (flength-1)) flength  ""--subtring removes frame stuff
	
	if (matchPattern remover pattern:"*front*" == true) then seatAngle = "front"
	else seatAngle = "Back"
		
	remover = replace remover (findstring remover seatAngle) seatAngle.count ""

	remover = replace remover (findstring remover ac) ac.count ""
	
	seatPos = remover
		
	arr_netDetails[1] = arr_sceneCams[c]
	arr_netDetails[2] = seatAngle
	arr_netDetails[3] = seatPos
	arr_netDetails[4] = framePerCam  --need these too as well as below
	
	arr_netCams[c] = #(arr_sceneCams[c],seatAngle,seatPos,framePerCam)  -- so just needed to add this line
)
print arr_netCams
--messagebox (arr_netCams as string)

This is what is printed in the MaxScript Listener

-- your code
#("Cam 7500 front crew seat - F0", "front", "  crew seat", "0")
#("Cam 7500 front 23in seat - F3", "front", "  23in seat", "3")
-- mine code
#("Cam 7500 front crew seat - F0", "front", "  crew seat", "0")
#("Cam 7500 front 23in seat - F3", "front", "  23in seat", "3")

In your last code you use the arr_netDetails variable, but there is no need of it. I suppose that you use it in some other part of your full code.
By the way, do not use so many GLOBAL variables with so common names.

Hm, okay, there’s something I’m missing then. I’ll have to take a look.

As for the Global variable comment, thank you, I had originally thought it was better to use global where possible. I did a quick google search to understand why . I’m new to scripting in general with no formal training. So nice bonus