Lua 科罗纳新手,为什么';这个脚本不会产生任何可见的输出吗?

Lua 科罗纳新手,为什么';这个脚本不会产生任何可见的输出吗?,lua,coronasdk,Lua,Coronasdk,我刚接触Corona Sdk,我正在尝试开发一款类似Pig(骰子)的游戏。我找到了一个相同的脚本,但在运行它之后我没有得到输出,所以请帮我解决这个问题。我还需要一些关于Mac的Lua脚本的好的调试器的建议 另一个开发骰子游戏的类似教程将不胜感激 先谢谢你 --[[ dice.lua - A dice rolling module useful for bell curve type random distributions ===============================

我刚接触Corona Sdk,我正在尝试开发一款类似Pig(骰子)的游戏。我找到了一个相同的脚本,但在运行它之后我没有得到输出,所以请帮我解决这个问题。我还需要一些关于Mac的Lua脚本的好的调试器的建议

另一个开发骰子游戏的类似教程将不胜感激 先谢谢你

--[[

  dice.lua - A dice rolling module useful for bell curve type random distributions
  ================================================================================

  (c)2011 Shaun Sullivan
  Electric Plum, LLC
  www.electricplum.com

  twitter: @LiquidSullivan
  email: shaun@electricplum.com

  Please use freely in any of your projects!

    Example usage:

      local dice = require("dice")
      -- Most compact method roll 4d6 and subtract 2 from the roll
      local dRoller = dice.new({dice=4, sides=6, adjust=-2})
      dRoller.roll()

      local dRoller = dice.new()

      -- Roll 3 6 sided dice and add 1 to the result (string method)
      local roll = dRoller.rollFromDiceString("3d6+1")
      print("roll = "..tostring(roll))

      -- Add 3 8 sided dice and one 12 and then roll
      dRoller.reset()
      dRoller.addMultipleDice(3, 8)
      dRoller.addDie(12)
      roll = dRoller.roll()
      print("roll = "..roll)

      -- Roll 4 10-sided dice and add 6 to the total
      for i=1,10 do
        print(dRoller.rollFromDiceString("4d10+6"))
      end

]]--

module (..., package.seeall)

