Forgot password?

Create an account!

Forum

« back

RhinoScript – simple function error?

Messages

Please log in to write a message.

  • 2. drape (Sep 30, 2009 05.11):

    I got the answer. The function is recursive and has to call itself. i.e. checkLight = checkLight(strLight)

    Option Explicit

    Call lightDetect()
    Sub lightDetect()

    Dim strLight, lightType

    strLight = Rhino.GetObject ("Select light", 256)
    lightType = checkLight(strLight)
    Rhino.Print "lightType = " & lightType
    End Sub


    Function checkLight(strLight)

    If Rhino.IsDirectionalLight(strLight) Then
    Rhino.Print "The object is a directional light."
    checkLight = "directional"

    ElseIf Rhino.IsSpotLight(strLight) Then
    Rhino.Print "The object is a spot light."
    checkLight = "spot"
    Else
    Rhino.print "spot or dir. light only please"
    strLight = Rhino.GetObject ("Select light", 256)
    checkLight = checkLight(strLight)
    End If
    End Function
  • 1. drape (Sep 29, 2009 19.45):

    Hello,

    I'm testing lights and only want the user to have a spot or directional light.

    The attached code works and returns a value for checkLight if a spot or directional light is chosen first. If another type of light is chosen first and then a correct type is chosen, checkLight returns empty.

    I think I'm doing something wrong with the way I'm calling my function from within itself and the var recheck is causing the problem. But I'm not sure why it doesn't work.

    What's the proper way to write this?

    (to test, make a file with a spot, directional and some other type of light)

    -----

    Option Explicit

    Call lightDetect()
    Sub lightDetect()

    Dim strLight, lightType

    strLight = Rhino.GetObject ("Select light", 256)
    lightType = checkLight(strLight)
    Rhino.Print "lightType = " & lightType
    End Sub


    Function checkLight(strLight)

    Dim recheck

    If Rhino.IsDirectionalLight(strLight) Then
    Rhino.Print "The object is a directional light."
    checkLight = "directional"

    ElseIf Rhino.IsSpotLight(strLight) Then
    Rhino.Print "The object is a spot light."
    checkLight = "spot"
    Else
    Rhino.print "spot or dir. light only please"
    strLight = Rhino.GetObject ("Select light", 256)
    recheck = checkLight(strLight)
    End If
    End Function

    -----

Recommend

Why are these buttons gray?