Posts

Showing posts with the label Construct 2 if else

Construct 2: if-then-elseif-else statement

Image
Do you have an idea how to implement IF-THEN-ELSEIF-ELSE statement with Construct 2? At least I had to think for a while how to do it. It seems that this basic structure is not so straightforward to implement in C2. I was creating a very simple game where boxes were moving from left to right. See example below: The color of each box is chosen randomly, so it required the usage of random() function and if-then-else statement. There are probably several ways to do this, but I wanted to make this as simple as possible inside one single event and action box.  Normally I would create a if-then-elseif-else structure like this to select color for the box (pseudo-code just for an example): if randomNumber == 0       set colorOfBox = "red" else if randomNumber == 1       set colorOfBox = "yellow" else if randomNumber == 2       set colorOfBox = "green" else       set colorOfBox = "blue" end if But ...