LPC basic tutorial-Data Type

Source: Internet
Author: User

An LPC object is composed of zero or more variables controlled by one or more functions. In code, the order of function arrangement does not affect the object features, but the readability of the Code. When the object you wrote is called for the first time, the driver loads the code you wrote into the memory. When an object is transferred to the memory, all variables have no value. The create () function is called to initialize the object value. The create () function is called immediately after the object is loaded into the memory. When you read this article, you may not know anything about programming. You may not know what functions are and how they are called. Maybe you have some programming experience, you may be confused about how functions of a newly created object call each other. Before solving these confusions, you need to know more about what these function manipulation controls are. So you 'd better read this chapter: LPC data type. It can be said that almost 90% of errors (including loss of {} and () are caused by the incorrect use of LPC data types. I think the true understanding of this chapter can help you program more easily.

Computer Language

A well-known computer actually uses a machine code consisting of "0" and "1. Computers do not know human natural language at all, but actually they do not know the advanced languages we use, such as basic, C, C ++, Pascal, and so on. These advanced languages make it easier for us to implement our ideas. However, these advanced languages will eventually be translated into computer languages consisting of "0" and "1. There are two ways to translate advanced languages into computer languages: Compilation and interpretation. After the program is written, compile the class and use a compiler to translate it into a computer language. Compilation is completed before the program is executed. The translation process of the interpretation class is carried out during program execution. Since the language program of the interpretation class is executed and interpreted, it is generally slower than compiling and execution. Regardless of the language, they will eventually be translated into 0 and 1. However, variables that you have in the memory cannot be 0 or 1. So you must have a method in the programming language that you use to tell the computer that these 0 and 1 should be treated as integers, characters, strings, or something else. In this way, the data type must be used.

Data Type

A simple example: You now have a variable named 'X' and assign it a decimal integer of 65. In LPC, you can use the following statement to do this:

X = 65;

Then you can do something like the following:

Write (x + "/N ");

Y = x + 5;

The first line outputs 65 and the letter "A" to the screen, and the second line assigns the value 70 to the variable Y, which is a problem for the computer: it doesn't know what you mean by "x = 65. you think it is 65, but the computer may think it is 00000000000000000000000001000001. But for the computer, the letter 'A' is also considered as: 00000000000000000000000001000001, when you want the computer to understand write (x + "/N");, it must have a way to know that you want to see 65 instead of 'A '. computers distinguish between 65 and 'A' by data type '. A data type is simply somewhere in the memory, which represents or points to a given variable. What type of data is stored in the memory. each LPC variable must have its corresponding variable type. in the example given above, there should be the following line before those codes:

Int X;

This line tells driver X what type of value to point to. It should be used as a data type 'int. 'int' is a 32-bit integer. here, you should have a basic impression on the Data Type and why the data type must exist. they can let the driver know what the '0' and '1' in the memory are in the computer.

LPC data type

All lpmud drivers have the following data types: void, Int, String, object, mixed, int *, string *, object *, mixed * Most drivers have the following important data types: float, mapping, float *, and mapping *. Some drivers also support the following data types: function, struct, class, char Special Data Types supported by mudos: (take v22pre8 as an example) void, Int, String, object, float, mapping, function, class, mixed, int *, string *, object *, float *, mapping *, function *, class *, mixed *

Some simple data types

The following data types are introduced in LPC:

Void, Int, float, String, object, and mixed.

For complex data types such as mapping and array, and some uncommon types such as class and function, I will introduce them in LPC. this section describes three data types: int, float, and string ). an int (integer) is an integer, such as 1, 42,-18, 0, and-10002938. in mudos, an integer is a 32-bit integer with a signed integer. in practice, int is widely used. For example, we start to introduce wiz_level in variables, and for example, biological talents and ages are usually int (integer ). A float is a real number, such as 2.034,-102.3453, 0.0, and 1132741034.33. in mudos, a floating point number is also a 32-bit real number, a signed real number. float is not commonly used. in the numeric nature of an object, we usually Int, float, or even int are used only. During Variable initialization, int and float are automatically assigned 0. however, the general driver, such as mudos, does not check whether the value is out of bounds. It should be noted that both int and float are signed numbers. string is composed of one or more characters, such as "a", "I am a bird! "," 42 "," Birds 15 years old. "," I am trill. ", these are strings. note that the strings are enclosed by "", so that the first difference is as follows: int (integer) 42 and string (string) "42 ", second, you can distinguish variable names (such as room) from strings with the same name (such as "room "). when initializing a string type variable, if it is not explicitly assigned to a string such as an empty string "", it will be 0, which is an empty pointer. as the most basic data types, Int, float, and string are the basis of some complex data types. we will introduce the operators that perform operations and operations on these data later. However, the LPC operators are the same as the General C/C ++ operators. the only difference is that + LPC supports adding string and Int or float values directly. For example, the above mentioned: Write (x + "/N"); "/N" is a character, X is an integer variable. During LPC interpretation execution, the number represented by X is automatically set. The value is converted into a string, and then the two strings are connected together. when you use a variable in programming, you must first let the driver know what data type the variable represents. this process is called variable declaration. this variable must be declared in the beginning of a function or object. how can this problem be solved? Put the name of the Data Type before the name of the variable you want to use. For example:

Void add_x_and_y () {<br/> int X; <br/> int y; <br/> X = 2; <br/> Y = x + x * X; <br/>}

The above is a complete function. the function name is add_x_and_y (). in this function, two variables X and Y are declared at the beginning. the following describes the data types supported by mudos: int, an integer (32 bits ). float: A floating point number (32 bits ). an infinitely long string. object Pointer to an object. mapping a relational array. function is a special pointer that points to a combination of (object, function name. the Declaration of the arrays array follows a basic type using. the void type is useless to variables and only useful to functions. it indicates that this function does not return any value. mixed is a special data type that can point to any data type. if a variable is declared as mixed, the driver does not check it. the Custom Data Type of class, similar to the struct of C, is different from that of C ++ and class. one is the data type supported by mudos.


For a variable, the driver needs to know what '0' and '1' actually refer to in the computer memory, so that we can introduce the data type. we learned three simple data types and various data types supported by mudos. for various operators, different data types have different operators. For example, if you ask "bird"/"Trill", the driver will definitely return an error. the operator of most numbers is the same as that of C/C ++, but ++ also supports adding strings and numbers.

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.