How to Control Multiple V-Ray Lights with Spinners in MaxScript

Published on January 06, 2026 | Translated from Spanish
Screenshot of 3ds Max interface showing multiple spinners controlling parameters of different V-Ray lights, with the MaxScript editor visible.

The Dilemma of the Rebellious Spinner in MaxScript 🎚️💡

What a mess of lights and spinners you've created! It seems your controls are playing "last one in wins." Let's solve this spinner identity problem like good code detectives.

The Conceptual Problem

What's happening is:

"A handler without context is like a switch without wiring: it clicks but doesn't turn on anything useful"

Technical Solution

You need to create closures to capture the correct context. Try this approach:

for i = 1 to mat_sel.count do (
    local currentLight = mat_sel[i]  -- Capture the current light
    local spinnerName = ("spin_" + (i as string)) as name
    local lightName = (currentLight.name + ": ") as string
    
    -- Create the spinner with the current value
    samp.addControl #spinner spinnerName lightName paramStr type:#integer range:[0,100, currentLight.subdivisiones] fieldWidth:40 align:#center
    
    -- Handler with closure that captures the correct light
    on spinnerName changed val do (
        currentLight.subdivisiones = val
    )
)

Key Explanation

  1. Capture the context with a local variable in each iteration
  2. Use closures so the handler "remembers" which light to modify
  3. Avoid global references that get overwritten

If this doesn't work (sometimes MaxScript's handler system is special), another option is:

Remember: in MaxScript, as in life, context is everything. May your spinners light the right path! 💡 And if all else fails, you can always do like in the movies: "More lights!" (even if the render takes forever afterwards).