Announcement

Collapse
No announcement yet.

MAXScript - Declare variable only once - not working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MAXScript - Declare variable only once - not working

    Hi all

    I have a script with a couple of functions and a UI

    For some reason, I have to declare or assign my variable a value in every function. Not sure why it's not working if I only do it once in the beginning?
    Kind Regards,
    Morne

  • #2
    Hi Morné, if you declare a variable inside of the first function it will be local inside of the first function only. Simply put, anything declared inside of parentheses will be visible only within those parentheses.

    You can also explicitly declare the variable as available from everywhere placing 'global' in front of it, for example: global aTemp = #(1,2,3)

    In your script you can declare the variable outside of and before the rollout and the functions. It should be available for your functions and UI then.

    Also see 'scope of variables' in the maxscript help.
    Rens Heeren
    Generalist
    WEBSITE - IMDB - LINKEDIN - OSL SHADERS

    Comment


    • #3
      Originally posted by Rens View Post
      Hi Morné, if you declare a variable inside of the first function it will be local inside of the first function only. Simply put, anything declared inside of parentheses will be visible only within those parentheses.

      You can also explicitly declare the variable as available from everywhere placing 'global' in front of it, for example: global aTemp = #(1,2,3)

      In your script you can declare the variable outside of and before the rollout and the functions. It should be available for your functions and UI then.

      Also see 'scope of variables' in the maxscript help.
      Ah ok, I also tried "local" and that didn't work. I thought "global" meant that other scripts can also access it.
      Kind Regards,
      Morne

      Comment


      • #4
        Yeah, you can just declare it at the start of you script, that way it will be available to your rollout and functions only.

        Code:
        aTemp = #(1,2,3)
        function fnTemp x = aTemp[1] + x
        rollout rltTemp "bla"
        etc
        Rens Heeren
        Generalist
        WEBSITE - IMDB - LINKEDIN - OSL SHADERS

        Comment


        • #5
          I tried it like that at the beginning (without global), but it didn't work

          First thing in my script is:
          Code:
          try(destroydialog VizStill)catch()
          I think I declared my variable after this. I'll try a bit later today to put it before the above code
          Kind Regards,
          Morne

          Comment


          • #6
            OK I tries and its not working

            Basically I'm setting
            Code:
             myvariable = renderers.current
            It works fine if I do it in every function, but if I do it 1st thing in my script, then the script doesnt work
            Kind Regards,
            Morne

            Comment


            • #7
              Nevermind
              1st had to set vray to default, then its fine
              Kind Regards,
              Morne

              Comment

              Working...
              X