-------------------------------------------------------------------------------
-- new
--
-- Construct a new one and return it
-- Optional object constructor arguments: {dice, sides, adjust, seed}
--
-------------------------------------------------------------------------------
new = function(args)

  -- Table we'll return
  local t = {}

  -- privates

  -- array of dice
  local _dies = {}
  -- number of dice 
  local _numDies = 0
  -- random seed to use default to os.time() but can be overriden by the caller 
  local _seed = os.time()
  -- something to add or subtract to/from the die roll 
  local _adjust = 0

  -------------------------------------------------------------------------------
  -- initInternal
  -------------------------------------------------------------------------------
  local initInternal = function(args)

    if args then

      -- Use the caller's seed or just seed with the time
      _seed = args.seed or _seed
      _numDies = args.dice or 0
      _adjust = args.adjust or 0 

      if (_numDies > 0) then

        for i=1,_numDies do

          -- default to 6 sided 
          _dies[i] = args.sides or 6

        end
      end

    else

      -- No args passed at all, so we start empty
      _seed = os.time()
      _numDies =  0
      _adjust = 0

    end

    -- Seed, note the caller can pass in a seed to get a repeatable sequence
    math.randomseed(_seed)

  end

  -------------------------------------------------------------------------------
  -- rollInternal
  -------------------------------------------------------------------------------
  local rollInternal = function()

    local total = 0

    for i=1,_numDies do
      total = total + math.random(1, _dies[i])
    end

    return total + _adjust

  end

  -------------------------------------------------------------------------------
  -- quickResetInternal
  --
  -- Called by rollFromDiceString to make sure it gets a clean roll
  --
  -------------------------------------------------------------------------------
  local quickResetInternal = function()
    _dies = nil
    _dies = {}
    _numDies = 0
    _adjust = 0
  end

  -------------------------------------------------------------------------------
  -- Constructor
  -------------------------------------------------------------------------------
  initInternal(args)

  -- ============================================================================
  -- public interface
  -- ============================================================================

  -------------------------------------------------------------------------------
  -- reset
  -------------------------------------------------------------------------------
  t.reset = function(args)
    initInternal(args)
  end

  -------------------------------------------------------------------------------
  -- addDie
  -------------------------------------------------------------------------------
  t.addDie = function(sides) 

    _numDies = _numDies + 1
    _dies[_numDies] = sides

  end

  -------------------------------------------------------------------------------
  -- addMultipleDice
  -------------------------------------------------------------------------------
  t.addMultipleDice = function(numDiceToAdd, numSides)

    numDiceToAdd = numDiceToAdd or 1
    numSides = numSides or 6

    if (numDiceToAdd < 1) then
      print("bad args, forcing one die")  
      numDiceToAdd = 1
    end

    if (numSides < 1) then
      print("bad args, forcing 6 sides")  
      numSides = 6 
    end

    --for i=1,#_dies do
    for i=1,numDiceToAdd do

      _numDies = _numDies + 1
      _dies[_numDies] = numSides

    end

  end

  -------------------------------------------------------------------------------
  -- rollFromDiceString 
  --
  -- Pass in a string like "4d6+3" (roll 4 6 sided dice and add 3)
  -------------------------------------------------------------------------------
  t.rollFromDiceString = function(s)

    -- "split" Lifted from Crawlspace Lib 
    -- https://github.com/AdamBuchweitz/CrawlSpaceLib 
    local split = function(str, pat)
        local t = {}
        local fpat = "(.-)" .. pat
        local last_end = 1
        local s, e, cap = str:find(fpat, 1)
        while s do
            if s ~= 1 or cap ~= "" then table.insert(t,cap) end
            last_end = e+1
            s, e, cap = str:find(fpat, last_end)
        end
        if last_end <= #str then
            cap = str:sub(last_end)
            table.insert(t,cap)
        end
        return t
    end

    -- Sanity check to at least make sure we have a "d" in the string
    local dLoc = string.find(s, "d") or 0

    if (dLoc > 0) then

      local addSubRoll = 0
      local dice = split(s, "d")
      local numD = tonumber(dice[1])
      local stopAt = 0
      local sides = 0

      -- not super robust here, you could pass in +- in the same 
      -- string and break it, but just testing...   
      if (string.find(s, "+")) then

        local plus = string.find(s, "+")
        addSubRoll = tonumber(string.sub(s, plus + 1))
        stopAt = plus - 1

      elseif (string.find(s, "-")) then

        local minus = string.find(s, "-")
        addSubRoll = tonumber(string.sub(s, minus + 1)) * -1
        stopAt = minus - 1

      else
        stopAt = 0
      end     

      local dPos = string.find(s, "d")

      if (stopAt ~= 0) then
        sides = tonumber(string.sub(s, dPos + 1, stopAt))
      else
        sides = tonumber(string.sub(s, dPos))
      end

      -- We don't want to add to previous initializations
      quickResetInternal()
      t.addMultipleDice(numD, sides)

      _adjust = addSubRoll
      return(rollInternal())

    else
      assert(false, "Bad arguments")
    end 

  end

  -------------------------------------------------------------------------------
  -- roll
  -------------------------------------------------------------------------------
  t.roll = function()
    return rollInternal()
  end

  -------------------------------------------------------------------------------
  -- get_Seed
  --
  -- getter for the seed if the caller wants to store it for 
  -- some future replay
  -------------------------------------------------------------------------------
  t.get_Seed = function()
    return _seed
  end

  return t
