File tree Expand file tree Collapse file tree 5 files changed +88
-60
lines changed Expand file tree Collapse file tree 5 files changed +88
-60
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ int main(object me, string arg)
9
9
printf ("s[0..20] = %s\n" , s [0. .20 ]);
10
10
printf ("s[20..30] = %s\n" , s [20. .30 ]);
11
11
printf ("s[1..0] = %s\n" , s [1. .0 ]);
12
+ printf ("s[4..<1] = %s\n" , s [4. .< 1 ]);
13
+ printf ("s[<7..<5] = %s\n" , s [< 7. .< 5 ]);
12
14
13
15
return 1 ;
14
16
}
Original file line number Diff line number Diff line change 1
- private
2
- void test1 ()
3
- {
4
- printf ("%s\n" , "A:我是 private test1。" );
5
- }
6
-
7
- protected
8
- void test2 ()
9
- {
10
- printf ("%s\n" , "A:我是 protected test2。" );
11
- }
12
-
13
- public
14
- void test3 ()
15
- {
16
- printf ("%s\n" , "A:我是 public test3。" );
17
- }
18
-
19
- void test4 ()
1
+ // 示例:5.1.1
2
+ // apply 方法,对象加载时自动执行
3
+ void create ()
20
4
{
21
- printf ("%s\n" , "A:我还是 public test4。" );
5
+ // 发送信息给当前玩家
6
+ write ("create 5.1.1!\n" );
22
7
}
23
8
24
- void test ()
9
+ // apply 方法,设置心跳后自动执行
10
+ void heart_beat ()
25
11
{
26
- printf ("%s\n" , "A:我是 public 并且 nomask test。" );
12
+ // 记录日志,请在driver界面或 debug.log 文件中查看
13
+ debug_message (file_name (this_object ()) + ": " + time ());
27
14
}
28
15
29
16
int main (object me , string arg )
30
17
{
31
- test1 ();
32
- test2 ();
33
- test3 ();
34
- test4 ();
35
- test ();
36
- return 1 ;
37
- }
18
+ if (query_heart_beat ())
19
+ {
20
+ write ("停止心跳!\n" );
21
+ set_heart_beat (0 );
22
+ }
23
+ else
24
+ {
25
+ write ("开始心跳!\n" );
26
+ set_heart_beat (1 );
27
+ }
38
28
39
- void create ()
40
- {
41
- debug_message ("create 5.1.1" );
29
+ return 1 ;
42
30
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ // 示例:5.2.1
2
+
3
+ // 全局变量,可以在当前文件中使用,不会被存档
4
+ nosave string file = "/data/dbase" ;
5
+ // 全局变量,可以在当前文件中使用,会被存档
6
+ string data ;
7
+
8
+ int sum (int m , int n );
9
+
10
+ int main (object me , string arg )
11
+ {
12
+ // me、arg 是局部变量,可以在 main() 内部使用
13
+ if (arg == "load" )
14
+ {
15
+ if (file_size (file + __SAVE_EXTENSION__ ) > 0 )
16
+ {
17
+ // 读取存档,file 是全局变量
18
+ restore_object (file );
19
+ printf ("data = %s\n" , data );
20
+ }
21
+ else
22
+ {
23
+ printf ("目前没有存档!\n" );
24
+ }
25
+ }
26
+ else if (arg )
27
+ {
28
+ // data 是全局变量
29
+ data = arg ;
30
+ // 数据存档,file 是全局变量
31
+ if (!catch (save_object (file )))
32
+ {
33
+ printf ("数据存档成功!\n" );
34
+ }
35
+ else
36
+ {
37
+ printf ("数据存档失败,请确认存档目录 data 存在!\n" );
38
+ }
39
+ }
40
+ else
41
+ {
42
+ // begin、end、result 是块级变量,只能在本代码块内使用
43
+ int begin = 1 , end = 1024 ;
44
+ int result = sum (begin , end );
45
+ printf ("The sum from %d to %d is %d\n" , begin , end , result );
46
+ }
47
+
48
+ return 1 ;
49
+ }
50
+
51
+ int sum (int m , int n )
52
+ {
53
+ int sum = 0 ;
54
+ //m、n、sum 都是局部变量,只能在 sum() 内部使用
55
+ // i 是块级变量,只能在 for 循环内部使用
56
+ for (int i = m ; i <= n ; i ++ )
57
+ {
58
+ sum += i ;
59
+ }
60
+ return sum ;
61
+ }
Original file line number Diff line number Diff line change
1
+ # 如果系统未能在 log 目录下自动生成以下二个文件,请手动增加
2
+ # author_stats
3
+ # domain_stats
4
+ *
5
+ ! .gitignore
You can’t perform that action at this time.
0 commit comments