尝试连接字段' ?' (零值)电晕SDK

时间:2017-03-31 01:04:38

标签: lua corona

嘿,我是电晕和lua的新手,我正在为一个学校项目制作一个小记忆游戏,但我不断得到nill值的连接错误,它显示了来自在屏幕上连接但它没有工作

继承我的代码:

rule "Insert count collections per manager in same grade"
    salience 10
    when 
        $gradeClass: GradeInfo($grade: grade)
        $managerClass: ManagerInfo()
        accumulate(
            CollectionInfo(
                manager == $managerClass,
                $recoveryGrade: recoveryGrade == $grade),
            $count : count($recoveryGrade))
    then 
        insertLogical(new GradeStatic($gradeClass, $managerClass, $count.longValue()));
end

rule "Insert Compare total Receivables for each group"
    salience 10
    when 
        $groupClass: GroupInfo($groupId: groupId)
        $managerClass: ManagerInfo($managerName: name, groupId == $groupId)
        accumulate(
            CollectionInfo(
                manager == $managerClass,
                $receivables : receivables),
            $sum : sum($receivables))
    then 
        insertLogical(new GroupStatic($groupClass, $managerClass, $sum.doubleValue()));
end

// Hard constraints
rule "Hard Score 1 Weight And Receivables"
    when
        GroupStatic($highReceivable: totalReceivables, $weight: groupInfo.weight)
        GroupStatic(groupInfo.weight < $weight, $lowReceivable: totalReceivables)
        eval($highReceivable < $lowReceivable)
    then
        scoreHolder.addHardConstraintMatch(kcontext, -$lowReceivable);
end

rule "Hard Score 2-3 There is a manager who is not arranged collecion"
    when
        accumulate(
            GradeStatic(
                $arrangedManagerName: managerInfo.name),
            $arrangedManagerCnt : count($arrangedManagerName))
        accumulate(
            ManagerInfo($managerName: name),
            $managerCnt : count($managerName))
        accumulate(
            GradeInfo($grade: grade),
            $gradeCnt : count($grade))
        eval($arrangedManagerCnt < $managerCnt * $gradeCnt)
    then
        scoreHolder.addHardConstraintMatch(kcontext, -99999999.0);
end

// Soft constraints
rule "Calculate Soft Score"
    when
        GroupStatic($totalReceivables: totalReceivables, $weight: groupInfo.weight)
        accumulate(
            CollectionInfo(
                $receivables: receivables),
            $average: average($receivables))
    then
        System.out.println("Soft Score: "+ Math.abs($average.doubleValue() - ($totalReceivables / $weight))/1000000.0); 
        scoreHolder.addSoftConstraintMatch(kcontext, -(Math.abs($average.doubleValue() - ($totalReceivables / $weight)))/1000000.0);
end

欢迎任何建议

2 个答案:

答案 0 :(得分:2)

代码中唯一的连接发生在这一行:

local thing = display.newImage("images/" ..things[idx].. ".png")

因此,似乎things[idx]为零。

答案 1 :(得分:2)

idx函数中的索引值makeTiles()在内循环结束时递增,因此在外循环的几次迭代之后,idx引用{{ 1}} nil中的值,因为things#things

一种可能的解决方法是使用模数运算符在8idx之间保持1

8

这将重复循环遍历洗牌表。当idx=(idx % 8) + 1 重置为shuffle时,您也可以在things再次致电idx