我如何在algodoo的百里香脚本中编写三个if块组的脚本

时间:2019-07-08 21:37:07

标签: haskell-thyme

我正在和物理模拟器Algodoo玩耍。

它包含一种称为“百里香”的脚本语言。

我正在创建一个类似于大理石赛道的小模拟,许多用户使用它进行创建。

我想显示我的弹珠的分数,这应该实现每一个尖齿,其中一个弹珠通过与之碰撞来击败一个敌人。

有三种类型的敌人,得分不同。

我的大理石应该能够通过检查其纹理是否与敌人碰撞来检测。

我想在大理石的“ onCollide”字段中使用此百里香脚本的三个if块来实现这一目标。

我尝试了许多这种方法:

1。

{
    e.other.texture == "Minion_pig_240.png"
}?{
    scene.my.red = scene.my.red + 5000
}:{
    {
        e.other.texture == "CorporalPig.png"
    }?{
        scene.my.red = scene.my.red + 10000
    }:{
        {
            e.other.texture == "KingPig.png"
        }?{
            scene.my.red = scene.my.red + 20000
        }
    }
}

2。

{
    e.other.texture == "Minion_pig_240.png"
}?{
    scene.my.red = scene.my.red + 5000
}:{
    {
        e.other.texture == "CorporalPig.png"
    }?{
        scene.my.red = scene.my.red + 10000
    }:{
        {
            e.other.texture == "KingPig.png"
        }?{
            scene.my.red = scene.my.red + 20000
        }:{

        }
    }
}

3。

e.other.texture == "Minion_pig_240.png"?{
    scene.my.red = scene.my.red + 5000
}:{
    e.other.texture == "CorporalPig.png"?{
        scene.my.red = scene.my.red + 10000
    }:{
        e.other.texture == "KingPig.png"?{
            scene.my.red = scene.my.red + 20000
        }
    }
}

4。

e.other.texture == "Minion_pig_240.png"?{
    scene.my.red = scene.my.red + 5000
}:{
    e.other.texture == "CorporalPig.png"?{
        scene.my.red = scene.my.red + 10000
    }:{
        e.other.texture == "KingPig.png"?{
            scene.my.red = scene.my.red + 20000
        }:{

        }
    }
}

5。

{
    e.other.texture == "Minion_pig_240.png"
}?{
    scene.my.red = scene.my.red + 5000
}

{
    e.other.texture == "CorporalPig.png"
}?{
    scene.my.red = scene.my.red + 10000
}

{
    e.other.texture == "KingPig.png"
}?{
    scene.my.red = scene.my.red + 20000
}

6。

{
    e.other.texture == "Minion_pig_240.png"
}?{
    scene.my.red = scene.my.red + 5000
}:{

}

{
    e.other.texture == "CorporalPig.png"
}?{
    scene.my.red = scene.my.red + 10000
}:{

}

{
    e.other.texture == "KingPig.png"
}?{
    scene.my.red = scene.my.red + 20000
}:{

}

7。

e.other.texture == "Minion_pig_240.png"?{
    scene.my.red = scene.my.red + 5000
}

e.other.texture == "CorporalPig.png"?{
    scene.my.red = scene.my.red + 10000
}

e.other.texture == "KingPig.png"?{
    scene.my.red = scene.my.red + 20000
}

8。

e.other.texture == "Minion_pig_240.png"?{
    scene.my.red = scene.my.red + 5000
}:{

}

e.other.texture == "CorporalPig.png"?{
    scene.my.red = scene.my.red + 10000
}:{

}

e.other.texture == "KingPig.png"?{
    scene.my.red = scene.my.red + 20000
}:{

}

9。

{
    e.other.texture == "Minion_pig_240.png"
}?{
    e.other.density = NaN;
    scene.my.red = scene.my.red + 5000
}:{
    {
        e.other.texture == "CorporalPig.png"
    }?{
        e.other.density = NaN;
        scene.my.red = scene.my.red + 10000
    }:{
        {
            e.other.texture == "KingPig.png"
        }?{
            e.other.density = NaN;
            scene.my.red = scene.my.red + 20000
        }
    }
}

