If/Then statement and DrawBorder

About advanced scenes, and the Thyme scripting language used in Algodoo.

If/Then statement and DrawBorder

Postby TShrepel85 » Mon Mar 04, 2019 9:29 pm

Hello!

Just started writing script in this program in a pinball machine scene, and I'm having some trouble with an if/then statement working like it's supposed to. I have a set of 5 targets that I want to change states with DrawBorder and Restitution when the ball hits them. here's my code:

Code: Select all
(e)=>{
    drawBorder == false ? {
        drawBorder = true;
        restitution = 3
    } : {
        drawBorder = false;
        restitution = 1
    };
    points = points + 150
}


I've got this in the onCollide line of each of the targets, but it doesn't seem to want to do anything. The points line is a separate way I use to keep track of the player's points, and I've tried taking it out, still doesn't work. Any help y'all can give would be greatly appreciated. Thanks!
TShrepel85
 
Posts: 7
Joined: Mon Mar 04, 2019 9:00 pm

Re: If/Then statement and DrawBorder

Postby FRA32 » Wed Mar 06, 2019 1:00 pm

Keep in mind that comparisons dont work with boolean(true/false) values, as they are obsolete. Since drawBorder is a boolean value, you can't compare it to another boolean as theres a way simpler method.
Instead of writing drawBorder == false, simply write !drawBorder ? {} : {}
An exclamation mark negates the following boolean value, so if it's true, it becomes false, and vice versa. Since if statements operate purely on boolean statements, you dont need any comparisons after that, the negated value itself is enough to set the condition.
FRA32
 
Posts: 227
Joined: Wed Dec 03, 2014 9:51 pm

Re: If/Then statement and DrawBorder

Postby TShrepel85 » Thu Mar 07, 2019 11:22 pm

That's awesome! Thank you so much!
TShrepel85
 
Posts: 7
Joined: Mon Mar 04, 2019 9:00 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 4 guests

cron