3DGS script tutorial translation (10)-action

Source: Internet
Author: User
Workshop 10: Action

Action is a special function that can be attached with entities: players, elevators, monsters, weapons, etc. You can attach any entity to an action: model, Genie, or terrain. All actions are created in the Wed action list script, as shown below:

Let's take a look at the differences between functions and actions:

An action has a similar definition as a function. Let's look at an example:

Action add_numbers
{
B = a + 5;
}

Function add_numbers ()
{
B = a + 5;
}

It looks very similar, but there is a big difference:

-Call a function when we want to run it.

-The action must be attached to the object if we want it to run.

Actions are used only when you want to change the attributes of an object. functions do not need to process entities (for example, when you want to add numbers, just like in my example above ).

Are you ready? Start Wed and open work10 level:

Run the level immediately:

The plane starts to rotate! If you have learned lesson 8th, you will know that the plane has changed it.PanAngle.

Let's take a look at the relevant script and start Sed to open script10:

Have you noticed that these scripts become shorter as we learn more? Maybe the last tutorial only contains one line of code. Who knows ......

Most of the Code is easy to understand because we have seen it several times. We focus on learning the code for airplanes.

We have created a rotate_plane action, so its name will appear in the Wed action list. But what is this action list and where to view it?

In Wed, select the airplane model in the top window, right-click and select properties:

Click "action" and "select action ":

You will see the "select action" window, which allows us to select the action created in the script:

 

We only have one rotate_plane action in the list. Return to the Code:

Action rotate_plane
{
While (1)
{
My. pan = my. pan + 1;
Wait (1 );
}
}

Some actions or functions require a large period of time to run-some of them may run until the game is started! If you want to create a game that looks like a thunderboat, make sure that you can move your mouse any time. Otherwise, you cannot click a square. Do not say that you won't click it in the upper right corner"X"To end the game. All functions and actions are good till now, but not always running. They are executed for a while and then stopped. The plane is always rotating, so we should use some instructions to keep an action always running.

We need to learn how to make new things work: while (1) loops. What is a loop? See the following:

While (some condition is true)
{
// Repeat the instructions that are placed inside the curly brackets
}

Use the above actionsWhile (1), Which means always loop. OK. The first line in the action, rotate_plane, indicates the object to be recycled, but what is in the loop? There are only two rows:

My. pan = my. pan + 1;
Wait (1 );

The first line adds 1 to the plane's horizontal angle. The plane starts at 90 degrees and is then set to 91,92 ...... Therefore, the plane rotates in the horizontal plane.

But what is "wait (1? Let me first ask you: have you heard of multiple tasks? This is the ability to run multiple programs at the same time. Now you are reading the project, maybe you are still listening to music, maybe anti-virus software is still running ...... All these software run at the same time because one task on the computer is converted into another very much, so that you believe that all the programs are running together.

The same thing occurs in the while loop. They must allow the rest of the action and function. If a while loop is not stopped, all computer resources will be eaten, because it will repeat the loop continuously, and even the system will not be able to refresh the time!

So how do we pause a loop? The simplest way is to insert the "wait (1);" command, where each frame is paused. This small change allows other actions and functions to run their code.

To discuss the next frame and frame speed. What you see on the monitor is a series of continuous images. If your PC displays 50 pictures per second, it can run the game 50 frames per second. The frame speed is 50 FPS. A wait (1) Command tells the function or action to stop running when the PC displays one of 50 pictures.

Important:Each while (1) loop should contain an instruction to interrupt it. Normally, "wait (1);" is used );". If you forget to add "wait" or "sleep" in the while loop, the engine will give an error message like this:

Read the second part of the Manual "C-Script keywords" to learn more about "wait" and "sleep ".

Create a new action and copy and paste the following code to your script10 file:

Action change_roll
{
While (1)
{
My. roll = my. roll + 1;
Wait (1 );
}
}

The result looks like this:

Save the script, select Wed, and add a new fighter (mig) model to the top right window:

 

Make sure that the new model is visible. Select an appropriate location. You don't know how to do it?

Cameras (windows in the 3D world) can be controlled using C-Script commands, but for simplicity, I am not writing code until you learn something new. The camera is in its own position. What happens when we allow it to happen? It appears at the origin.

X = 0
Y = 0
Z = 0

The following figure shows the camera position in Wed:

The camera looks to the right, so I want to put a new object to see in the level, and its X should be greater than 0. Take a look at the initial picture and see how to choose the initial position of the plane:

 

Look at the top window and you will see the airplane model clearly. If you have set an appropriate position in the top window of Wed, you must note that you can set the plane height in the rear or left window. I encourage you to add a second airplane model, as shown below:

The second model (red) has an X greater than the first model and a Z greater than the first model. If you cannot place it in the correct position, right-click it and select its XYZ value.

Click "world location". If you need it, it works with the "real" 3D world. Click the "Action" tab in the "object properties" window and then click the "select action" button:

You will see the "select action" window and two actions in the list:

(If the action change_roll does not appear in the list, you forgot to save the modified script file. Save it and load it to work10)

Click change_roll and select OK to give you a big hug: You have allocated a new action to the second airplane model. The action name is change_roll:

Close the "object properties" window, save the level, set up, and run. You will see the following picture:

This is the effect of rotation! You can move the plane to the left or right if you do not like it. Change the X and Y values in the top window of Wed and set a different Z value in the back window.

I encourage you to join the third airplane model and change its skew angle in a loop with a new action. Don't look at the Solution Below-I will look at you!

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.