10。

{
    e.other.texture == "Minion_pig_240.png"
}?{
    e.other.density = NaN;
    scene.my.red = scene.my.red + 5000
}:{
    {
        e.other.texture == "CorporalPig.png"
    }?{
        e.other.density = NaN;
        scene.my.red = scene.my.red + 10000
    }:{
        {
            e.other.texture == "KingPig.png"
        }?{
            e.other.density = NaN;
            scene.my.red = scene.my.red + 20000
        }:{

        }
    }
}

11。

e.other.texture == "Minion_pig_240.png"?{
    e.other.density = NaN;
    scene.my.red = scene.my.red + 5000
}:{
    e.other.texture == "CorporalPig.png"?{
        e.other.density = NaN;
        scene.my.red = scene.my.red + 10000
    }:{
        e.other.texture == "KingPig.png"?{
            e.other.density = NaN;
            scene.my.red = scene.my.red + 20000
        }
    }
}

12。

e.other.texture == "Minion_pig_240.png"?{
    e.other.density = NaN;
    scene.my.red = scene.my.red + 5000
}:{
    e.other.texture == "CorporalPig.png"?{
        e.other.density = NaN;
        scene.my.red = scene.my.red + 10000
    }:{
        e.other.texture == "KingPig.png"?{
            e.other.density = NaN;
            scene.my.red = scene.my.red + 20000
        }:{

        }
    }
}

13。

{
    e.other.texture == "Minion_pig_240.png"
}?{
    e.other.density = NaN;
    scene.my.red = scene.my.red + 5000
}

{
    e.other.texture == "CorporalPig.png"
}?{
    e.other.density = NaN;
    scene.my.red = scene.my.red + 10000
}

{
    e.other.texture == "KingPig.png"
}?{
    e.other.density = NaN;
    scene.my.red = scene.my.red + 20000
}

14。

{
    e.other.texture == "Minion_pig_240.png"
}?{
    e.other.density = NaN;
    scene.my.red = scene.my.red + 5000
}:{

}

{
    e.other.texture == "CorporalPig.png"
}?{
    e.other.density = NaN;
    scene.my.red = scene.my.red + 10000
}:{

}

{
    e.other.texture == "KingPig.png"
}?{
    e.other.density = NaN;
    scene.my.red = scene.my.red + 20000
}:{

}

15。

e.other.texture == "Minion_pig_240.png"?{
    e.other.density = NaN;
    scene.my.red = scene.my.red + 5000
}

e.other.texture == "CorporalPig.png"?{
    e.other.density = NaN;
    scene.my.red = scene.my.red + 10000
}

e.other.texture == "KingPig.png"?{
    e.other.density = NaN;
    scene.my.red = scene.my.red + 20000
}

16。

e.other.texture == "Minion_pig_240.png"?{
    e.other.density = NaN;
    scene.my.red = scene.my.red + 5000
}:{

}

e.other.texture == "CorporalPig.png"?{
    e.other.density = NaN;
    scene.my.red = scene.my.red + 10000
}:{

}

e.other.texture == "KingPig.png"?{
    e.other.density = NaN;
    scene.my.red = scene.my.red + 20000
}:{

}

17。

{
    e.other.texture == "Minion_pig_240.png"
}?{
    e.other.density = 0;
    scene.my.red = scene.my.red + 5000
}:{
    {
        e.other.texture == "CorporalPig.png"
    }?{
        e.other.density = 0;
        scene.my.red = scene.my.red + 10000
    }:{
        {
            e.other.texture == "KingPig.png"
        }?{
            e.other.density = 0;
            scene.my.red = scene.my.red + 20000
        }
    }
}

18。

{
    e.other.texture == "Minion_pig_240.png"
}?{
    e.other.density = 0;
    scene.my.red = scene.my.red + 5000
}:{
    {
        e.other.texture == "CorporalPig.png"
    }?{
        e.other.density = 0;
        scene.my.red = scene.my.red + 10000
    }:{
        {
            e.other.texture == "KingPig.png"
        }?{
            e.other.density = 0;
            scene.my.red = scene.my.red + 20000
        }:{

        }
    }
}

