Lesson 5.9 – Creating a Swivel Door
The task – creating a swivel door
In this lesson we will create a swivel door.
We will get to know a new programming environment, and through it we will create the script intended for rotating the door. To do this, we will learn about the use of variables.
First, enter the SCRIPTASTIC programming environment.
This environment is based on code using blocks.
On the left are the block drawers for creating the code.
Open the EVENTS category, and drag the event named WHEN SCRIPT IS RESET
toward the panel on the right side of the screen.
From group FUNCTIONS, drag the integral variable block.
We will change the values.
Rename the variable to am I opened.
The variable will serve as the door status identifier (closed or open).
We will change the numeric value to 0.
Return to the EVENTS group and drag the WHEN OBJECT IS CLICKED block to the right panel.
Then, add the block which will constitute the condition of the door.
This condition will allow the script to differentiate between the
two different modes of the door.
In the writing field, write the variable name as follows: am I opened == 0
Now drag the block
From the MOTIONS group, and change the rotation value to 90 degrees.
Add the block within the condition block.
Now, we will define that the 90 degree rotation,
constitutes the condition of the door as open,
so we need to add under this command the integral variable,
but we will change the numeric value from 0 to 1.
so the script will recognize the condition as open.
Next, define in the script the second situation:
when the door is already open, it should be closed.
At the bottom of the condition,
we will drag the block
But now, the rotation values will be reversed – instead of 90 degrees,
write -90 degrees to return the door to its original position.
As in the previous situation,
set in the script that the 90-degree rotation is a closed position in the door.
At this point we have finished creating the script, and now we’ll copy it.
At the top of the screen click on the LSL SCRIPT tab to see the full script.
Select and copy it.
Go back to the world, and
the new door
Click the CONTENT tab, and create a new script.
Delete all existing content in the script, and paste the new script.
Save the changes with the SAVE button.
Now, every click on the door will cause it to open and close.