Construct a script engine using C language (1) script syntax definition

Source: Internet
Author: User
Construct a script engine using C language (1)

Author: kevin_qing

Please note

Requirements:
Implement the NPC logic and interact with the game (server.

For example, if you want to open a window with the merchant NPC

Design:
After referring to the legendary 2 server-side script (poor implementation), the script rules are defined as follows:

1. C language is used, because many people are familiar with C, and C syntax is more rigorous and easy to use
2. Data Types only support int and const string (parameters or return values for external functions). variables can only be int and do not need to be declared.
3. The supported syntax is function call (external), if-[else], switch-case, Goto, and only one main () function can be defined.
External function return value
4. Considering the efficiency, the script is compiled and executed in the VM.

Example:

Main (){
Say ("Hello, ^ 1% s ^ 0 I am here to provide you with a variety of quality services/N"
"Such as red name, job transfer, buy baby, drugs, and so on ...... And so on/N"
"If ^ 1% s ^ 0 are you sure you need the service, please go to select the required service/N"
"<SELECT> allow <forget it>", username (), username ());
Switch (wait (0 )){
1 :{
Say ("<transfer> quit <drug> quit <beauty>/N ");
Switch (wait (0 )){
1: {// Transfer
If (JOB () = 0) // warrior
{
Say ("are you tired of blood and fire as a warrior? /N"
"Transferred to <wizards> <monks>/N ");
Switch (wait (0 )){
1:

2:

}

} Else //........
//.........
}
//.......

}

 
}
2:
Return;

}

}

 

Explanation:
The above script uses two external function calls
The say () parameter is the same as that of printf (). ^ 1 ^ 0 in the string changes the font color, and <> the content in the string is optional (like the link in HTML)
Wait () is a waiting event. 0 is currently the event selected by the user.

Main (){
Say ("Hello, ^ 1% s ^ 0 I am here to provide you with a variety of quality services/N"
"Such as red name, job transfer, buy baby, drugs, and so on ...... And so on/N"
"If ^ 1% s ^ 0 are you sure you need the service, please go to select the required service/N"
"<SELECT> allow <forget it>", username (), username ());
Switch (wait (0 )){
1 :{
Say ("<transfer> quit <drug> quit <beauty>/N ");
Switch (wait (0 )){
1: {// Transfer
If (JOB () = 0) // warrior
{
Say ("are you tired of blood and fire as a warrior? /N"
"Transferred to <wizards> <monks>/N ");
Switch (wait (0 )){
1:

2:

}

} Else //........
//.........
}
//.......

}

 
}
2:
Return;

}

}

 

Explanation:
The above script uses two external function calls
The say () parameter is the same as that of printf (). ^ 1 ^ 0 in the string changes the font color, and <> the content in the string is optional (like the link in HTML)
Wait () is a waiting event. 0 is currently the event selected by the user.

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.