Modding Help "bad argument #1 to 'for iterator' " Error

Discussion in 'Starbound Modding' started by ZedStudios98, Aug 19, 2016.

  1. ZedStudios98

    ZedStudios98 Big Damn Hero

    While attempting to program a custom weapon (specifically a revived Pulse Rifle from the Koala versions) I've encountered an error that I cannot figure out how to solve:
    Code:
    [16:05:24.647] [Error] Exception while calling script init: (LuaException) Error code 2, [string "/items/active/weapons/weapon.lua"]:298: bad argument #1 to 'for iterator' (table expected, got nil)
    stack traceback:
        [C]: in ?
        [C]: in for iterator 'for iterator'
        [string "/items/active/weapons/weapon.lua"]:298: in function <[string "/items/active/weapons/weapon.lua"]:297>
        (...tail calls...)
        [string "/items/active/weapons/ranged/gun.lua"]:14: in function <[string "/items/active/weapons/ranged/gun.lua"]:5>
    
    The following is the .activeitem code I'm using for the Pulse Rifle:
    Code:
    {
      "itemName" : "pulserifle",
      "price" : 150,
      "maxStack" : 1,
      "rarity" : "Uncommon",
      "description" : "A high-tech rifle, perfect for kicking some serious alien!",
      "shortdescription" : "Pulse Rifle",
      "tooltipKind" : "gun",
      "weaponType" : "Pulse Rifle",
      "twoHanded" : true,
      "itemTags" : ["weapon","ranged","pulserifle"],
      "level" : 1,
    
      "animation" : "/items/active/weapons/ranged/gun.animation",
      "animationParts" : { },
      "animationCustom" : { },
      "baseOffset" : [-1.0, 0.25],
      "muzzleOffset" : [0.0, 0.3125],
    
      "scripts" : ["/items/active/weapons/ranged/gun.lua"],
    
      "primaryAbility" : {
        "fireTime" : [0.13, 0.06],
        "baseDps" : [7, 8],
        "energyUsage" : 15,
        "inaccuracy" : 0.035,
    
        "fireType" : "auto",
    
        "projectileType" : "standardbullet",
        "projectileParameters" : {
          "knockback" : [4,8]
        }
      },
      "fireSounds" : [ "/sfx/gun/pulserifle1.ogg", "/sfx/gun/pulserifle2.ogg" ],
    
      "stances" : {
        "idle" : {
          "armRotation" : 0,
          "weaponRotation" : 0,
          "twoHanded" : true,
    
          "allowRotate" : true,
          "allowFlip" : true
        },
        "fire" : {
          "duration" : 0,
          "armRotation" : 3,
          "weaponRotation" : 3,
          "twoHanded" : true,
    
          "allowRotate" : false,
          "allowFlip" : false
        },
        "cooldown" : {
          "duration" : 0.05,
          "armRotation" : 3,
          "weaponRotation" : 3,
          "twoHanded" : true,
    
          "allowRotate" : false,
          "allowFlip" : false
        }
      },
    
      "builder" : "/items/buildscripts/buildweapon.lua",
      "builderConfig" : [{
        "nameGenerator" : "assaultnames.config:nameGen",
        "elementalType" : [
          "physical",
          "fire",
          "ice",
          "electric",
          "poison"
          ],
    
        "animationParts" : {
          "butt" : {
            "path" : "/items/active/weapons/ranged/revived/pulserifle/butt/<variant>.png",
            "variants" : 3,
            "paletteSwap" : true
          },
          "middle" : {
            "path" : "/items/active/weapons/ranged/revived/pulserifle/middle/<variant>.png",
            "variants" : 3,
            "paletteSwap" : true
          },
          "barrel" : {
            "path" : "/items/active/weapons/ranged/revived/pulserifle/barrel/<variant>.png",
            "variants" : 3,
            "paletteSwap" : true
          },
          "muzzleFlash" : "/items/active/weapons/ranged/muzzleflash.png"
        },
        "gunParts" : ["butt", "middle", "barrel"],
        "altAbilities" : [
          "/items/active/weapons/ranged/altabilities/explosiveshot/explosiveshot.altability",
          "/items/active/weapons/ranged/altabilities/grenadelauncher/grenadelauncher.altability"
        ],
        "palette" : "/items/active/weapons/colors/pulserifle.weaponcolors",
        "iconDrawables" : ["butt", "middle", "barrel"]
      }]
    }
    Does anyone know of a solution to this error?

    ~Zed
     
  2. Wheee321

    Wheee321 Subatomic Cosmonaut

    Hello,

    I am not sure if this relates to your problem, but you use .altability files, but in vanilla version I do only find .weaponability files
    Could you explain that to me?
     
  3. Inf_Wolf14

    Inf_Wolf14 Spaceman Spiff

    Problem in the script that handles your weapon. (weapon.lua/ranged.lua)
    Somewhere along the lines, a function in either script is being passed a nil value whereas the operation requires a table variable.

    Assuming your gun uses only vanilla abilities, probably the weapon has a property omitted that is needed. Compare it to vanilla files to see what you're missing.

    If I find it myself, I'll post the culprit in question.
     
  4. ZedStudios98

    ZedStudios98 Big Damn Hero

    I think I figured out the problem:

    At the "stances" section I had a "}" on the line above; it should have been placed after the section. It was a subtle error that I only found with a text compare website.

    I investigated that and realized the difference in earlier Giraffe versions compared to Cheerful Giraffe. I made that fix and it appears to have contributed to the solution.

    Anyway, those changes should solve the problem. I'll give a heads-up if it continues with anything else.
     

Share This Page