Modding Help Lua lights don't work

Discussion in 'Starbound Modding' started by WuZuMaX, Jul 14, 2017.

  1. WuZuMaX

    WuZuMaX Void-Bound Voyager

    Hey guys, let me explain my issue.
    What I want to do is to create a beam of light using only a lua file.
    This is the code i have in my tech:

    test = {
    active = false,
    position = {0, 0.5},
    color = {255, 0, 0},
    pointLight = true,
    pointAngle = 0,
    pointBeam = 4
    }
    animator.setLightActive(test, 1)

    However, it's not working. I get an error:
    Error code 2, [string "/tech/distortionsphere/distortionsphere.lua"]:26: (LuaConversionException) Error converting LuaValue to type 'class Star::String'

    So it fails to convert the "test" into a string... Any ideas why???
    Or maybe do you know any other methods to create a beam of light using lua (multiplayer friendly)???
     
    Last edited: Jul 14, 2017
  2. cpeosphoros

    cpeosphoros Orbital Explorer

    Because test is not a string, it is a table.

    As from doc/lua/animator.md:
    Code:
    The *animator* table contains functions that relate to an attached networked animator. Networked animators are found in:
    
    * tech
    * monsters
    * vehicles
    * status effects
    * active items
    [...]
    
    #### `void` animator.setLightActive(`String` lightName, bool active)
    Sets a light to be active/inactive.
    Quick example,
    Code:
    {
      "animationCustom" : {
        "animatedParts" : { "parts" : {
          "flashlight" : {
            "properties" : {
              "zLevel" : 5,
              "centered" : true,
              "offset" : [-1.25, -0.375],
              "transformationGroups" : ["muzzle"],
              "image" : "/items/active/weapons/ranged/abilities/flashlight/flashlight.png"
            }
          }
        }},
        "lights" : {
          "flashlightSpread" : {
            "active" : false,
            "position" : [-0.75, -0.5],
            "transformationGroups" : ["muzzle"],
            "color" : [80, 80, 80]
          },
          "flashlight" : {
            "active" : false,
            "position" : [-1.25, -0.5],
            "transformationGroups" : ["muzzle"],
            "color" : [200, 200, 200],
            "pointLight" : true,
            "pointAngle" : 0.00,
            "pointBeam" : 2.5
          }
        },
        "sounds" : {
          "flashlight" : [ "/sfx/tools/flashlight_toggle.ogg" ]
        }
      },
    
      "ability" : {
        "name" : "Flashlight",
        "type" : "flashlight",
        "scripts" : ["/items/active/weapons/ranged/abilities/flashlight/flashlight.lua"],
        "class" : "Flashlight"
      }
    }
    Now, see this section:
    Code:
    "lights" : {
          "flashlightSpread" : {
            "active" : false,
            "position" : [-0.75, -0.5],
            "transformationGroups" : ["muzzle"],
            "color" : [80, 80, 80]
          },
          "flashlight" : {
            "active" : false,
            "position" : [-1.25, -0.5],
            "transformationGroups" : ["muzzle"],
            "color" : [200, 200, 200],
            "pointLight" : true,
            "pointAngle" : 0.00,
            "pointBeam" : 2.5
          }
        }
    Right? Those are the lights connected to this "weapon" - the flashlight is treated as it if were a weapon - so, the lights are "flashlightSpread" and "flashlight".

    Well, right in the end of the complete code, there's a reference to the script "flashlight.lua". In that script, we have:

    Code:
        animator.setLightActive("flashlight", self.active)
        animator.setLightActive("flashlightSpread", self.active)
        [...]
        animator.setLightActive("flashlight", false)
        animator.setLightActive("flashlightSpread", false)
    So, that's the way of turning lights on and off.
     
    WuZuMaX and bk3k like this.
  3. WuZuMaX

    WuZuMaX Void-Bound Voyager

    Alright, thanks for explaining the issue.
    Now I attached the light to a weapon and it's working (Even on multiplayer!)
     
  4. cpeosphoros

    cpeosphoros Orbital Explorer

    Any time.
     

Share This Page