我如何从阵列中产生旋转器?

发布于 2025-01-22 05:53:04 字数 835 浏览 4 评论 0原文

我正在尝试创建旋转器来设定“变形者”目标的价值,但是,NUM返回不确定的

``

mf_mod = $.Morpher -- get selected model
    channels = #{} -- empty bitArray
    for i=1 to 100 do channels[i] = WM3_MC_HasData mf_mod i 
    channels = channels as array
    listNames = for num in channels collect WM3_MC_GetName mf_mod num--get target names
        
    fn create_spinners = (
        
        rci = rolloutCreator "myRollout" "My Rollout"
        rci.begin()
        
        for num in channels do (
            
            rci.addControl #spinner listNames[num] listNames[num]
            
            rci.addHandler rci_name #changed paramStr:"val" codeStr:("WM3_MC_SetValue mf_mod num val") 
            
            )
    
            
        createDialog(rci.end())
        
        )
    
    create_spinners()

```` '''

I am trying to create spinners to set the value of Morpher targets, however, num is returning as undefined

`

mf_mod = $.Morpher -- get selected model
    channels = #{} -- empty bitArray
    for i=1 to 100 do channels[i] = WM3_MC_HasData mf_mod i 
    channels = channels as array
    listNames = for num in channels collect WM3_MC_GetName mf_mod num--get target names
        
    fn create_spinners = (
        
        rci = rolloutCreator "myRollout" "My Rollout"
        rci.begin()
        
        for num in channels do (
            
            rci.addControl #spinner listNames[num] listNames[num]
            
            rci.addHandler rci_name #changed paramStr:"val" codeStr:("WM3_MC_SetValue mf_mod num val") 
            
            )
    
            
        createDialog(rci.end())
        
        )
    
    create_spinners()

`

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屌丝范 2025-01-29 05:53:04

我可以看到此代码的多个问题:

  • 有一系列的频道编号不必是连续的(1,2,20)和一系列名称(name1,name2,name20),您可以通过数字 -在这种情况下,只有三个名称,您将尝试获取名称[20]
  • 您不是在您创建的控件中添加处理程序,而是将处理程序添加到相同的rci_name(无论如何在此范围中不确定)
  • 对象名称用作对象名称推出控制标识符将与许多对象名称中断,最好构造自己的
  • 代码字符串中使用“ num”作为字符串的一部分 - 因此,它将始终不确定,
  • 它依赖于MF_MOD是全局变量,并且有没有错误检查
  • 旋转器的初始化零,无论是什么因权重,如果用户在UI等元中更改了权重,而UI等级则不会更新,则推出不会更新 - 更好地使用Morpher
  • Controller一个nitpick,但如果您想要的只是迭代它,则不必将bitarray转换为数组
(
    fn create_spinners channelData =
    (
        local rci = rolloutCreator "myRollout" "My Rollout"
        rci.begin()
        rci.str += "\tlocal mf_mod = modPanel.getCurrentObject()\n\n"

        for item in channelData do
            rci.addControl #spinner ("spn" + item.channel) item.name paramStr:("controller:mf_mod[" + item.channel + "]")

        createDialog (rci.end())
    )

    local mf_mod = modPanel.getCurrentObject()

    if not isKindOf mf_mod Morpher then messageBox "Select morpher modifier" else
    (
        local channelData = for channel = 1 to 100 where WM3_MC_HasData mf_mod channel collect
            dataPair channel:(channel as string) name:(WM3_MC_GetName mf_mod channel)
        create_spinners channelData
    )
)

I can see multiple problems with this piece of code:

  • There's an array of channel numbers that don't have to be successive (1,2,20) and array of names (name1, name2, name20) which you address by the numbers - there's only three names in this case yet you'd be trying to get name[20]
  • You are not adding the handler to the control you just created but to the same rci_name (that is undefined in this scope anyway)
  • Object names are used as rollout control identifiers which would break with many object names, better to construct your own
  • You are using 'num' in the code string as a part of the string - as such, it will always be undefined
  • It relies on mf_mod being global variable and there's no error checking
  • Spinners are initialized zeroed out, no matter what the acutal weights are, if the weights are changed by the user in the morpher while the UI isopen, the rollout won't update either - better use the morpher controllers directly
  • This is more of a nitpick but you don't have to convert bitarray to array if all you want is to iterate over it
(
    fn create_spinners channelData =
    (
        local rci = rolloutCreator "myRollout" "My Rollout"
        rci.begin()
        rci.str += "\tlocal mf_mod = modPanel.getCurrentObject()\n\n"

        for item in channelData do
            rci.addControl #spinner ("spn" + item.channel) item.name paramStr:("controller:mf_mod[" + item.channel + "]")

        createDialog (rci.end())
    )

    local mf_mod = modPanel.getCurrentObject()

    if not isKindOf mf_mod Morpher then messageBox "Select morpher modifier" else
    (
        local channelData = for channel = 1 to 100 where WM3_MC_HasData mf_mod channel collect
            dataPair channel:(channel as string) name:(WM3_MC_GetName mf_mod channel)
        create_spinners channelData
    )
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文