MAXScript Tools and Interaction with 3ds Max > Creating MAXScript Tools > Scripted Utilities and Rollouts >

# Non-Local Variables As Captions Of Rollouts and UI Controls

| Creating User Interfaces - Quick Navigation

In versions prior to 3ds Max 2012, the caption parameter of a rollout or UI control had to be provided as a string literal and could not be specified via a variable name. This made it difficult to use computed names as it required the setting of the rollout's or control's caption property after its construction, or the creation of the whole rollout using string building and evaluation or the Rollout Creator functions.

3ds Max 2012 added the ability to specify captions of rollouts and UI controls via non-local variable name. This means that the variable cannot be a local variable or a variable name passed through as a function parameter. The variable must be either in the global scope or in the top-level scope such as a structure definition, MacroScript definition or scripted plugin definition.

This restriction stems from the fact that a rollout definition is a compile-time construct, and the local variables would be defined using the context when the rollout is compiled. However, an evaluation of the variables will be attempted when the rollout is created, by which time it would no longer be in the compile context. So if a local variable was used as the caption, a compile time error will be thrown:

EXAMPLE
    fn test cap1 =
    (
      cap2 = "cap2"
      Rollout test cap1
      (
        Spinner s1 cap2
      )
      createdialog test
    )
    -- Compile error: No outer or current scope local variable references permitted here: cap1
    -- In line: Rollout test cap1

If you change the above usage of cap1 to a string literal, you will get another error on the usage of cap2.

The following shows various usages that compile successfully:

EXAMPLE
    cap1 = "cap1"
    cap2 = "cap2"
    fn test =
    (
      Rollout test cap1
      (
        Spinner s1 cap2
      )
      createdialog test
    )
    test()

EXAMPLE
    struct xxx
    (
      cap1b = "cap1",
      cap2b = "cap2",
      fn createRollout =
      (
        rollout test cap1b
        (
          spinner s00
          spinner s01 "A"
          spinner s1 cap2b
        )
        createDialog test
      )
    )
    x = xxx()
    r=x.createRollout()

EXAMPLE
    plugin material MyMaterial
    name:"MyMaterial"
    classID:#(0x69fedc0d, 0x7c79a4d2)
    extends:Standard replaceUI:true
    (
      local rollout_title = "Hardware Shaders"
      local spinner_title = "AA"
      parameters hardwareShaders rollout:shaderRoll
      (
      )
      rollout shaderRoll rollout_title width:328 height:189
      (
        spinner s1 spinner_title
      )
    )
    a=mymaterial()
    meditmaterials[1] = a