19。

e.other.texture == "Minion_pig_240.png"?{
    e.other.density = 0;
    scene.my.red = scene.my.red + 5000
}:{
    e.other.texture == "CorporalPig.png"?{
        e.other.density = 0;
        scene.my.red = scene.my.red + 10000
    }:{
        e.other.texture == "KingPig.png"?{
            e.other.density = 0;
            scene.my.red = scene.my.red + 20000
        }
    }
}

20。

e.other.texture == "Minion_pig_240.png"?{
    e.other.density = 0;
    scene.my.red = scene.my.red + 5000
}:{
    e.other.texture == "CorporalPig.png"?{
        e.other.density = 0;
        scene.my.red = scene.my.red + 10000
    }:{
        e.other.texture == "KingPig.png"?{
            e.other.density = 0;
            scene.my.red = scene.my.red + 20000
        }:{

        }
    }
}

21。

{
    e.other.texture == "Minion_pig_240.png"
}?{
    e.other.density = 0;
    scene.my.red = scene.my.red + 5000
}

{
    e.other.texture == "CorporalPig.png"
}?{
    e.other.density = 0;
    scene.my.red = scene.my.red + 10000
}

{
    e.other.texture == "KingPig.png"
}?{
    e.other.density = 0;
    scene.my.red = scene.my.red + 20000
}

22。

{
    e.other.texture == "Minion_pig_240.png"
}?{
    e.other.density = 0;
    scene.my.red = scene.my.red + 5000
}:{

}

{
    e.other.texture == "CorporalPig.png"
}?{
    e.other.density = 0;
    scene.my.red = scene.my.red + 10000
}:{

}

{
    e.other.texture == "KingPig.png"
}?{
    e.other.density = 0;
    scene.my.red = scene.my.red + 20000
}:{

}

23。

e.other.texture == "Minion_pig_240.png"?{
    e.other.density = 0;
    scene.my.red = scene.my.red + 5000
}

e.other.texture == "CorporalPig.png"?{
    e.other.density = 0;
    scene.my.red = scene.my.red + 10000
}

e.other.texture == "KingPig.png"?{
    e.other.density = 0;
    scene.my.red = scene.my.red + 20000
}

24。

e.other.texture == "Minion_pig_240.png"?{
    e.other.density = 0;
    scene.my.red = scene.my.red + 5000
}:{

}

e.other.texture == "CorporalPig.png"?{
    e.other.density = 0;
    scene.my.red = scene.my.red + 10000
}:{

}

e.other.texture == "KingPig.png"?{
    e.other.density = 0;
    scene.my.red = scene.my.red + 20000
}:{

}

但没有一个能正常工作...

Algodoo自动在theese脚本的某些部分周围添加圆括号。

什么是正确的管理方式? (有人可以为我添加标签“ Algodoo”和“百里香”吗?我没有足够的声誉积分来做到这一点。)

1 个答案:

答案 0 :(得分:0)

您需要调用该函数。这是我为这三种方式所做的事情

(e)=>{
    (e.other.var == 0 ? {
        color = [0, 0, 1]
    } : {
        (e.other.var == 1 ? {
            color = [0, 1, 0]
        } : {
            (e.other.var == 2 ? {
                color = [1, 0, 0]
            } : {})()
        })()
    })()
}

我对此进行了测试,但效果很好,但就您而言,它看起来像这样(未测试适合您的那个)

(e)=>{
    (e.other.texture == "Minion_pig_240.png" ? {
        e.other.density = 0;
        scene.my.red = scene.my.red + 5000
    } : {
        (e.other.texture == "CorporalPig.png" ? {
            e.other.density = 0;
            scene.my.red = scene.my.red + 10000
        } : {
            (e.other.texture == "KingPig.png" ? {
                e.other.density = 0;
                scene.my.red = scene.my.red + 20000
            } : {})()
        })()
    })()
}

请注意,可能有更好的方法对此进行编码,但这正是您所需要的