end
--[[
lua-用于钟形曲线型随机分布的骰子滚动模块
================================================================================
(c) 2011年肖恩·沙利文
电气李子有限责任公司
www.electricplum.com
推特:@LiquidSullivan
电邮:shaun@electricplum.com
请在您的任何项目中自由使用!
用法示例:
本地骰子=需要(“骰子”)
--最紧凑的方法是滚动4d6并从滚动中减去2
本地dRoller=dice.new({dice=4,sides=6,adjust=-2})
dRoller.roll()
本地dRoller=dice.new()
--掷3个6面骰子,结果加1(字符串法)
本地滚动=dRoller.rollFromDiceString(“3d6+1”)
打印(“滚动=“…tostring(滚动))
--添加3个8面骰子和1个12面骰子,然后掷骰子
dRoller.reset()
dRoller.addMultipleDice(3,8)
德罗尔·阿德迪(12)
roll=dRoller.roll()
打印(“滚动”=…滚动)
--掷4个10面骰子,总共加6个
对于i=1,10 do
打印(dRoller.rollFromDiceString(“4d10+6”))
结束
]]--
模块(…,package.seeall)
-------------------------------------------------------------------------------
--新的
--
--构造一个新的并返回它
--可选对象构造函数参数:{dice,side,adjust,seed}
--
-------------------------------------------------------------------------------
新=函数(args)
--我们会回来的
局部t={}
--私人
--骰子阵
局部_={}
--骰子数
本地_numDies=0
--random seed可使用os.time()的默认值,但可由调用方重写
本地_seed=os.time()
--在模辊上加或减的东西
局部调整=0
-------------------------------------------------------------------------------
--初始内部
-------------------------------------------------------------------------------
本地initInternal=函数(args)
如果args那么
--使用呼叫者的种子或只是种子与时间
_种子=args.seed或_seed
_numDies=args.dice或0
_调整=args.adjust或0
如果(_numDies>0),则
当i=1时,数值为
--默认为6边
_模具[i]=参数侧或6
结束
结束
其他的
--根本没有传递参数,所以我们开始为空
_seed=os.time()
_numDies=0
_调整=0
结束
--Seed,注意调用方可以传入Seed以获得可重复的序列
数学。随机种子(_种子)
结束
-------------------------------------------------------------------------------
--内翻
-------------------------------------------------------------------------------
本地rollInternal=函数()
本地总数=0
当i=1时,数值为
总计=总计+数学随机(1,_[i])
结束
返回总+\u调整
结束
-------------------------------------------------------------------------------
--快速重置内部
--
--由rollFromDiceString调用,以确保获得干净的卷
--
-------------------------------------------------------------------------------
本地quickResetInternal=函数()
_死亡=零
_模具={}
_numDies=0
_调整=0
结束
-------------------------------------------------------------------------------
--建造师
-------------------------------------------------------------------------------
初始化内部(args)
-- ============================================================================
--公共接口
-- ============================================================================
-------------------------------------------------------------------------------
--重置
-------------------------------------------------------------------------------
t、 重置=功能(args)
初始化内部(args)
结束
-------------------------------------------------------------------------------
--阿迪
-------------------------------------------------------------------------------
t、 addDie=功能(侧面)
_numDies=\u numDies+1
_模具[_numDies]=侧面
结束
-------------------------------------------------------------------------------
--多目标
-------------------------------------------------------------------------------
t、 addMultipleDice=函数(numdicetodd,numSides)
numDiceToAdd=numDiceToAdd或1
numSides=numSides或6
如果(numDiceToAdd<1),则
打印(“错误参数,强制一个模具”)
numDiceToAdd=1
结束
如果(numSides<1),则
打印(“错误参数,强制6面”)
裸体=6
结束
--当i=1时,###
对于i=1,numdicetoaddo
_numDies=\u numDies+1
_骰子[_numDies]=numSides
结束
结束
-------------------------------------------------------------------------------
--滚骰子串
--
--像“4d6+3”一样传递字符串(滚动4个6边骰子并添加3个)
-------------------------------------------------------------------------------
t、 rollFromDiceString=函数
--从爬网空间库中取消“拆分”
-- https://github.com/AdamBuchweitz/CrawlSpaceLib 
局部拆分=功能(str、pat)
局部t={}
本地fpat=“(.-)”。。拍打
本地最后\u端=1
局部s,e,cap=str:find(fpat,1)
当我们做的时候
如果s~=1或cap~='',则table.insert(t,cap)end
最后一端=e+1
s、 e,cap=str:find(fpat,last_end)
结束
如果最后一个_结束0),则
本地addSubRoll=0
地方的
local diceLibrary = require("dice.lua")
diceLibrary.addDie(6)
local dice = require("dice")

local dRoller = dice.new( {dice=1, sides=6, adjust=0} )

for i=1, 10 do
    local result  = dRoller.roll()
    print( result )
end
22:00:10.125  1
22:00:10.125  4
22:00:10.125  2
22:00:10.125  3
22:00:10.125  6
22:00:10.125  3
22:00:10.125  3
22:00:10.125  6
22:00:10.125  1
22:00:10.125  1