Page 1 of 1

problem with a script for a score

PostPosted: Fri Jul 05, 2019 6:45 pm
by Drachenbauer
I have this in "on collision" in the script-menu:

(e)=>{
{
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
}
}
}
}

it should detect, if the other object of the collision has got one of theese three pig-textures and if je, add a matching score-value to the score of the bird, who holds this script.

But the score stays "0" (i display it on a rectangle, that should be my score-panel for this bird).

{condition}?{do_this_if_its_true}:{else_do_this}

the script should be three if-blocks like this, each one in the else-section of another, because there are three types of pigs around in my simulation, wich should make different score-values.
I see in this sample from a wiki, that all three parts are in curly brackets.
So i did this too.

In the script-menu, it turned into this:
(e)=>{
{
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
})
}
}
}

it adds round brackets around "?" and the to do part of the third if-block.

And if i try to add an empty else-part to the third if-block, the code will be replaced with "[BAD]" and the game crashes.

Why this script does not do, what i want and what is the right way to cause three diffent actions with three different conditions?

The birds are set to "killer" and "immortal", the pigs not.
Does that mean, the pigs disappear too fast for my script to check their textures?

Re: problem with a script for a score

PostPosted: Mon Jul 22, 2019 8:05 pm
by Ken3344
Your scripts are too confusing for me to trouble shoot. I'd appreciate it if you copy and pasted the script from Algodoo. Like this:
Code: Select all
(e)=>{
    e.other._marble ? {
        e.other.postStep = (e)=>{
            pos = _pos
        }
    } : {}
}

Until you do that, I can't figure out how to solve your problem.

Re: problem with a script for a score

PostPosted: Thu Jul 25, 2019 9:33 pm
by Drachenbauer
now i found a way to solve this, my self.

It works now.