【问题标题】:Maxscript function forward declarationMaxscript函数前向声明
【发布时间】:2013-04-02 08:56:08
【问题描述】:

我遇到了 Maxscripts 第一次运行(从冷启动)时无法工作的老问题,因为需要在使用函数之前声明它们。

以下脚本在第一次运行时会失败:

fOne()
function fOne = 
(
    fTwo()
)

function fTwo = 
(
    messageBox ("Hello world!")
)

我们得到错误:“类型错误:调用需要函数或类,得到:未定义”。第二次,脚本将运行良好。

但是,向脚本添加前向声明后,我们不再收到错误消息。霍拉!但是不再调用该函数。嘘!

-- declare function names before calling them!
function fOne = ()
function fTwo = ()

fOne()
function fOne = 
(
    fTwo()
)

function fTwo = 
(
    messageBox ("Hello world!")
)

那么,前向声明在 Maxscript 中是如何工作的呢?

【问题讨论】:

    标签: function forward-declaration maxscript


    【解决方案1】:

    您不能在声明之前调用某些东西...它不是动作脚本...它在您第二次运行代码时起作用,因为它可以找到函数...

    struct myFunc (
        function fOne =  (
            fTwo()
        ),
        function fTwo =  (
            messageBox ("Hello world!")
        )
    )
    myFunc.fOne()
    

    【讨论】:

    • 啊,你找到了我所做的example。除了在更多的括号和逗号中封装函数之外,还有其他方法。
    【解决方案2】:

    致我未来的自己:保持一切本地化。将截面函数声明为(局部)变量。注意定义函数的代码中的下落

    ( -- put everything in brackets
    
        (
        -- declare the second function first!
        local funcTwo
    
        -- declare function names before calling them!
        function funcOne = ()
        function funcTwo = ()
    
        funcOne()
    
        function funcOne = 
        (
        funcTwo()
        )
    
        function funcTwo = 
        (
        messageBox ("Hello world")
        )
    )
    

    【讨论】:

      【解决方案3】:

      “::”是关键。遗憾的是,这不是一个众所周知或记录在案的功能。 http://lotsofparticles.blogspot.ie/2009/09/lost-gems-in-maxscript-forcing-global.html

      ::fOne() -- this will error if forward declaration is not working.
      
      function fOne = 
      (
          ::fTwo()
      )
      
      function fTwo = 
      (
          messageBox ("Hello world!")
      )
      

      【讨论】:

      • 我不知道为什么这被否决了。这是实际的,正确的答案。唯一的事情 - 我不知道为什么作者包含初始 ::fOne 语句。没有它对我来说工作正常(Max 2018)。这该死的有用 - 请对此答案进行投票以使其成为最佳答案
      • 只是为了表明一切正常。现在的我会更简洁:)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-08
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多