Tutorial Don't use math.pow, use ^ in Lua with Starbound

Discussion in 'Starbound Modding' started by zekrom_vale, Feb 7, 2018.

  1. zekrom_vale

    zekrom_vale Tentacle Wrangler

    If you are also having trouble with powers, use the carrot (^) as math.pow gives an error. (Original file rewardbag.lua)
    Code:
    local level = config.getParameter("treasure.level")
        local variance = config.getParameter("treasure.variance")
        local factor = config.getParameter("treasure.factor")
       
        if variance == 0 then
            return level
        end
        local rez = math.floor(
            math.random(level^factor, (level + variance)^factor)^(1/factor)    + 0.5
        )
        return variance - rez + 2 * level
    But this gives a nil value...
    Code:
    local level = config.getParameter("treasure.level")
        local variance = config.getParameter("treasure.variance")
        local factor = config.getParameter("treasure.factor")
       
        if variance == 0 then
            return level
        end
        local rez = math.floor(
            math.pow(
                math.random(
                    math.pow(
                        level,
                        factor
                    ), math.pow(
                        level + variance,
                        factor
                    )
                ),
                1/factor
            )
            + 0.5
        )
        return variance - rez + 2 * level
    P.S. Why is this the case and could this be fixed? I didn't even know you could exclude functions in the base script.
     
  2. Nexus Of Chaos

    Nexus Of Chaos Parsec Taste Tester

    Modding help should not be used in this situation. Modding Discussion would be appropriate, and Tutorial slightly more precise
     
  3. bk3k

    bk3k Oxygen Tank

    math.pow is depreciated in LUA 5.3

    edit:

    Easily remedied if you like.

    Code:
    math.pow = function(num, factor)
      return num^factor
    end
    
     
    Boshed likes this.

Share This Page