Improve the documentation of functions in CBOT
parent
e5c9e86e5f
commit
e04e8b7f6a
|
@ -1,8 +1,22 @@
|
|||
\b;Functions
|
||||
With functions you can divide your program into several parts, each of them will execute a specific task.
|
||||
Let's imagine following program¦:
|
||||
Function, simply put, is an instruction created by you.
|
||||
|
||||
\b;Main function
|
||||
You probably already know how to create a function. Every program in CBOT must have a main function, which looks like this:
|
||||
\c;
|
||||
\s;extern void object::Remote( )
|
||||
\s;extern void object::ProgramName()
|
||||
\s;{
|
||||
\s;
|
||||
\s; // instructions
|
||||
\s;
|
||||
\s;}
|
||||
\n;
|
||||
Nothing but a name can be changed in the main function. The keyword \c;extern\n; distinguish the main function from others.
|
||||
|
||||
\b;Basic use
|
||||
With functions you can divide your program into several parts. Each of them will execute a specific task. For example, see the following program:
|
||||
\c;
|
||||
\s;extern void object::Remote()
|
||||
\s;{
|
||||
\s; send("order", 1, 100);
|
||||
\s; wait(5);
|
||||
|
@ -14,14 +28,15 @@ Let's imagine following program¦:
|
|||
\s; wait(5);
|
||||
\s;}
|
||||
\n;
|
||||
\c;send\n; and \c;wait\n; are repeated several times. So it would be a good thing if we created a function that executes these two instructions:
|
||||
\c;\l;send\u cbot\send;\n; and \c;\l;wait\u cbot\wait;\n; are repeated several times. So it would be a good thing if we created a function that executes these two instructions:
|
||||
\c;
|
||||
\s;void object::SendToPost( float op )
|
||||
\s;void SendToPost(float op)
|
||||
\s;{
|
||||
\s; send("order", op, 100);
|
||||
\s; wait(5);
|
||||
\s;}
|
||||
\s;extern void object::Remote( )
|
||||
\s;
|
||||
\s;extern void object::Remote()
|
||||
\s;{
|
||||
\s; SendToPost(1);
|
||||
\s; SendToPost(3);
|
||||
|
@ -29,17 +44,35 @@ Let's imagine following program¦:
|
|||
\s; SendToPost(4);
|
||||
\s;}
|
||||
\n;
|
||||
A function can have paramteters¦:
|
||||
Now the program is much easier to read. It is a good practice to split the program into several functions with self-describing names.
|
||||
|
||||
\b;Syntax
|
||||
\c;
|
||||
\s;void Example( int a, float x, string s )
|
||||
\s;result_type FunctionName(optional_parameters)
|
||||
\s;{
|
||||
\s; body
|
||||
\s;}
|
||||
\n;
|
||||
The \c;Example\n; function will reveive un integer \c;a\n;, a floating point number \c;x\n; and a string \c;s\n;. Parameters are "passed by value", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an \c;int\n; to a function, its parameter is a copy of whatever value was being passed as argument, and the function can change its parameter value without affecting values in the code that invoked the function.
|
||||
A function must be declared above the main function. Result \l;type\u cbot\type; should be \l;void\u cbot/void; if the function does not give any. Body is just a set of instructions. Function name must be created with the exact same rules applied to \l;variables\u cbot\var;.
|
||||
|
||||
If you pass a \l;class\u cbot\class; instance or an \l;array\u cbot\array; as parameter to a function, the function only receives a \l;reference\u cbot\pointer; to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actuallay modified.
|
||||
|
||||
A function can also return a result with the \c;\l;return\u cbot\return;\n; instruction. Therefore the function must be declared no longer as void but as a type:
|
||||
\t;Parameters
|
||||
A function can have parameters:
|
||||
\c;
|
||||
\s;float Mean( float a, float b )
|
||||
\s;void Example(int a, float x, string s)
|
||||
\s;{
|
||||
\s; message(a);
|
||||
\s; message(x);
|
||||
\s; message(s);
|
||||
\s;}
|
||||
\n;
|
||||
The \c;Example\n; function will receive an \l;integer\u cbot\int; \c;a\n;, a \l;floating point number\u cbot\float; \c;x\n; and a \l;string\u cbot\string; \c;s\n;. Parameters are "passed by value", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an \c;\l;int\u cbot\int;\n; to a function, its parameter is a copy of whatever value was being passed as the argument, and the function can change its parameter value without affecting values in the code that invoked the function.
|
||||
|
||||
If you pass a \l;class\u cbot\class; instance or an \l;array\u cbot\array; as parameter to a function, the function only receives a \l;reference\u cbot\pointer; to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actually modified.
|
||||
|
||||
\t;Result
|
||||
A function can also return a result with the \c;\l;return\u cbot\return;\n; instruction. Therefore the function must be declared no longer as \c;\l;void\u cbot\void;\n; but as an other \l;type\u cbot\type;:
|
||||
\c;
|
||||
\s;float Average(float a, float b)
|
||||
\s;{
|
||||
\s; return (a+b)/2;
|
||||
\s;}
|
||||
|
@ -47,39 +80,51 @@ A function can also return a result with the \c;\l;return\u cbot\return;\n; inst
|
|||
\s;extern void object::Test( )
|
||||
\s;{
|
||||
\s; float value;
|
||||
\s; value = Mean(2, 6);
|
||||
\s; message( value ); // will display 4
|
||||
\s; value = Average(2, 6);
|
||||
\s; message(value); // will display 4
|
||||
\s;}
|
||||
\n;
|
||||
Some other examples¦:
|
||||
Some other examples:
|
||||
\c;
|
||||
\s;float Pi( )
|
||||
\s;float Pi()
|
||||
\s;{
|
||||
\s; return 3.1415;
|
||||
\s;}
|
||||
\s;
|
||||
\s;string Sign( float a )
|
||||
\s;string Sign(float a)
|
||||
\s;{
|
||||
\s; if ( a > 0 ) return "positive";
|
||||
\s; if ( a < 0 ) return "negative";
|
||||
\s; if (a > 0) return "positive";
|
||||
\s; if (a < 0) return "negative";
|
||||
\s; return "null";
|
||||
\s;}
|
||||
\n;
|
||||
You can declare several functions with the same name but different parameters¦:
|
||||
|
||||
\b;Overloading
|
||||
You can declare several functions with the same name but different parameters:
|
||||
\c;
|
||||
\s;float Pythagoras( float a, float b )
|
||||
\s;float Pythagoras(float a, float b)
|
||||
\s;{
|
||||
\s; return sqrt((a*a)+(b*b));
|
||||
\s;}
|
||||
\s;
|
||||
\s;float Pythagoras( float a, float b, float c )
|
||||
\s;float Pythagoras(float a, float b, float c)
|
||||
\s;{
|
||||
\s; return sqrt((a*a)+(b*b)+(c*c));
|
||||
\s;}
|
||||
\n;
|
||||
CBOT will call either the one or the other function depending on the paramteres passed.
|
||||
CBOT will call either the one or the other function depending on the parameters passed. They must be distinguishable, i.e. you can't declare two functions with the same name and parameter types in the exact same order, e.g. declaring \c;int Pythagoras(float b, float a)\n; will result in error. Note that result type does not matter.
|
||||
|
||||
\b;Public functions
|
||||
You can also declare a function \l;public\u cbot\public; so it can be used by other bots.
|
||||
|
||||
\b;object::
|
||||
Declaring a function as a part of the \l;object\u cbot\object; namespace gives it access to \c;\l;this\u cbot\this;\n; \l;pointer\u cbot\pointer;, in other words, to all available properties of the robot which the program is run on.
|
||||
\c;
|
||||
\s;void object::Example()
|
||||
\s;{
|
||||
\s; message(this.category);
|
||||
\s;}
|
||||
\n;
|
||||
|
||||
\t;See also
|
||||
\l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
|
||||
|
|
|
@ -53,13 +53,13 @@ msgid "Time in seconds."
|
|||
msgstr ""
|
||||
|
||||
#. type: \t; header
|
||||
#: ../E/abstime.txt:10 ../E/acos.txt:11 ../E/aim.txt:23 ../E/array.txt:30 ../E/asin.txt:11 ../E/atan.txt:11 ../E/atan2.txt:16 ../E/bloc.txt:48 ../E/bool.txt:4 ../E/break.txt:24 ../E/build.txt:27 ../E/buildingenabled.txt:22 ../E/canbuild.txt:22 ../E/category.txt:107 ../E/ceil.txt:12 ../E/class.txt:70 ../E/close.txt:6 ../E/cond.txt:27 ../E/continue.txt:24 ../E/cos.txt:11 ../E/deletef.txt:9 ../E/delinfo.txt:13 ../E/direct.txt:13 ../E/dist.txt:29 ../E/dist2d.txt:13 ../E/do.txt:27 ../E/drop.txt:28 ../E/eof.txt:13 ../E/errmode.txt:32 ../E/expr.txt:74 ../E/extern.txt:29 ../E/false.txt:4 ../E/file.txt:16 ../E/fire.txt:30 ../E/flatgrnd.txt:16 ../E/float.txt:24 ../E/floor.txt:12 ../E/for.txt:38 ../E/function.txt:84 ../E/goto.txt:34 ../E/grab.txt:28 ../E/if.txt:39 ../E/int.txt:18 ../E/jet.txt:14 ../E/message.txt:24 ../E/motor.txt:38 ../E/move.txt:21 ../E/nan.txt:14 ../E/new.txt:20 ../E/null.txt:4 ../E/object.txt:68 ../E/open.txt:18 ../E/openfile.txt:10 ../E/point.txt:35 ../E/pointer.txt:51 ../E/pow.txt:14 ../E/private.txt:17 ../E/public.txt:49 ../E/radar.txt:58 ../E/rand.txt:8 ../E/readln.txt:18 ../E/receive.txt:16 ../E/recycle.txt:12 ../E/retobj.txt:13 ../E/return.txt:29 ../E/round.txt:12 ../E/search.txt:16 ../E/send.txt:17 ../E/shield.txt:18 ../E/sin.txt:11 ../E/sizeof.txt:21 ../E/sniff.txt:16 ../E/space.txt:22 ../E/sqrt.txt:11 ../E/static.txt:20 ../E/strfind.txt:18 ../E/string.txt:32 ../E/strleft.txt:14 ../E/strlen.txt:12 ../E/strlower.txt:10 ../E/strmid.txt:18 ../E/strright.txt:14 ../E/strupper.txt:10 ../E/strval.txt:17 ../E/synchro.txt:23 ../E/tan.txt:11 ../E/term.txt:30 ../E/testinfo.txt:16 ../E/this.txt:52 ../E/thump.txt:12 ../E/topo.txt:13 ../E/true.txt:4 ../E/trunc.txt:12 ../E/turn.txt:32 ../E/type.txt:32 ../E/var.txt:66 ../E/void.txt:10 ../E/wait.txt:21 ../E/while.txt:46 ../E/writeln.txt:19
|
||||
#: ../E/abstime.txt:10 ../E/acos.txt:11 ../E/aim.txt:23 ../E/array.txt:30 ../E/asin.txt:11 ../E/atan.txt:11 ../E/atan2.txt:16 ../E/bloc.txt:48 ../E/bool.txt:4 ../E/break.txt:24 ../E/build.txt:27 ../E/buildingenabled.txt:22 ../E/canbuild.txt:22 ../E/category.txt:107 ../E/ceil.txt:12 ../E/class.txt:70 ../E/close.txt:6 ../E/cond.txt:27 ../E/continue.txt:24 ../E/cos.txt:11 ../E/deletef.txt:9 ../E/delinfo.txt:13 ../E/direct.txt:13 ../E/dist.txt:29 ../E/dist2d.txt:13 ../E/do.txt:27 ../E/drop.txt:28 ../E/eof.txt:13 ../E/errmode.txt:32 ../E/expr.txt:74 ../E/extern.txt:29 ../E/false.txt:4 ../E/file.txt:16 ../E/fire.txt:30 ../E/flatgrnd.txt:16 ../E/float.txt:24 ../E/floor.txt:12 ../E/for.txt:38 ../E/function.txt:129 ../E/goto.txt:34 ../E/grab.txt:28 ../E/if.txt:39 ../E/int.txt:18 ../E/jet.txt:14 ../E/message.txt:24 ../E/motor.txt:38 ../E/move.txt:21 ../E/nan.txt:14 ../E/new.txt:20 ../E/null.txt:4 ../E/object.txt:68 ../E/open.txt:18 ../E/openfile.txt:10 ../E/point.txt:35 ../E/pointer.txt:51 ../E/pow.txt:14 ../E/private.txt:17 ../E/public.txt:49 ../E/radar.txt:58 ../E/rand.txt:8 ../E/readln.txt:18 ../E/receive.txt:16 ../E/recycle.txt:12 ../E/retobj.txt:13 ../E/return.txt:29 ../E/round.txt:12 ../E/search.txt:16 ../E/send.txt:17 ../E/shield.txt:18 ../E/sin.txt:11 ../E/sizeof.txt:21 ../E/sniff.txt:16 ../E/space.txt:22 ../E/sqrt.txt:11 ../E/static.txt:20 ../E/strfind.txt:18 ../E/string.txt:32 ../E/strleft.txt:14 ../E/strlen.txt:12 ../E/strlower.txt:10 ../E/strmid.txt:18 ../E/strright.txt:14 ../E/strupper.txt:10 ../E/strval.txt:17 ../E/synchro.txt:23 ../E/tan.txt:11 ../E/term.txt:30 ../E/testinfo.txt:16 ../E/this.txt:52 ../E/thump.txt:12 ../E/topo.txt:13 ../E/true.txt:4 ../E/trunc.txt:12 ../E/turn.txt:32 ../E/type.txt:32 ../E/var.txt:66 ../E/void.txt:10 ../E/wait.txt:21 ../E/while.txt:46 ../E/writeln.txt:19
|
||||
#, no-wrap
|
||||
msgid "See also"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/abstime.txt:11 ../E/aim.txt:24 ../E/array.txt:31 ../E/bool.txt:5 ../E/break.txt:25 ../E/cond.txt:28 ../E/continue.txt:25 ../E/deletef.txt:10 ../E/direct.txt:14 ../E/dist.txt:30 ../E/dist2d.txt:14 ../E/drop.txt:29 ../E/errmode.txt:33 ../E/expr.txt:75 ../E/extern.txt:30 ../E/false.txt:5 ../E/fire.txt:31 ../E/flatgrnd.txt:17 ../E/float.txt:25 ../E/for.txt:39 ../E/function.txt:85 ../E/goto.txt:35 ../E/grab.txt:29 ../E/if.txt:40 ../E/int.txt:19 ../E/jet.txt:15 ../E/message.txt:25 ../E/move.txt:22 ../E/nan.txt:15 ../E/object.txt:69 ../E/openfile.txt:11 ../E/point.txt:36 ../E/radar.txt:59 ../E/recycle.txt:13 ../E/retobj.txt:14 ../E/return.txt:30 ../E/search.txt:17 ../E/shield.txt:19 ../E/sizeof.txt:22 ../E/sniff.txt:17 ../E/space.txt:23 ../E/string.txt:33 ../E/term.txt:31 ../E/thump.txt:13 ../E/topo.txt:14 ../E/true.txt:5 ../E/turn.txt:33 ../E/type.txt:33 ../E/var.txt:67 ../E/void.txt:11 ../E/wait.txt:22
|
||||
#: ../E/abstime.txt:11 ../E/aim.txt:24 ../E/array.txt:31 ../E/bool.txt:5 ../E/break.txt:25 ../E/cond.txt:28 ../E/continue.txt:25 ../E/deletef.txt:10 ../E/direct.txt:14 ../E/dist.txt:30 ../E/dist2d.txt:14 ../E/drop.txt:29 ../E/errmode.txt:33 ../E/expr.txt:75 ../E/extern.txt:30 ../E/false.txt:5 ../E/fire.txt:31 ../E/flatgrnd.txt:17 ../E/float.txt:25 ../E/for.txt:39 ../E/function.txt:130 ../E/goto.txt:35 ../E/grab.txt:29 ../E/if.txt:40 ../E/int.txt:19 ../E/jet.txt:15 ../E/message.txt:25 ../E/move.txt:22 ../E/nan.txt:15 ../E/object.txt:69 ../E/openfile.txt:11 ../E/point.txt:36 ../E/radar.txt:59 ../E/recycle.txt:13 ../E/retobj.txt:14 ../E/return.txt:30 ../E/search.txt:17 ../E/shield.txt:19 ../E/sizeof.txt:22 ../E/sniff.txt:17 ../E/space.txt:23 ../E/string.txt:33 ../E/term.txt:31 ../E/thump.txt:13 ../E/topo.txt:14 ../E/true.txt:5 ../E/turn.txt:33 ../E/type.txt:33 ../E/var.txt:67 ../E/void.txt:11 ../E/wait.txt:22
|
||||
#, no-wrap
|
||||
msgid "<a cbot>Programming</a>, <a cbot|type>types</a> and <a cbot|category>categories</a>."
|
||||
msgstr ""
|
||||
|
@ -958,7 +958,7 @@ msgid "With the instruction <code>distance( , )</code> you can calculate the dis
|
|||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/build.txt:4 ../E/buildingenabled.txt:4 ../E/canbuild.txt:4 ../E/dist.txt:4 ../E/drop.txt:4 ../E/fire.txt:4 ../E/goto.txt:4 ../E/grab.txt:4 ../E/if.txt:4 ../E/motor.txt:4 ../E/move.txt:4 ../E/radar.txt:4 ../E/turn.txt:4 ../E/wait.txt:4 ../E/while.txt:4
|
||||
#: ../E/build.txt:4 ../E/buildingenabled.txt:4 ../E/canbuild.txt:4 ../E/dist.txt:4 ../E/drop.txt:4 ../E/fire.txt:4 ../E/function.txt:16 ../E/goto.txt:4 ../E/grab.txt:4 ../E/if.txt:4 ../E/motor.txt:4 ../E/move.txt:4 ../E/radar.txt:4 ../E/turn.txt:4 ../E/wait.txt:4 ../E/while.txt:4
|
||||
#, no-wrap
|
||||
msgid "Basic use"
|
||||
msgstr ""
|
||||
|
@ -1871,153 +1871,7 @@ msgid "Functions"
|
|||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:2
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"With functions you can divide your program into several parts, each of them will execute a specific task.\n"
|
||||
"Let's imagine following program¦:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:5
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"extern void object::Remote( )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", 1, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 3, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 2, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 4, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:17
|
||||
#, no-wrap
|
||||
msgid "<code>send</code> and <code>wait</code> are repeated several times. So it would be a good thing if we created a function that executes these two instructions:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:19
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void object::SendToPost( float op )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", op, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}\n"
|
||||
"extern void object::Remote( )\n"
|
||||
"{\n"
|
||||
"\tSendToPost(1);\n"
|
||||
"\tSendToPost(3);\n"
|
||||
"\tSendToPost(2);\n"
|
||||
"\tSendToPost(4);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:32
|
||||
#, no-wrap
|
||||
msgid "A function can have paramteters¦:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:34
|
||||
#, no-wrap
|
||||
msgid "void Example( int a, float x, string s )"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:36
|
||||
#, no-wrap
|
||||
msgid "The <code>Example</code> function will reveive un integer <code>a</code>, a floating point number <code>x</code> and a string <code>s</code>. Parameters are \"passed by value\", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an <code>int</code> to a function, its parameter is a copy of whatever value was being passed as argument, and the function can change its parameter value without affecting values in the code that invoked the function."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:38
|
||||
#, no-wrap
|
||||
msgid "If you pass a <a cbot|class>class</a> instance or an <a cbot|array>array</a> as parameter to a function, the function only receives a <a cbot|pointer>reference</a> to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actuallay modified."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:40
|
||||
#, no-wrap
|
||||
msgid "A function can also return a result with the <code><a cbot|return>return</a></code> instruction. Therefore the function must be declared no longer as void but as a type:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:42
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Mean( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn (a+b)/2;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Test( )\n"
|
||||
"{\n"
|
||||
"\tfloat value;\n"
|
||||
"\tvalue = Mean(2, 6);\n"
|
||||
"\tmessage( value ); // will display 4\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:54
|
||||
#, no-wrap
|
||||
msgid "Some other examples¦:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:56
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pi( )\n"
|
||||
"{\n"
|
||||
"\treturn 3.1415;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"string Sign( float a )\n"
|
||||
"{\n"
|
||||
"\tif ( a > 0 ) return \"positive\";\n"
|
||||
"\tif ( a < 0 ) return \"negative\";\n"
|
||||
"\treturn \"null\";\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:68
|
||||
#, no-wrap
|
||||
msgid "You can declare several functions with the same name but different parameters¦:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:70
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pythagoras( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float Pythagoras( float a, float b, float c )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:80
|
||||
#, no-wrap
|
||||
msgid "CBOT will call either the one or the other function depending on the paramteres passed."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:82
|
||||
#: ../E/function.txt:118
|
||||
#, no-wrap
|
||||
msgid "You can also declare a function <a cbot|public>public</a> so it can be used by other bots."
|
||||
msgstr ""
|
||||
|
@ -6037,6 +5891,387 @@ msgstr ""
|
|||
msgid "x: <code><a cbot|float>float</a></code> (default value: <code>0</code>)"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:2
|
||||
#, no-wrap
|
||||
msgid "Function, simply put, is an instruction created by you."
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:4
|
||||
#, no-wrap
|
||||
msgid "Main function"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:5
|
||||
#, no-wrap
|
||||
msgid "You probably already know how to create a function. Every program in CBOT must have a main function, which looks like this:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:7
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"extern void object::ProgramName()\n"
|
||||
"{\n"
|
||||
"\t\n"
|
||||
"\t// instructions\n"
|
||||
"\t\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:14
|
||||
#, no-wrap
|
||||
msgid "Nothing but a name can be changed in a main function. The keyword <code>extern</code> distinguish the main function from others."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:17
|
||||
#, no-wrap
|
||||
msgid "With functions you can divide your program into several parts. Each of them will execute a specific task. For example, see the following program:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:19
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"extern void object::Remote()\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", 1, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 3, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 2, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 4, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:31
|
||||
#, no-wrap
|
||||
msgid "<code><a cbot|send>send</a></code> and <code><a cbot|wait>wait</a></code> are repeated several times. So it would be a good thing if we created a function that executes these two instructions:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:33
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void SendToPost(float op)\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", op, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Remote()\n"
|
||||
"{\n"
|
||||
"\tSendToPost(1);\n"
|
||||
"\tSendToPost(3);\n"
|
||||
"\tSendToPost(2);\n"
|
||||
"\tSendToPost(4);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:49
|
||||
#, no-wrap
|
||||
msgid "Syntax"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:56
|
||||
#, no-wrap
|
||||
msgid "A function must be declared above the main function. Result <a cbot|type>type</a> should be <a cbot/void>void</a> if the function does not give any. Body is just a set of instructions. Function name must be created with the exact same rules applied to <a cbot|var>variables</a>."
|
||||
msgstr ""
|
||||
|
||||
#. type: \t; header
|
||||
#: ../E/function.txt:58
|
||||
#, no-wrap
|
||||
msgid "Parameters"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:59
|
||||
#, no-wrap
|
||||
msgid "A function can have parameters:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:68
|
||||
#, no-wrap
|
||||
msgid "The <code>Example</code> function will receive an <a cbot|int>integer</a> <code>a</code>, a <a cbot|float>floating point number</a> <code>x</code> and a <a cbot|string>string</a> <code>s</code>. Parameters are \"passed by value\", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an <code><a cbot|int>int</a></code> to a function, its parameter is a copy of whatever value was being passed as the argument, and the function can change its parameter value without affecting values in the code that invoked the function."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:70
|
||||
#, no-wrap
|
||||
msgid "If you pass a <a cbot|class>class</a> instance or an <a cbot|array>array</a> as parameter to a function, the function only receives a <a cbot|pointer>reference</a> to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actually modified."
|
||||
msgstr ""
|
||||
|
||||
#. type: \t; header
|
||||
#: ../E/function.txt:72
|
||||
#, no-wrap
|
||||
msgid "Result"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:73
|
||||
#, no-wrap
|
||||
msgid "A function can also return a result with the <code><a cbot|return>return</a></code> instruction. Therefore the function must be declared no longer as <code><a cbot|void>void</a></code> but as an other <a cbot|type>type</a>:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:75
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Average(float a, float b)\n"
|
||||
"{\n"
|
||||
"\treturn (a+b)/2;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Test( )\n"
|
||||
"{\n"
|
||||
"\tfloat value;\n"
|
||||
"\tvalue = Average(2, 6);\n"
|
||||
"\tmessage(value); // will display 4\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:87
|
||||
#, no-wrap
|
||||
msgid "Some other examples:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:89
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pi()\n"
|
||||
"{\n"
|
||||
"\treturn 3.1415;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"string Sign(float a)\n"
|
||||
"{\n"
|
||||
"\tif (a > 0) return \"positive\";\n"
|
||||
"\tif (a < 0) return \"negative\";\n"
|
||||
"\treturn \"null\";\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:102
|
||||
#, no-wrap
|
||||
msgid "Overloading"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:103
|
||||
#, no-wrap
|
||||
msgid "You can declare several functions with the same name but different parameters:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:105
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pythagoras(float a, float b)\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float Pythagoras(float a, float b, float c)\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:115
|
||||
#, no-wrap
|
||||
msgid "CBOT will call either the one or the other function depending on the parameters passed. They must be distinguishable, i.e. you can't declare two functions with the same name and parameter types in the exact same order, e.g. declaring <code>int Pythagoras(float b, float a)</code> will result in error. Note that result type does not matter."
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:117
|
||||
#, no-wrap
|
||||
msgid "Public functions"
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:120
|
||||
#, no-wrap
|
||||
msgid "object::"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:121
|
||||
#, no-wrap
|
||||
msgid "Declaring a function as a part of the <a cbot|object>object</a> namespace gives it access to <code><a cbot|this>this</a></code> <a cbot|pointer>pointer</a>, in other words, to all available properties of the robot which the program is run on."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:47
|
||||
#, no-wrap
|
||||
msgid "Now the program is much easier to read. It is a good practice to split the program into several functions with self-describing names."
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:51
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"result_type FunctionName(optional_parameters)\n"
|
||||
"{\n"
|
||||
"\tbody\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:61
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void Example(int a, float x, string s)\n"
|
||||
"{\n"
|
||||
"\tmessage(a);\n"
|
||||
"\tmessage(x);\n"
|
||||
"\tmessage(s);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:123
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void object::Example()\n"
|
||||
"{\n"
|
||||
"\tmessage(this.category);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#~ msgid "Now the program is much easier to read. It's a good practice to split the program into several functions with self-describing names."
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "result_type FunctionName(optional_parameters)\n"
|
||||
#~ "{\n"
|
||||
#~ " body\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "void Example(int a, float x, string s)\n"
|
||||
#~ "{\n"
|
||||
#~ " message(a);\n"
|
||||
#~ " message(x);\n"
|
||||
#~ " message(s);\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "With functions you can divide your program into several parts, each of them will execute a specific task.\n"
|
||||
#~ "Let's imagine following program¦:"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "extern void object::Remote( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", 1, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 3, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 2, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 4, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid "<code>send</code> and <code>wait</code> are repeated several times. So it would be a good thing if we created a function that executes these two instructions:"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "void object::SendToPost( float op )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", op, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}\n"
|
||||
#~ "extern void object::Remote( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tSendToPost(1);\n"
|
||||
#~ "\tSendToPost(3);\n"
|
||||
#~ "\tSendToPost(2);\n"
|
||||
#~ "\tSendToPost(4);\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid "A function can have paramteters¦:"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid "void Example( int a, float x, string s )"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid "The <code>Example</code> function will reveive un integer <code>a</code>, a floating point number <code>x</code> and a string <code>s</code>. Parameters are \"passed by value\", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an <code>int</code> to a function, its parameter is a copy of whatever value was being passed as argument, and the function can change its parameter value without affecting values in the code that invoked the function."
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid "If you pass a <a cbot|class>class</a> instance or an <a cbot|array>array</a> as parameter to a function, the function only receives a <a cbot|pointer>reference</a> to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actuallay modified."
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid "A function can also return a result with the <code><a cbot|return>return</a></code> instruction. Therefore the function must be declared no longer as void but as a type:"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "float Mean( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn (a+b)/2;\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "extern void object::Test( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tfloat value;\n"
|
||||
#~ "\tvalue = Mean(2, 6);\n"
|
||||
#~ "\tmessage( value ); // will display 4\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid "Some other examples¦:"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "float Pi( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn 3.1415;\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "string Sign( float a )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tif ( a > 0 ) return \"positive\";\n"
|
||||
#~ "\tif ( a < 0 ) return \"negative\";\n"
|
||||
#~ "\treturn \"null\";\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid "You can declare several functions with the same name but different parameters¦:"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "float Pythagoras( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b));\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "float Pythagoras( float a, float b, float c )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid "CBOT will call either the one or the other function depending on the paramteres passed."
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid "x: <code><a cbot|float>float</a></code> (default value: <code>0</code>);"
|
||||
#~ msgstr ""
|
||||
|
||||
|
|
|
@ -53,13 +53,13 @@ msgid "Time in seconds."
|
|||
msgstr "Zeit in Sekunden."
|
||||
|
||||
#. type: \t; header
|
||||
#: ../E/abstime.txt:10 ../E/acos.txt:11 ../E/aim.txt:23 ../E/array.txt:30 ../E/asin.txt:11 ../E/atan.txt:11 ../E/atan2.txt:16 ../E/bloc.txt:48 ../E/bool.txt:4 ../E/break.txt:24 ../E/build.txt:27 ../E/buildingenabled.txt:22 ../E/canbuild.txt:22 ../E/category.txt:107 ../E/ceil.txt:12 ../E/class.txt:70 ../E/close.txt:6 ../E/cond.txt:27 ../E/continue.txt:24 ../E/cos.txt:11 ../E/deletef.txt:9 ../E/delinfo.txt:13 ../E/direct.txt:13 ../E/dist.txt:29 ../E/dist2d.txt:13 ../E/do.txt:27 ../E/drop.txt:28 ../E/eof.txt:13 ../E/errmode.txt:32 ../E/expr.txt:74 ../E/extern.txt:29 ../E/false.txt:4 ../E/file.txt:16 ../E/fire.txt:30 ../E/flatgrnd.txt:16 ../E/float.txt:24 ../E/floor.txt:12 ../E/for.txt:38 ../E/function.txt:84 ../E/goto.txt:34 ../E/grab.txt:28 ../E/if.txt:39 ../E/int.txt:18 ../E/jet.txt:14 ../E/message.txt:24 ../E/motor.txt:38 ../E/move.txt:21 ../E/nan.txt:14 ../E/new.txt:20 ../E/null.txt:4 ../E/object.txt:68 ../E/open.txt:18 ../E/openfile.txt:10 ../E/point.txt:35 ../E/pointer.txt:51 ../E/pow.txt:14 ../E/private.txt:17 ../E/public.txt:49 ../E/radar.txt:58 ../E/rand.txt:8 ../E/readln.txt:18 ../E/receive.txt:16 ../E/recycle.txt:12 ../E/retobj.txt:13 ../E/return.txt:29 ../E/round.txt:12 ../E/search.txt:16 ../E/send.txt:17 ../E/shield.txt:18 ../E/sin.txt:11 ../E/sizeof.txt:21 ../E/sniff.txt:16 ../E/space.txt:22 ../E/sqrt.txt:11 ../E/static.txt:20 ../E/strfind.txt:18 ../E/string.txt:32 ../E/strleft.txt:14 ../E/strlen.txt:12 ../E/strlower.txt:10 ../E/strmid.txt:18 ../E/strright.txt:14 ../E/strupper.txt:10 ../E/strval.txt:17 ../E/synchro.txt:23 ../E/tan.txt:11 ../E/term.txt:30 ../E/testinfo.txt:16 ../E/this.txt:52 ../E/thump.txt:12 ../E/topo.txt:13 ../E/true.txt:4 ../E/trunc.txt:12 ../E/turn.txt:32 ../E/type.txt:32 ../E/var.txt:66 ../E/void.txt:10 ../E/wait.txt:21 ../E/while.txt:46 ../E/writeln.txt:19
|
||||
#: ../E/abstime.txt:10 ../E/acos.txt:11 ../E/aim.txt:23 ../E/array.txt:30 ../E/asin.txt:11 ../E/atan.txt:11 ../E/atan2.txt:16 ../E/bloc.txt:48 ../E/bool.txt:4 ../E/break.txt:24 ../E/build.txt:27 ../E/buildingenabled.txt:22 ../E/canbuild.txt:22 ../E/category.txt:107 ../E/ceil.txt:12 ../E/class.txt:70 ../E/close.txt:6 ../E/cond.txt:27 ../E/continue.txt:24 ../E/cos.txt:11 ../E/deletef.txt:9 ../E/delinfo.txt:13 ../E/direct.txt:13 ../E/dist.txt:29 ../E/dist2d.txt:13 ../E/do.txt:27 ../E/drop.txt:28 ../E/eof.txt:13 ../E/errmode.txt:32 ../E/expr.txt:74 ../E/extern.txt:29 ../E/false.txt:4 ../E/file.txt:16 ../E/fire.txt:30 ../E/flatgrnd.txt:16 ../E/float.txt:24 ../E/floor.txt:12 ../E/for.txt:38 ../E/function.txt:129 ../E/goto.txt:34 ../E/grab.txt:28 ../E/if.txt:39 ../E/int.txt:18 ../E/jet.txt:14 ../E/message.txt:24 ../E/motor.txt:38 ../E/move.txt:21 ../E/nan.txt:14 ../E/new.txt:20 ../E/null.txt:4 ../E/object.txt:68 ../E/open.txt:18 ../E/openfile.txt:10 ../E/point.txt:35 ../E/pointer.txt:51 ../E/pow.txt:14 ../E/private.txt:17 ../E/public.txt:49 ../E/radar.txt:58 ../E/rand.txt:8 ../E/readln.txt:18 ../E/receive.txt:16 ../E/recycle.txt:12 ../E/retobj.txt:13 ../E/return.txt:29 ../E/round.txt:12 ../E/search.txt:16 ../E/send.txt:17 ../E/shield.txt:18 ../E/sin.txt:11 ../E/sizeof.txt:21 ../E/sniff.txt:16 ../E/space.txt:22 ../E/sqrt.txt:11 ../E/static.txt:20 ../E/strfind.txt:18 ../E/string.txt:32 ../E/strleft.txt:14 ../E/strlen.txt:12 ../E/strlower.txt:10 ../E/strmid.txt:18 ../E/strright.txt:14 ../E/strupper.txt:10 ../E/strval.txt:17 ../E/synchro.txt:23 ../E/tan.txt:11 ../E/term.txt:30 ../E/testinfo.txt:16 ../E/this.txt:52 ../E/thump.txt:12 ../E/topo.txt:13 ../E/true.txt:4 ../E/trunc.txt:12 ../E/turn.txt:32 ../E/type.txt:32 ../E/var.txt:66 ../E/void.txt:10 ../E/wait.txt:21 ../E/while.txt:46 ../E/writeln.txt:19
|
||||
#, no-wrap
|
||||
msgid "See also"
|
||||
msgstr "Siehe auch"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/abstime.txt:11 ../E/aim.txt:24 ../E/array.txt:31 ../E/bool.txt:5 ../E/break.txt:25 ../E/cond.txt:28 ../E/continue.txt:25 ../E/deletef.txt:10 ../E/direct.txt:14 ../E/dist.txt:30 ../E/dist2d.txt:14 ../E/drop.txt:29 ../E/errmode.txt:33 ../E/expr.txt:75 ../E/extern.txt:30 ../E/false.txt:5 ../E/fire.txt:31 ../E/flatgrnd.txt:17 ../E/float.txt:25 ../E/for.txt:39 ../E/function.txt:85 ../E/goto.txt:35 ../E/grab.txt:29 ../E/if.txt:40 ../E/int.txt:19 ../E/jet.txt:15 ../E/message.txt:25 ../E/move.txt:22 ../E/nan.txt:15 ../E/object.txt:69 ../E/openfile.txt:11 ../E/point.txt:36 ../E/radar.txt:59 ../E/recycle.txt:13 ../E/retobj.txt:14 ../E/return.txt:30 ../E/search.txt:17 ../E/shield.txt:19 ../E/sizeof.txt:22 ../E/sniff.txt:17 ../E/space.txt:23 ../E/string.txt:33 ../E/term.txt:31 ../E/thump.txt:13 ../E/topo.txt:14 ../E/true.txt:5 ../E/turn.txt:33 ../E/type.txt:33 ../E/var.txt:67 ../E/void.txt:11 ../E/wait.txt:22
|
||||
#: ../E/abstime.txt:11 ../E/aim.txt:24 ../E/array.txt:31 ../E/bool.txt:5 ../E/break.txt:25 ../E/cond.txt:28 ../E/continue.txt:25 ../E/deletef.txt:10 ../E/direct.txt:14 ../E/dist.txt:30 ../E/dist2d.txt:14 ../E/drop.txt:29 ../E/errmode.txt:33 ../E/expr.txt:75 ../E/extern.txt:30 ../E/false.txt:5 ../E/fire.txt:31 ../E/flatgrnd.txt:17 ../E/float.txt:25 ../E/for.txt:39 ../E/function.txt:130 ../E/goto.txt:35 ../E/grab.txt:29 ../E/if.txt:40 ../E/int.txt:19 ../E/jet.txt:15 ../E/message.txt:25 ../E/move.txt:22 ../E/nan.txt:15 ../E/object.txt:69 ../E/openfile.txt:11 ../E/point.txt:36 ../E/radar.txt:59 ../E/recycle.txt:13 ../E/retobj.txt:14 ../E/return.txt:30 ../E/search.txt:17 ../E/shield.txt:19 ../E/sizeof.txt:22 ../E/sniff.txt:17 ../E/space.txt:23 ../E/string.txt:33 ../E/term.txt:31 ../E/thump.txt:13 ../E/topo.txt:14 ../E/true.txt:5 ../E/turn.txt:33 ../E/type.txt:33 ../E/var.txt:67 ../E/void.txt:11 ../E/wait.txt:22
|
||||
#, no-wrap
|
||||
msgid "<a cbot>Programming</a>, <a cbot|type>types</a> and <a cbot|category>categories</a>."
|
||||
msgstr "Die <a cbot>CBOT-Sprache</a>, <a cbot|type>Variablentypen</a> und <a cbot|category>Kategorien</a>."
|
||||
|
@ -1129,7 +1129,7 @@ msgid "With the instruction <code>distance( , )</code> you can calculate the dis
|
|||
msgstr "Mit der Anweisung <code>distance( , )</code> können Sie die Distanz zwischen zwei Positionen berechnen."
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/build.txt:4 ../E/buildingenabled.txt:4 ../E/canbuild.txt:4 ../E/dist.txt:4 ../E/drop.txt:4 ../E/fire.txt:4 ../E/goto.txt:4 ../E/grab.txt:4 ../E/if.txt:4 ../E/motor.txt:4 ../E/move.txt:4 ../E/radar.txt:4 ../E/turn.txt:4 ../E/wait.txt:4 ../E/while.txt:4
|
||||
#: ../E/build.txt:4 ../E/buildingenabled.txt:4 ../E/canbuild.txt:4 ../E/dist.txt:4 ../E/drop.txt:4 ../E/fire.txt:4 ../E/function.txt:16 ../E/goto.txt:4 ../E/grab.txt:4 ../E/if.txt:4 ../E/motor.txt:4 ../E/move.txt:4 ../E/radar.txt:4 ../E/turn.txt:4 ../E/wait.txt:4 ../E/while.txt:4
|
||||
#, no-wrap
|
||||
msgid "Basic use"
|
||||
msgstr "Grundlagen"
|
||||
|
@ -2181,207 +2181,7 @@ msgid "Functions"
|
|||
msgstr "Funktionen"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:2
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"With functions you can divide your program into several parts, each of them will execute a specific task.\n"
|
||||
"Let's imagine following program¦:"
|
||||
msgstr "Mit Funktionen können Sie Ihr Programm in mehrere Abschnitte unterteilen, von denen jeder eine bestimmte Aufgabe hat. Nehmen wir folgendes Programm:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:5
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"extern void object::Remote( )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", 1, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 3, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 2, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 4, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"extern void object::Remote( )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", 1, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 3, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 2, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 4, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:17
|
||||
#, no-wrap
|
||||
msgid "<code>send</code> and <code>wait</code> are repeated several times. So it would be a good thing if we created a function that executes these two instructions:"
|
||||
msgstr "Die Anweisungen <code>send</code> und<code>wait</code> werden mehrere Male wiederholt. Es ist deshalb zweckmäßig, eine Funktion zu erstellen, die diese Anweisungen ausführt:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:19
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void object::SendToPost( float op )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", op, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}\n"
|
||||
"extern void object::Remote( )\n"
|
||||
"{\n"
|
||||
"\tSendToPost(1);\n"
|
||||
"\tSendToPost(3);\n"
|
||||
"\tSendToPost(2);\n"
|
||||
"\tSendToPost(4);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"void object::SendToPost( float op )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", op, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}\n"
|
||||
"extern void object::Remote( )\n"
|
||||
"{\n"
|
||||
"\tSendToPost(1);\n"
|
||||
"\tSendToPost(3);\n"
|
||||
"\tSendToPost(2);\n"
|
||||
"\tSendToPost(4);\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:32
|
||||
#, no-wrap
|
||||
msgid "A function can have paramteters¦:"
|
||||
msgstr "Eine Funktion kann mehrere Parameter erhalten:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:34
|
||||
#, no-wrap
|
||||
msgid "void Example( int a, float x, string s )"
|
||||
msgstr "void Beispiel( int a, float x, string s )"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:36
|
||||
#, no-wrap
|
||||
msgid "The <code>Example</code> function will reveive un integer <code>a</code>, a floating point number <code>x</code> and a string <code>s</code>. Parameters are \"passed by value\", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an <code>int</code> to a function, its parameter is a copy of whatever value was being passed as argument, and the function can change its parameter value without affecting values in the code that invoked the function."
|
||||
msgstr "Die Funktion <code>Beispiel</code> erhält folgende Parameter: einen Wert vom Typ <code>int</code> (ganze Zahl), der in die Variable<code>a</code> kommt; einen Wert vom Typ <code>float</code> (Fließkommazahl), der in die Variable <code>x</code> kommt, und einen Wert vom Typ <code>string</code> (Zeichenkette), der in die Variable <code>s</code> kommt."
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:38
|
||||
#, no-wrap
|
||||
msgid "If you pass a <a cbot|class>class</a> instance or an <a cbot|array>array</a> as parameter to a function, the function only receives a <a cbot|pointer>reference</a> to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actuallay modified."
|
||||
msgstr "Wenn Sie hingegen eine Instanz einer <a cbot|class>Klasse</a> oder ein <a cbot|Array>array</a> als Parameter übergeben, erhält die Funktion nur einen \\l;Zeiger\\u cbot\\pointer; auf die Instanz oder das Array. Wenn der Inhalt der Instanz oder des Arrays verändert wird, wirkt sich das auch auf die Funktion aus, die den Parameter übergeben hat."
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:40
|
||||
#, no-wrap
|
||||
msgid "A function can also return a result with the <code><a cbot|return>return</a></code> instruction. Therefore the function must be declared no longer as void but as a type:"
|
||||
msgstr "Mit der Anweisung <code><a cbot|return>return</a></code> kann die Funktion auch ein Ergebnis zurückgeben. In diesem Fall muss der Typ der Rückgabe anstelle des Typs \\c;\\l;void\\u cbot\\void;\\n; bei der Deklaration der Funktion (erste Zeile) angegeben werden:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:42
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Mean( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn (a+b)/2;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Test( )\n"
|
||||
"{\n"
|
||||
"\tfloat value;\n"
|
||||
"\tvalue = Mean(2, 6);\n"
|
||||
"\tmessage( value ); // will display 4\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"float Mittel( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn (a+b)/2;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Test( )\n"
|
||||
"{\n"
|
||||
"\tfloat value;\n"
|
||||
"\tvalue = Mittel(2, 6);\n"
|
||||
"\tmessage( value ); // wird 4 anzeigen\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:54
|
||||
#, no-wrap
|
||||
msgid "Some other examples¦:"
|
||||
msgstr "Hier sind ein paar weitere Beispiele:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:56
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pi( )\n"
|
||||
"{\n"
|
||||
"\treturn 3.1415;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"string Sign( float a )\n"
|
||||
"{\n"
|
||||
"\tif ( a > 0 ) return \"positive\";\n"
|
||||
"\tif ( a < 0 ) return \"negative\";\n"
|
||||
"\treturn \"null\";\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"float Pi( )\n"
|
||||
"{\n"
|
||||
"\treturn 3.1415;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"string Sign( float a )\n"
|
||||
"{\n"
|
||||
"\tif ( a > 0 ) return \"positiv\";\n"
|
||||
"\tif ( a < 0 ) return \"negativ\";\n"
|
||||
"\treturn \"null\";\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:68
|
||||
#, no-wrap
|
||||
msgid "You can declare several functions with the same name but different parameters¦:"
|
||||
msgstr "Sie können mehrere Funktionen mit dem gleichen Namen, aber mit verschiedenen Parametern definieren:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:70
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pythagoras( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float Pythagoras( float a, float b, float c )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"float Pythagoras( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float Pythagoras( float a, float b, float c )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:80
|
||||
#, no-wrap
|
||||
msgid "CBOT will call either the one or the other function depending on the paramteres passed."
|
||||
msgstr "CBOT wird die eine oder andere Funktion aufrufen, je nach den gegebenen Parametern."
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:82
|
||||
#: ../E/function.txt:118
|
||||
#, no-wrap
|
||||
msgid "You can also declare a function <a cbot|public>public</a> so it can be used by other bots."
|
||||
msgstr "Sie können auch eine \"öffentliche\" Funktion mit dem Schlüsselwort <a cbot|public>public</a> deklarieren, so dass sie von anderen Robotern aus aufgerufen werden kann."
|
||||
|
@ -6926,6 +6726,441 @@ msgstr ""
|
|||
msgid "x: <code><a cbot|float>float</a></code> (default value: <code>0</code>)"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:2
|
||||
#, no-wrap
|
||||
msgid "Function, simply put, is an instruction created by you."
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:4
|
||||
#, no-wrap
|
||||
msgid "Main function"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:5
|
||||
#, no-wrap
|
||||
msgid "You probably already know how to create a function. Every program in CBOT must have a main function, which looks like this:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:7
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"extern void object::ProgramName()\n"
|
||||
"{\n"
|
||||
"\t\n"
|
||||
"\t// instructions\n"
|
||||
"\t\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:14
|
||||
#, no-wrap
|
||||
msgid "Nothing but a name can be changed in a main function. The keyword <code>extern</code> distinguish the main function from others."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:17
|
||||
#, no-wrap
|
||||
msgid "With functions you can divide your program into several parts. Each of them will execute a specific task. For example, see the following program:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:19
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"extern void object::Remote()\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", 1, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 3, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 2, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 4, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:31
|
||||
#, no-wrap
|
||||
msgid "<code><a cbot|send>send</a></code> and <code><a cbot|wait>wait</a></code> are repeated several times. So it would be a good thing if we created a function that executes these two instructions:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:33
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void SendToPost(float op)\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", op, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Remote()\n"
|
||||
"{\n"
|
||||
"\tSendToPost(1);\n"
|
||||
"\tSendToPost(3);\n"
|
||||
"\tSendToPost(2);\n"
|
||||
"\tSendToPost(4);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:49
|
||||
#, no-wrap
|
||||
msgid "Syntax"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:56
|
||||
#, no-wrap
|
||||
msgid "A function must be declared above the main function. Result <a cbot|type>type</a> should be <a cbot/void>void</a> if the function does not give any. Body is just a set of instructions. Function name must be created with the exact same rules applied to <a cbot|var>variables</a>."
|
||||
msgstr ""
|
||||
|
||||
#. type: \t; header
|
||||
#: ../E/function.txt:58
|
||||
#, no-wrap
|
||||
msgid "Parameters"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:59
|
||||
#, no-wrap
|
||||
msgid "A function can have parameters:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:68
|
||||
#, no-wrap
|
||||
msgid "The <code>Example</code> function will receive an <a cbot|int>integer</a> <code>a</code>, a <a cbot|float>floating point number</a> <code>x</code> and a <a cbot|string>string</a> <code>s</code>. Parameters are \"passed by value\", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an <code><a cbot|int>int</a></code> to a function, its parameter is a copy of whatever value was being passed as the argument, and the function can change its parameter value without affecting values in the code that invoked the function."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:70
|
||||
#, no-wrap
|
||||
msgid "If you pass a <a cbot|class>class</a> instance or an <a cbot|array>array</a> as parameter to a function, the function only receives a <a cbot|pointer>reference</a> to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actually modified."
|
||||
msgstr ""
|
||||
|
||||
#. type: \t; header
|
||||
#: ../E/function.txt:72
|
||||
#, no-wrap
|
||||
msgid "Result"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:73
|
||||
#, no-wrap
|
||||
msgid "A function can also return a result with the <code><a cbot|return>return</a></code> instruction. Therefore the function must be declared no longer as <code><a cbot|void>void</a></code> but as an other <a cbot|type>type</a>:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:75
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Average(float a, float b)\n"
|
||||
"{\n"
|
||||
"\treturn (a+b)/2;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Test( )\n"
|
||||
"{\n"
|
||||
"\tfloat value;\n"
|
||||
"\tvalue = Average(2, 6);\n"
|
||||
"\tmessage(value); // will display 4\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:87
|
||||
#, no-wrap
|
||||
msgid "Some other examples:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:89
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pi()\n"
|
||||
"{\n"
|
||||
"\treturn 3.1415;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"string Sign(float a)\n"
|
||||
"{\n"
|
||||
"\tif (a > 0) return \"positive\";\n"
|
||||
"\tif (a < 0) return \"negative\";\n"
|
||||
"\treturn \"null\";\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:102
|
||||
#, no-wrap
|
||||
msgid "Overloading"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:103
|
||||
#, no-wrap
|
||||
msgid "You can declare several functions with the same name but different parameters:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:105
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pythagoras(float a, float b)\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float Pythagoras(float a, float b, float c)\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:115
|
||||
#, no-wrap
|
||||
msgid "CBOT will call either the one or the other function depending on the parameters passed. They must be distinguishable, i.e. you can't declare two functions with the same name and parameter types in the exact same order, e.g. declaring <code>int Pythagoras(float b, float a)</code> will result in error. Note that result type does not matter."
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:117
|
||||
#, no-wrap
|
||||
msgid "Public functions"
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:120
|
||||
#, no-wrap
|
||||
msgid "object::"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:121
|
||||
#, no-wrap
|
||||
msgid "Declaring a function as a part of the <a cbot|object>object</a> namespace gives it access to <code><a cbot|this>this</a></code> <a cbot|pointer>pointer</a>, in other words, to all available properties of the robot which the program is run on."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:47
|
||||
#, no-wrap
|
||||
msgid "Now the program is much easier to read. It is a good practice to split the program into several functions with self-describing names."
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:51
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"result_type FunctionName(optional_parameters)\n"
|
||||
"{\n"
|
||||
"\tbody\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:61
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void Example(int a, float x, string s)\n"
|
||||
"{\n"
|
||||
"\tmessage(a);\n"
|
||||
"\tmessage(x);\n"
|
||||
"\tmessage(s);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:123
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void object::Example()\n"
|
||||
"{\n"
|
||||
"\tmessage(this.category);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#~ msgid "Now the program is much easier to read. It's a good practice to split the program into several functions with self-describing names."
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "result_type FunctionName(optional_parameters)\n"
|
||||
#~ "{\n"
|
||||
#~ " body\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "void Example(int a, float x, string s)\n"
|
||||
#~ "{\n"
|
||||
#~ " message(a);\n"
|
||||
#~ " message(x);\n"
|
||||
#~ " message(s);\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "With functions you can divide your program into several parts, each of them will execute a specific task.\n"
|
||||
#~ "Let's imagine following program¦:"
|
||||
#~ msgstr "Mit Funktionen können Sie Ihr Programm in mehrere Abschnitte unterteilen, von denen jeder eine bestimmte Aufgabe hat. Nehmen wir folgendes Programm:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "extern void object::Remote( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", 1, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 3, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 2, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 4, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "extern void object::Remote( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", 1, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 3, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 2, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 4, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "<code>send</code> and <code>wait</code> are repeated several times. So it would be a good thing if we created a function that executes these two instructions:"
|
||||
#~ msgstr "Die Anweisungen <code>send</code> und<code>wait</code> werden mehrere Male wiederholt. Es ist deshalb zweckmäßig, eine Funktion zu erstellen, die diese Anweisungen ausführt:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "void object::SendToPost( float op )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", op, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}\n"
|
||||
#~ "extern void object::Remote( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tSendToPost(1);\n"
|
||||
#~ "\tSendToPost(3);\n"
|
||||
#~ "\tSendToPost(2);\n"
|
||||
#~ "\tSendToPost(4);\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "void object::SendToPost( float op )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", op, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}\n"
|
||||
#~ "extern void object::Remote( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tSendToPost(1);\n"
|
||||
#~ "\tSendToPost(3);\n"
|
||||
#~ "\tSendToPost(2);\n"
|
||||
#~ "\tSendToPost(4);\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "A function can have paramteters¦:"
|
||||
#~ msgstr "Eine Funktion kann mehrere Parameter erhalten:"
|
||||
|
||||
#~ msgid "void Example( int a, float x, string s )"
|
||||
#~ msgstr "void Beispiel( int a, float x, string s )"
|
||||
|
||||
#~ msgid "The <code>Example</code> function will reveive un integer <code>a</code>, a floating point number <code>x</code> and a string <code>s</code>. Parameters are \"passed by value\", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an <code>int</code> to a function, its parameter is a copy of whatever value was being passed as argument, and the function can change its parameter value without affecting values in the code that invoked the function."
|
||||
#~ msgstr "Die Funktion <code>Beispiel</code> erhält folgende Parameter: einen Wert vom Typ <code>int</code> (ganze Zahl), der in die Variable<code>a</code> kommt; einen Wert vom Typ <code>float</code> (Fließkommazahl), der in die Variable <code>x</code> kommt, und einen Wert vom Typ <code>string</code> (Zeichenkette), der in die Variable <code>s</code> kommt."
|
||||
|
||||
#~ msgid "If you pass a <a cbot|class>class</a> instance or an <a cbot|array>array</a> as parameter to a function, the function only receives a <a cbot|pointer>reference</a> to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actuallay modified."
|
||||
#~ msgstr "Wenn Sie hingegen eine Instanz einer <a cbot|class>Klasse</a> oder ein <a cbot|Array>array</a> als Parameter übergeben, erhält die Funktion nur einen \\l;Zeiger\\u cbot\\pointer; auf die Instanz oder das Array. Wenn der Inhalt der Instanz oder des Arrays verändert wird, wirkt sich das auch auf die Funktion aus, die den Parameter übergeben hat."
|
||||
|
||||
#~ msgid "A function can also return a result with the <code><a cbot|return>return</a></code> instruction. Therefore the function must be declared no longer as void but as a type:"
|
||||
#~ msgstr "Mit der Anweisung <code><a cbot|return>return</a></code> kann die Funktion auch ein Ergebnis zurückgeben. In diesem Fall muss der Typ der Rückgabe anstelle des Typs \\c;\\l;void\\u cbot\\void;\\n; bei der Deklaration der Funktion (erste Zeile) angegeben werden:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "float Mean( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn (a+b)/2;\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "extern void object::Test( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tfloat value;\n"
|
||||
#~ "\tvalue = Mean(2, 6);\n"
|
||||
#~ "\tmessage( value ); // will display 4\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "float Mittel( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn (a+b)/2;\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "extern void object::Test( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tfloat value;\n"
|
||||
#~ "\tvalue = Mittel(2, 6);\n"
|
||||
#~ "\tmessage( value ); // wird 4 anzeigen\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "Some other examples¦:"
|
||||
#~ msgstr "Hier sind ein paar weitere Beispiele:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "float Pi( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn 3.1415;\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "string Sign( float a )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tif ( a > 0 ) return \"positive\";\n"
|
||||
#~ "\tif ( a < 0 ) return \"negative\";\n"
|
||||
#~ "\treturn \"null\";\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "float Pi( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn 3.1415;\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "string Sign( float a )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tif ( a > 0 ) return \"positiv\";\n"
|
||||
#~ "\tif ( a < 0 ) return \"negativ\";\n"
|
||||
#~ "\treturn \"null\";\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "You can declare several functions with the same name but different parameters¦:"
|
||||
#~ msgstr "Sie können mehrere Funktionen mit dem gleichen Namen, aber mit verschiedenen Parametern definieren:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "float Pythagoras( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b));\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "float Pythagoras( float a, float b, float c )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "float Pythagoras( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b));\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "float Pythagoras( float a, float b, float c )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "CBOT will call either the one or the other function depending on the paramteres passed."
|
||||
#~ msgstr "CBOT wird die eine oder andere Funktion aufrufen, je nach den gegebenen Parametern."
|
||||
|
||||
#~ msgid "x: <code><a cbot|float>float</a></code> (default value: <code>0</code>);"
|
||||
#~ msgstr ""
|
||||
|
||||
|
|
|
@ -53,13 +53,13 @@ msgid "Time in seconds."
|
|||
msgstr "Temps en secondes."
|
||||
|
||||
#. type: \t; header
|
||||
#: ../E/abstime.txt:10 ../E/acos.txt:11 ../E/aim.txt:23 ../E/array.txt:30 ../E/asin.txt:11 ../E/atan.txt:11 ../E/atan2.txt:16 ../E/bloc.txt:48 ../E/bool.txt:4 ../E/break.txt:24 ../E/build.txt:27 ../E/buildingenabled.txt:22 ../E/canbuild.txt:22 ../E/category.txt:107 ../E/ceil.txt:12 ../E/class.txt:70 ../E/close.txt:6 ../E/cond.txt:27 ../E/continue.txt:24 ../E/cos.txt:11 ../E/deletef.txt:9 ../E/delinfo.txt:13 ../E/direct.txt:13 ../E/dist.txt:29 ../E/dist2d.txt:13 ../E/do.txt:27 ../E/drop.txt:28 ../E/eof.txt:13 ../E/errmode.txt:32 ../E/expr.txt:74 ../E/extern.txt:29 ../E/false.txt:4 ../E/file.txt:16 ../E/fire.txt:30 ../E/flatgrnd.txt:16 ../E/float.txt:24 ../E/floor.txt:12 ../E/for.txt:38 ../E/function.txt:84 ../E/goto.txt:34 ../E/grab.txt:28 ../E/if.txt:39 ../E/int.txt:18 ../E/jet.txt:14 ../E/message.txt:24 ../E/motor.txt:38 ../E/move.txt:21 ../E/nan.txt:14 ../E/new.txt:20 ../E/null.txt:4 ../E/object.txt:68 ../E/open.txt:18 ../E/openfile.txt:10 ../E/point.txt:35 ../E/pointer.txt:51 ../E/pow.txt:14 ../E/private.txt:17 ../E/public.txt:49 ../E/radar.txt:58 ../E/rand.txt:8 ../E/readln.txt:18 ../E/receive.txt:16 ../E/recycle.txt:12 ../E/retobj.txt:13 ../E/return.txt:29 ../E/round.txt:12 ../E/search.txt:16 ../E/send.txt:17 ../E/shield.txt:18 ../E/sin.txt:11 ../E/sizeof.txt:21 ../E/sniff.txt:16 ../E/space.txt:22 ../E/sqrt.txt:11 ../E/static.txt:20 ../E/strfind.txt:18 ../E/string.txt:32 ../E/strleft.txt:14 ../E/strlen.txt:12 ../E/strlower.txt:10 ../E/strmid.txt:18 ../E/strright.txt:14 ../E/strupper.txt:10 ../E/strval.txt:17 ../E/synchro.txt:23 ../E/tan.txt:11 ../E/term.txt:30 ../E/testinfo.txt:16 ../E/this.txt:52 ../E/thump.txt:12 ../E/topo.txt:13 ../E/true.txt:4 ../E/trunc.txt:12 ../E/turn.txt:32 ../E/type.txt:32 ../E/var.txt:66 ../E/void.txt:10 ../E/wait.txt:21 ../E/while.txt:46 ../E/writeln.txt:19
|
||||
#: ../E/abstime.txt:10 ../E/acos.txt:11 ../E/aim.txt:23 ../E/array.txt:30 ../E/asin.txt:11 ../E/atan.txt:11 ../E/atan2.txt:16 ../E/bloc.txt:48 ../E/bool.txt:4 ../E/break.txt:24 ../E/build.txt:27 ../E/buildingenabled.txt:22 ../E/canbuild.txt:22 ../E/category.txt:107 ../E/ceil.txt:12 ../E/class.txt:70 ../E/close.txt:6 ../E/cond.txt:27 ../E/continue.txt:24 ../E/cos.txt:11 ../E/deletef.txt:9 ../E/delinfo.txt:13 ../E/direct.txt:13 ../E/dist.txt:29 ../E/dist2d.txt:13 ../E/do.txt:27 ../E/drop.txt:28 ../E/eof.txt:13 ../E/errmode.txt:32 ../E/expr.txt:74 ../E/extern.txt:29 ../E/false.txt:4 ../E/file.txt:16 ../E/fire.txt:30 ../E/flatgrnd.txt:16 ../E/float.txt:24 ../E/floor.txt:12 ../E/for.txt:38 ../E/function.txt:129 ../E/goto.txt:34 ../E/grab.txt:28 ../E/if.txt:39 ../E/int.txt:18 ../E/jet.txt:14 ../E/message.txt:24 ../E/motor.txt:38 ../E/move.txt:21 ../E/nan.txt:14 ../E/new.txt:20 ../E/null.txt:4 ../E/object.txt:68 ../E/open.txt:18 ../E/openfile.txt:10 ../E/point.txt:35 ../E/pointer.txt:51 ../E/pow.txt:14 ../E/private.txt:17 ../E/public.txt:49 ../E/radar.txt:58 ../E/rand.txt:8 ../E/readln.txt:18 ../E/receive.txt:16 ../E/recycle.txt:12 ../E/retobj.txt:13 ../E/return.txt:29 ../E/round.txt:12 ../E/search.txt:16 ../E/send.txt:17 ../E/shield.txt:18 ../E/sin.txt:11 ../E/sizeof.txt:21 ../E/sniff.txt:16 ../E/space.txt:22 ../E/sqrt.txt:11 ../E/static.txt:20 ../E/strfind.txt:18 ../E/string.txt:32 ../E/strleft.txt:14 ../E/strlen.txt:12 ../E/strlower.txt:10 ../E/strmid.txt:18 ../E/strright.txt:14 ../E/strupper.txt:10 ../E/strval.txt:17 ../E/synchro.txt:23 ../E/tan.txt:11 ../E/term.txt:30 ../E/testinfo.txt:16 ../E/this.txt:52 ../E/thump.txt:12 ../E/topo.txt:13 ../E/true.txt:4 ../E/trunc.txt:12 ../E/turn.txt:32 ../E/type.txt:32 ../E/var.txt:66 ../E/void.txt:10 ../E/wait.txt:21 ../E/while.txt:46 ../E/writeln.txt:19
|
||||
#, no-wrap
|
||||
msgid "See also"
|
||||
msgstr "Voir aussi"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/abstime.txt:11 ../E/aim.txt:24 ../E/array.txt:31 ../E/bool.txt:5 ../E/break.txt:25 ../E/cond.txt:28 ../E/continue.txt:25 ../E/deletef.txt:10 ../E/direct.txt:14 ../E/dist.txt:30 ../E/dist2d.txt:14 ../E/drop.txt:29 ../E/errmode.txt:33 ../E/expr.txt:75 ../E/extern.txt:30 ../E/false.txt:5 ../E/fire.txt:31 ../E/flatgrnd.txt:17 ../E/float.txt:25 ../E/for.txt:39 ../E/function.txt:85 ../E/goto.txt:35 ../E/grab.txt:29 ../E/if.txt:40 ../E/int.txt:19 ../E/jet.txt:15 ../E/message.txt:25 ../E/move.txt:22 ../E/nan.txt:15 ../E/object.txt:69 ../E/openfile.txt:11 ../E/point.txt:36 ../E/radar.txt:59 ../E/recycle.txt:13 ../E/retobj.txt:14 ../E/return.txt:30 ../E/search.txt:17 ../E/shield.txt:19 ../E/sizeof.txt:22 ../E/sniff.txt:17 ../E/space.txt:23 ../E/string.txt:33 ../E/term.txt:31 ../E/thump.txt:13 ../E/topo.txt:14 ../E/true.txt:5 ../E/turn.txt:33 ../E/type.txt:33 ../E/var.txt:67 ../E/void.txt:11 ../E/wait.txt:22
|
||||
#: ../E/abstime.txt:11 ../E/aim.txt:24 ../E/array.txt:31 ../E/bool.txt:5 ../E/break.txt:25 ../E/cond.txt:28 ../E/continue.txt:25 ../E/deletef.txt:10 ../E/direct.txt:14 ../E/dist.txt:30 ../E/dist2d.txt:14 ../E/drop.txt:29 ../E/errmode.txt:33 ../E/expr.txt:75 ../E/extern.txt:30 ../E/false.txt:5 ../E/fire.txt:31 ../E/flatgrnd.txt:17 ../E/float.txt:25 ../E/for.txt:39 ../E/function.txt:130 ../E/goto.txt:35 ../E/grab.txt:29 ../E/if.txt:40 ../E/int.txt:19 ../E/jet.txt:15 ../E/message.txt:25 ../E/move.txt:22 ../E/nan.txt:15 ../E/object.txt:69 ../E/openfile.txt:11 ../E/point.txt:36 ../E/radar.txt:59 ../E/recycle.txt:13 ../E/retobj.txt:14 ../E/return.txt:30 ../E/search.txt:17 ../E/shield.txt:19 ../E/sizeof.txt:22 ../E/sniff.txt:17 ../E/space.txt:23 ../E/string.txt:33 ../E/term.txt:31 ../E/thump.txt:13 ../E/topo.txt:14 ../E/true.txt:5 ../E/turn.txt:33 ../E/type.txt:33 ../E/var.txt:67 ../E/void.txt:11 ../E/wait.txt:22
|
||||
#, no-wrap
|
||||
msgid "<a cbot>Programming</a>, <a cbot|type>types</a> and <a cbot|category>categories</a>."
|
||||
msgstr "<a cbot>Programmation</a>, <a cbot|type>types</a> et <a cbot|category>catégories</a>."
|
||||
|
@ -1168,7 +1168,7 @@ msgid "With the instruction <code>distance( , )</code> you can calculate the dis
|
|||
msgstr "Avec l'instruction <code>distance( , )</code> vous pouvez calculer la distance entre deux positions. "
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/build.txt:4 ../E/buildingenabled.txt:4 ../E/canbuild.txt:4 ../E/dist.txt:4 ../E/drop.txt:4 ../E/fire.txt:4 ../E/goto.txt:4 ../E/grab.txt:4 ../E/if.txt:4 ../E/motor.txt:4 ../E/move.txt:4 ../E/radar.txt:4 ../E/turn.txt:4 ../E/wait.txt:4 ../E/while.txt:4
|
||||
#: ../E/build.txt:4 ../E/buildingenabled.txt:4 ../E/canbuild.txt:4 ../E/dist.txt:4 ../E/drop.txt:4 ../E/fire.txt:4 ../E/function.txt:16 ../E/goto.txt:4 ../E/grab.txt:4 ../E/if.txt:4 ../E/motor.txt:4 ../E/move.txt:4 ../E/radar.txt:4 ../E/turn.txt:4 ../E/wait.txt:4 ../E/while.txt:4
|
||||
#, no-wrap
|
||||
msgid "Basic use"
|
||||
msgstr "Utilisation courante"
|
||||
|
@ -2204,208 +2204,7 @@ msgid "Functions"
|
|||
msgstr "Les fonctions"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:2
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"With functions you can divide your program into several parts, each of them will execute a specific task.\n"
|
||||
"Let's imagine following program¦:"
|
||||
msgstr ""
|
||||
"Lorsqu'un programme devient long, il est conseillé de le fragmenter en plusieurs fonctions, qui accompliront chacune une tâche bien précise.\n"
|
||||
"Imaginons le programe suivant:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:5
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"extern void object::Remote( )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", 1, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 3, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 2, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 4, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"extern void object::Remote( )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", 1, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 3, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 2, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 4, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:17
|
||||
#, no-wrap
|
||||
msgid "<code>send</code> and <code>wait</code> are repeated several times. So it would be a good thing if we created a function that executes these two instructions:"
|
||||
msgstr "On constate que les deux instructions <code>send</code> et <code>wait</code> sont répétées plusieurs fois. Il est donc judicieux de créer une fonction <code>SendToPost</code> qui effectue ces deux instructions:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:19
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void object::SendToPost( float op )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", op, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}\n"
|
||||
"extern void object::Remote( )\n"
|
||||
"{\n"
|
||||
"\tSendToPost(1);\n"
|
||||
"\tSendToPost(3);\n"
|
||||
"\tSendToPost(2);\n"
|
||||
"\tSendToPost(4);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"extern void object::Remote( )\n"
|
||||
"{\n"
|
||||
"\tSendToPost(1);\n"
|
||||
"\tSendToPost(3);\n"
|
||||
"\tSendToPost(2);\n"
|
||||
"\tSendToPost(4);\n"
|
||||
"}\n"
|
||||
"void object::SendToPost( float op )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", op, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:32
|
||||
#, no-wrap
|
||||
msgid "A function can have paramteters¦:"
|
||||
msgstr "Une fonction peut recevoir des données en entrée. Il faut en donner la liste, avec à chaque fois le type de la variable et le nom qui lui est donné:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:34
|
||||
#, no-wrap
|
||||
msgid "void Example( int a, float x, string s )"
|
||||
msgstr "void Example( int a, float x, string s )"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:36
|
||||
#, no-wrap
|
||||
msgid "The <code>Example</code> function will reveive un integer <code>a</code>, a floating point number <code>x</code> and a string <code>s</code>. Parameters are \"passed by value\", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an <code>int</code> to a function, its parameter is a copy of whatever value was being passed as argument, and the function can change its parameter value without affecting values in the code that invoked the function."
|
||||
msgstr "La fonction <code>Example</code> va recevoir un nombre entier <code>a</code>, un nombre réel <code>x</code> et une chaîne <code>s</code>. Parameters are \"passed by value\", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an <code>int</code> to a function, its parameter is a copy of whatever value was being passed as argument, and the function can change its parameter value without affecting values in the code that invoked the function."
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:38
|
||||
#, no-wrap
|
||||
msgid "If you pass a <a cbot|class>class</a> instance or an <a cbot|array>array</a> as parameter to a function, the function only receives a <a cbot|pointer>reference</a> to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actuallay modified."
|
||||
msgstr "Les <a cbot|array>tableaux</a> et les instances de <a cbot|class>classes</a> sont toujours passées par <a cbot|pointer>référence</a>. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actuallay modified."
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:40
|
||||
#, no-wrap
|
||||
msgid "A function can also return a result with the <code><a cbot|return>return</a></code> instruction. Therefore the function must be declared no longer as void but as a type:"
|
||||
msgstr "Une fonction peut effectuer un calcul et retourner le résultat avec l'instruction <code><a cbot|return>return</a></code>. Therefore the function must be declared no longer as void but as a type:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:42
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Mean( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn (a+b)/2;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Test( )\n"
|
||||
"{\n"
|
||||
"\tfloat value;\n"
|
||||
"\tvalue = Mean(2, 6);\n"
|
||||
"\tmessage( value ); // will display 4\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"float Moyenne( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn (a+b)/2;\n"
|
||||
"}\n"
|
||||
"extern void object::Essai( )\n"
|
||||
"{\n"
|
||||
"\tfloat value;\n"
|
||||
"\tvalue = Moyenne(2, 6);\n"
|
||||
"\tmessage( value ); // affiche 4\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:54
|
||||
#, no-wrap
|
||||
msgid "Some other examples¦:"
|
||||
msgstr "Voici d'autres exemples de fonctions:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:56
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pi( )\n"
|
||||
"{\n"
|
||||
"\treturn 3.1415;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"string Sign( float a )\n"
|
||||
"{\n"
|
||||
"\tif ( a > 0 ) return \"positive\";\n"
|
||||
"\tif ( a < 0 ) return \"negative\";\n"
|
||||
"\treturn \"null\";\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"float Pi( )\n"
|
||||
"{\n"
|
||||
"\treturn 3.1415;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"string Signe( float a )\n"
|
||||
"{\n"
|
||||
"\tif ( a > 0 ) return \"positif\";\n"
|
||||
"\tif ( a < 0 ) return \"negatif\";\n"
|
||||
"\treturn \"nul\";\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:68
|
||||
#, no-wrap
|
||||
msgid "You can declare several functions with the same name but different parameters¦:"
|
||||
msgstr "Il est autorisé de créer plusieurs fonctions ayant le même nom mais des paramètres différents:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:70
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pythagoras( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float Pythagoras( float a, float b, float c )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"float Pythagore( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float Pythagore( float a, float b, float c )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:80
|
||||
#, no-wrap
|
||||
msgid "CBOT will call either the one or the other function depending on the paramteres passed."
|
||||
msgstr "Lors de l'appel à la fonction, CBOT recherche la fonction dont les paramètres correspondent au mieux."
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:82
|
||||
#: ../E/function.txt:118
|
||||
#, no-wrap
|
||||
msgid "You can also declare a function <a cbot|public>public</a> so it can be used by other bots."
|
||||
msgstr ""
|
||||
|
@ -6882,6 +6681,442 @@ msgstr ""
|
|||
msgid "x: <code><a cbot|float>float</a></code> (default value: <code>0</code>)"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:2
|
||||
#, no-wrap
|
||||
msgid "Function, simply put, is an instruction created by you."
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:4
|
||||
#, no-wrap
|
||||
msgid "Main function"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:5
|
||||
#, no-wrap
|
||||
msgid "You probably already know how to create a function. Every program in CBOT must have a main function, which looks like this:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:7
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"extern void object::ProgramName()\n"
|
||||
"{\n"
|
||||
"\t\n"
|
||||
"\t// instructions\n"
|
||||
"\t\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:14
|
||||
#, no-wrap
|
||||
msgid "Nothing but a name can be changed in a main function. The keyword <code>extern</code> distinguish the main function from others."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:17
|
||||
#, no-wrap
|
||||
msgid "With functions you can divide your program into several parts. Each of them will execute a specific task. For example, see the following program:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:19
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"extern void object::Remote()\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", 1, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 3, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 2, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 4, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:31
|
||||
#, no-wrap
|
||||
msgid "<code><a cbot|send>send</a></code> and <code><a cbot|wait>wait</a></code> are repeated several times. So it would be a good thing if we created a function that executes these two instructions:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:33
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void SendToPost(float op)\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", op, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Remote()\n"
|
||||
"{\n"
|
||||
"\tSendToPost(1);\n"
|
||||
"\tSendToPost(3);\n"
|
||||
"\tSendToPost(2);\n"
|
||||
"\tSendToPost(4);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:49
|
||||
#, no-wrap
|
||||
msgid "Syntax"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:56
|
||||
#, no-wrap
|
||||
msgid "A function must be declared above the main function. Result <a cbot|type>type</a> should be <a cbot/void>void</a> if the function does not give any. Body is just a set of instructions. Function name must be created with the exact same rules applied to <a cbot|var>variables</a>."
|
||||
msgstr ""
|
||||
|
||||
#. type: \t; header
|
||||
#: ../E/function.txt:58
|
||||
#, no-wrap
|
||||
msgid "Parameters"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:59
|
||||
#, no-wrap
|
||||
msgid "A function can have parameters:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:68
|
||||
#, no-wrap
|
||||
msgid "The <code>Example</code> function will receive an <a cbot|int>integer</a> <code>a</code>, a <a cbot|float>floating point number</a> <code>x</code> and a <a cbot|string>string</a> <code>s</code>. Parameters are \"passed by value\", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an <code><a cbot|int>int</a></code> to a function, its parameter is a copy of whatever value was being passed as the argument, and the function can change its parameter value without affecting values in the code that invoked the function."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:70
|
||||
#, no-wrap
|
||||
msgid "If you pass a <a cbot|class>class</a> instance or an <a cbot|array>array</a> as parameter to a function, the function only receives a <a cbot|pointer>reference</a> to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actually modified."
|
||||
msgstr ""
|
||||
|
||||
#. type: \t; header
|
||||
#: ../E/function.txt:72
|
||||
#, no-wrap
|
||||
msgid "Result"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:73
|
||||
#, no-wrap
|
||||
msgid "A function can also return a result with the <code><a cbot|return>return</a></code> instruction. Therefore the function must be declared no longer as <code><a cbot|void>void</a></code> but as an other <a cbot|type>type</a>:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:75
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Average(float a, float b)\n"
|
||||
"{\n"
|
||||
"\treturn (a+b)/2;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Test( )\n"
|
||||
"{\n"
|
||||
"\tfloat value;\n"
|
||||
"\tvalue = Average(2, 6);\n"
|
||||
"\tmessage(value); // will display 4\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:87
|
||||
#, no-wrap
|
||||
msgid "Some other examples:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:89
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pi()\n"
|
||||
"{\n"
|
||||
"\treturn 3.1415;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"string Sign(float a)\n"
|
||||
"{\n"
|
||||
"\tif (a > 0) return \"positive\";\n"
|
||||
"\tif (a < 0) return \"negative\";\n"
|
||||
"\treturn \"null\";\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:102
|
||||
#, no-wrap
|
||||
msgid "Overloading"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:103
|
||||
#, no-wrap
|
||||
msgid "You can declare several functions with the same name but different parameters:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:105
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pythagoras(float a, float b)\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float Pythagoras(float a, float b, float c)\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:115
|
||||
#, no-wrap
|
||||
msgid "CBOT will call either the one or the other function depending on the parameters passed. They must be distinguishable, i.e. you can't declare two functions with the same name and parameter types in the exact same order, e.g. declaring <code>int Pythagoras(float b, float a)</code> will result in error. Note that result type does not matter."
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:117
|
||||
#, no-wrap
|
||||
msgid "Public functions"
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:120
|
||||
#, no-wrap
|
||||
msgid "object::"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:121
|
||||
#, no-wrap
|
||||
msgid "Declaring a function as a part of the <a cbot|object>object</a> namespace gives it access to <code><a cbot|this>this</a></code> <a cbot|pointer>pointer</a>, in other words, to all available properties of the robot which the program is run on."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:47
|
||||
#, no-wrap
|
||||
msgid "Now the program is much easier to read. It is a good practice to split the program into several functions with self-describing names."
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:51
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"result_type FunctionName(optional_parameters)\n"
|
||||
"{\n"
|
||||
"\tbody\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:61
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void Example(int a, float x, string s)\n"
|
||||
"{\n"
|
||||
"\tmessage(a);\n"
|
||||
"\tmessage(x);\n"
|
||||
"\tmessage(s);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:123
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void object::Example()\n"
|
||||
"{\n"
|
||||
"\tmessage(this.category);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#~ msgid "Now the program is much easier to read. It's a good practice to split the program into several functions with self-describing names."
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "result_type FunctionName(optional_parameters)\n"
|
||||
#~ "{\n"
|
||||
#~ " body\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "void Example(int a, float x, string s)\n"
|
||||
#~ "{\n"
|
||||
#~ " message(a);\n"
|
||||
#~ " message(x);\n"
|
||||
#~ " message(s);\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "With functions you can divide your program into several parts, each of them will execute a specific task.\n"
|
||||
#~ "Let's imagine following program¦:"
|
||||
#~ msgstr ""
|
||||
#~ "Lorsqu'un programme devient long, il est conseillé de le fragmenter en plusieurs fonctions, qui accompliront chacune une tâche bien précise.\n"
|
||||
#~ "Imaginons le programe suivant:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "extern void object::Remote( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", 1, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 3, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 2, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 4, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "extern void object::Remote( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", 1, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 3, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 2, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 4, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "<code>send</code> and <code>wait</code> are repeated several times. So it would be a good thing if we created a function that executes these two instructions:"
|
||||
#~ msgstr "On constate que les deux instructions <code>send</code> et <code>wait</code> sont répétées plusieurs fois. Il est donc judicieux de créer une fonction <code>SendToPost</code> qui effectue ces deux instructions:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "void object::SendToPost( float op )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", op, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}\n"
|
||||
#~ "extern void object::Remote( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tSendToPost(1);\n"
|
||||
#~ "\tSendToPost(3);\n"
|
||||
#~ "\tSendToPost(2);\n"
|
||||
#~ "\tSendToPost(4);\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "extern void object::Remote( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tSendToPost(1);\n"
|
||||
#~ "\tSendToPost(3);\n"
|
||||
#~ "\tSendToPost(2);\n"
|
||||
#~ "\tSendToPost(4);\n"
|
||||
#~ "}\n"
|
||||
#~ "void object::SendToPost( float op )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", op, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "A function can have paramteters¦:"
|
||||
#~ msgstr "Une fonction peut recevoir des données en entrée. Il faut en donner la liste, avec à chaque fois le type de la variable et le nom qui lui est donné:"
|
||||
|
||||
#~ msgid "void Example( int a, float x, string s )"
|
||||
#~ msgstr "void Example( int a, float x, string s )"
|
||||
|
||||
#~ msgid "The <code>Example</code> function will reveive un integer <code>a</code>, a floating point number <code>x</code> and a string <code>s</code>. Parameters are \"passed by value\", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an <code>int</code> to a function, its parameter is a copy of whatever value was being passed as argument, and the function can change its parameter value without affecting values in the code that invoked the function."
|
||||
#~ msgstr "La fonction <code>Example</code> va recevoir un nombre entier <code>a</code>, un nombre réel <code>x</code> et une chaîne <code>s</code>. Parameters are \"passed by value\", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an <code>int</code> to a function, its parameter is a copy of whatever value was being passed as argument, and the function can change its parameter value without affecting values in the code that invoked the function."
|
||||
|
||||
#~ msgid "If you pass a <a cbot|class>class</a> instance or an <a cbot|array>array</a> as parameter to a function, the function only receives a <a cbot|pointer>reference</a> to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actuallay modified."
|
||||
#~ msgstr "Les <a cbot|array>tableaux</a> et les instances de <a cbot|class>classes</a> sont toujours passées par <a cbot|pointer>référence</a>. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actuallay modified."
|
||||
|
||||
#~ msgid "A function can also return a result with the <code><a cbot|return>return</a></code> instruction. Therefore the function must be declared no longer as void but as a type:"
|
||||
#~ msgstr "Une fonction peut effectuer un calcul et retourner le résultat avec l'instruction <code><a cbot|return>return</a></code>. Therefore the function must be declared no longer as void but as a type:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "float Mean( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn (a+b)/2;\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "extern void object::Test( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tfloat value;\n"
|
||||
#~ "\tvalue = Mean(2, 6);\n"
|
||||
#~ "\tmessage( value ); // will display 4\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "float Moyenne( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn (a+b)/2;\n"
|
||||
#~ "}\n"
|
||||
#~ "extern void object::Essai( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tfloat value;\n"
|
||||
#~ "\tvalue = Moyenne(2, 6);\n"
|
||||
#~ "\tmessage( value ); // affiche 4\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "Some other examples¦:"
|
||||
#~ msgstr "Voici d'autres exemples de fonctions:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "float Pi( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn 3.1415;\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "string Sign( float a )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tif ( a > 0 ) return \"positive\";\n"
|
||||
#~ "\tif ( a < 0 ) return \"negative\";\n"
|
||||
#~ "\treturn \"null\";\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "float Pi( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn 3.1415;\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "string Signe( float a )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tif ( a > 0 ) return \"positif\";\n"
|
||||
#~ "\tif ( a < 0 ) return \"negatif\";\n"
|
||||
#~ "\treturn \"nul\";\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "You can declare several functions with the same name but different parameters¦:"
|
||||
#~ msgstr "Il est autorisé de créer plusieurs fonctions ayant le même nom mais des paramètres différents:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "float Pythagoras( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b));\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "float Pythagoras( float a, float b, float c )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "float Pythagore( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b));\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "float Pythagore( float a, float b, float c )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "CBOT will call either the one or the other function depending on the paramteres passed."
|
||||
#~ msgstr "Lors de l'appel à la fonction, CBOT recherche la fonction dont les paramètres correspondent au mieux."
|
||||
|
||||
#~ msgid "x: <code><a cbot|float>float</a></code> (default value: <code>0</code>);"
|
||||
#~ msgstr ""
|
||||
|
||||
|
|
|
@ -53,13 +53,13 @@ msgid "Time in seconds."
|
|||
msgstr "Czas w sekundach."
|
||||
|
||||
#. type: \t; header
|
||||
#: ../E/abstime.txt:10 ../E/acos.txt:11 ../E/aim.txt:23 ../E/array.txt:30 ../E/asin.txt:11 ../E/atan.txt:11 ../E/atan2.txt:16 ../E/bloc.txt:48 ../E/bool.txt:4 ../E/break.txt:24 ../E/build.txt:27 ../E/buildingenabled.txt:22 ../E/canbuild.txt:22 ../E/category.txt:107 ../E/ceil.txt:12 ../E/class.txt:70 ../E/close.txt:6 ../E/cond.txt:27 ../E/continue.txt:24 ../E/cos.txt:11 ../E/deletef.txt:9 ../E/delinfo.txt:13 ../E/direct.txt:13 ../E/dist.txt:29 ../E/dist2d.txt:13 ../E/do.txt:27 ../E/drop.txt:28 ../E/eof.txt:13 ../E/errmode.txt:32 ../E/expr.txt:74 ../E/extern.txt:29 ../E/false.txt:4 ../E/file.txt:16 ../E/fire.txt:30 ../E/flatgrnd.txt:16 ../E/float.txt:24 ../E/floor.txt:12 ../E/for.txt:38 ../E/function.txt:84 ../E/goto.txt:34 ../E/grab.txt:28 ../E/if.txt:39 ../E/int.txt:18 ../E/jet.txt:14 ../E/message.txt:24 ../E/motor.txt:38 ../E/move.txt:21 ../E/nan.txt:14 ../E/new.txt:20 ../E/null.txt:4 ../E/object.txt:68 ../E/open.txt:18 ../E/openfile.txt:10 ../E/point.txt:35 ../E/pointer.txt:51 ../E/pow.txt:14 ../E/private.txt:17 ../E/public.txt:49 ../E/radar.txt:58 ../E/rand.txt:8 ../E/readln.txt:18 ../E/receive.txt:16 ../E/recycle.txt:12 ../E/retobj.txt:13 ../E/return.txt:29 ../E/round.txt:12 ../E/search.txt:16 ../E/send.txt:17 ../E/shield.txt:18 ../E/sin.txt:11 ../E/sizeof.txt:21 ../E/sniff.txt:16 ../E/space.txt:22 ../E/sqrt.txt:11 ../E/static.txt:20 ../E/strfind.txt:18 ../E/string.txt:32 ../E/strleft.txt:14 ../E/strlen.txt:12 ../E/strlower.txt:10 ../E/strmid.txt:18 ../E/strright.txt:14 ../E/strupper.txt:10 ../E/strval.txt:17 ../E/synchro.txt:23 ../E/tan.txt:11 ../E/term.txt:30 ../E/testinfo.txt:16 ../E/this.txt:52 ../E/thump.txt:12 ../E/topo.txt:13 ../E/true.txt:4 ../E/trunc.txt:12 ../E/turn.txt:32 ../E/type.txt:32 ../E/var.txt:66 ../E/void.txt:10 ../E/wait.txt:21 ../E/while.txt:46 ../E/writeln.txt:19
|
||||
#: ../E/abstime.txt:10 ../E/acos.txt:11 ../E/aim.txt:23 ../E/array.txt:30 ../E/asin.txt:11 ../E/atan.txt:11 ../E/atan2.txt:16 ../E/bloc.txt:48 ../E/bool.txt:4 ../E/break.txt:24 ../E/build.txt:27 ../E/buildingenabled.txt:22 ../E/canbuild.txt:22 ../E/category.txt:107 ../E/ceil.txt:12 ../E/class.txt:70 ../E/close.txt:6 ../E/cond.txt:27 ../E/continue.txt:24 ../E/cos.txt:11 ../E/deletef.txt:9 ../E/delinfo.txt:13 ../E/direct.txt:13 ../E/dist.txt:29 ../E/dist2d.txt:13 ../E/do.txt:27 ../E/drop.txt:28 ../E/eof.txt:13 ../E/errmode.txt:32 ../E/expr.txt:74 ../E/extern.txt:29 ../E/false.txt:4 ../E/file.txt:16 ../E/fire.txt:30 ../E/flatgrnd.txt:16 ../E/float.txt:24 ../E/floor.txt:12 ../E/for.txt:38 ../E/function.txt:129 ../E/goto.txt:34 ../E/grab.txt:28 ../E/if.txt:39 ../E/int.txt:18 ../E/jet.txt:14 ../E/message.txt:24 ../E/motor.txt:38 ../E/move.txt:21 ../E/nan.txt:14 ../E/new.txt:20 ../E/null.txt:4 ../E/object.txt:68 ../E/open.txt:18 ../E/openfile.txt:10 ../E/point.txt:35 ../E/pointer.txt:51 ../E/pow.txt:14 ../E/private.txt:17 ../E/public.txt:49 ../E/radar.txt:58 ../E/rand.txt:8 ../E/readln.txt:18 ../E/receive.txt:16 ../E/recycle.txt:12 ../E/retobj.txt:13 ../E/return.txt:29 ../E/round.txt:12 ../E/search.txt:16 ../E/send.txt:17 ../E/shield.txt:18 ../E/sin.txt:11 ../E/sizeof.txt:21 ../E/sniff.txt:16 ../E/space.txt:22 ../E/sqrt.txt:11 ../E/static.txt:20 ../E/strfind.txt:18 ../E/string.txt:32 ../E/strleft.txt:14 ../E/strlen.txt:12 ../E/strlower.txt:10 ../E/strmid.txt:18 ../E/strright.txt:14 ../E/strupper.txt:10 ../E/strval.txt:17 ../E/synchro.txt:23 ../E/tan.txt:11 ../E/term.txt:30 ../E/testinfo.txt:16 ../E/this.txt:52 ../E/thump.txt:12 ../E/topo.txt:13 ../E/true.txt:4 ../E/trunc.txt:12 ../E/turn.txt:32 ../E/type.txt:32 ../E/var.txt:66 ../E/void.txt:10 ../E/wait.txt:21 ../E/while.txt:46 ../E/writeln.txt:19
|
||||
#, no-wrap
|
||||
msgid "See also"
|
||||
msgstr "Zobacz również"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/abstime.txt:11 ../E/aim.txt:24 ../E/array.txt:31 ../E/bool.txt:5 ../E/break.txt:25 ../E/cond.txt:28 ../E/continue.txt:25 ../E/deletef.txt:10 ../E/direct.txt:14 ../E/dist.txt:30 ../E/dist2d.txt:14 ../E/drop.txt:29 ../E/errmode.txt:33 ../E/expr.txt:75 ../E/extern.txt:30 ../E/false.txt:5 ../E/fire.txt:31 ../E/flatgrnd.txt:17 ../E/float.txt:25 ../E/for.txt:39 ../E/function.txt:85 ../E/goto.txt:35 ../E/grab.txt:29 ../E/if.txt:40 ../E/int.txt:19 ../E/jet.txt:15 ../E/message.txt:25 ../E/move.txt:22 ../E/nan.txt:15 ../E/object.txt:69 ../E/openfile.txt:11 ../E/point.txt:36 ../E/radar.txt:59 ../E/recycle.txt:13 ../E/retobj.txt:14 ../E/return.txt:30 ../E/search.txt:17 ../E/shield.txt:19 ../E/sizeof.txt:22 ../E/sniff.txt:17 ../E/space.txt:23 ../E/string.txt:33 ../E/term.txt:31 ../E/thump.txt:13 ../E/topo.txt:14 ../E/true.txt:5 ../E/turn.txt:33 ../E/type.txt:33 ../E/var.txt:67 ../E/void.txt:11 ../E/wait.txt:22
|
||||
#: ../E/abstime.txt:11 ../E/aim.txt:24 ../E/array.txt:31 ../E/bool.txt:5 ../E/break.txt:25 ../E/cond.txt:28 ../E/continue.txt:25 ../E/deletef.txt:10 ../E/direct.txt:14 ../E/dist.txt:30 ../E/dist2d.txt:14 ../E/drop.txt:29 ../E/errmode.txt:33 ../E/expr.txt:75 ../E/extern.txt:30 ../E/false.txt:5 ../E/fire.txt:31 ../E/flatgrnd.txt:17 ../E/float.txt:25 ../E/for.txt:39 ../E/function.txt:130 ../E/goto.txt:35 ../E/grab.txt:29 ../E/if.txt:40 ../E/int.txt:19 ../E/jet.txt:15 ../E/message.txt:25 ../E/move.txt:22 ../E/nan.txt:15 ../E/object.txt:69 ../E/openfile.txt:11 ../E/point.txt:36 ../E/radar.txt:59 ../E/recycle.txt:13 ../E/retobj.txt:14 ../E/return.txt:30 ../E/search.txt:17 ../E/shield.txt:19 ../E/sizeof.txt:22 ../E/sniff.txt:17 ../E/space.txt:23 ../E/string.txt:33 ../E/term.txt:31 ../E/thump.txt:13 ../E/topo.txt:14 ../E/true.txt:5 ../E/turn.txt:33 ../E/type.txt:33 ../E/var.txt:67 ../E/void.txt:11 ../E/wait.txt:22
|
||||
#, no-wrap
|
||||
msgid "<a cbot>Programming</a>, <a cbot|type>types</a> and <a cbot|category>categories</a>."
|
||||
msgstr "<a cbot>Programowanie</a>, <a cbot|type>typy</a> i <a cbot|category>kategorie</a>."
|
||||
|
@ -1179,7 +1179,7 @@ msgid "With the instruction <code>distance( , )</code> you can calculate the dis
|
|||
msgstr "Za pomocą instrukcji <code>distance( , )</code> można obliczyć odległość między dwoma punktami."
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/build.txt:4 ../E/buildingenabled.txt:4 ../E/canbuild.txt:4 ../E/dist.txt:4 ../E/drop.txt:4 ../E/fire.txt:4 ../E/goto.txt:4 ../E/grab.txt:4 ../E/if.txt:4 ../E/motor.txt:4 ../E/move.txt:4 ../E/radar.txt:4 ../E/turn.txt:4 ../E/wait.txt:4 ../E/while.txt:4
|
||||
#: ../E/build.txt:4 ../E/buildingenabled.txt:4 ../E/canbuild.txt:4 ../E/dist.txt:4 ../E/drop.txt:4 ../E/fire.txt:4 ../E/function.txt:16 ../E/goto.txt:4 ../E/grab.txt:4 ../E/if.txt:4 ../E/motor.txt:4 ../E/move.txt:4 ../E/radar.txt:4 ../E/turn.txt:4 ../E/wait.txt:4 ../E/while.txt:4
|
||||
#, no-wrap
|
||||
msgid "Basic use"
|
||||
msgstr "Podstawowe użycie"
|
||||
|
@ -2231,209 +2231,7 @@ msgid "Functions"
|
|||
msgstr "Funkcje"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:2
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"With functions you can divide your program into several parts, each of them will execute a specific task.\n"
|
||||
"Let's imagine following program¦:"
|
||||
msgstr ""
|
||||
"Używając funkcji można podzielić program na kilka części, z których każda będzie wykonywała określone zadanie.\n"
|
||||
"Wyobraźmy sobie następujący program¦:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:5
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"extern void object::Remote( )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", 1, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 3, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 2, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 4, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"extern void object::Zdalnie( )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", 1, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 3, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 2, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 4, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:17
|
||||
#, no-wrap
|
||||
msgid "<code>send</code> and <code>wait</code> are repeated several times. So it would be a good thing if we created a function that executes these two instructions:"
|
||||
msgstr "Instrukcje <code>send</code> i <code>wait</code> wykonywane są wielokrotnie. Byłoby dobrze utworzyć funkcję wykonującą te dwie instrukcje:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:19
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void object::SendToPost( float op )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", op, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}\n"
|
||||
"extern void object::Remote( )\n"
|
||||
"{\n"
|
||||
"\tSendToPost(1);\n"
|
||||
"\tSendToPost(3);\n"
|
||||
"\tSendToPost(2);\n"
|
||||
"\tSendToPost(4);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"void object::WyślijDoStacji( float op )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", op, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}\n"
|
||||
"extern void object::Zdalnie( )\n"
|
||||
"{\n"
|
||||
"\tWyślijDoStacji(1);\n"
|
||||
"\tWyślijDoStacji(3);\n"
|
||||
"\tWyślijDoStacji(2);\n"
|
||||
"\tWyślijDoStacji(4);\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:32
|
||||
#, no-wrap
|
||||
msgid "A function can have paramteters¦:"
|
||||
msgstr "Funkcja może mieć parametry¦:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:34
|
||||
#, no-wrap
|
||||
msgid "void Example( int a, float x, string s )"
|
||||
msgstr "void Przykład( int a, float x, string s )"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:36
|
||||
#, no-wrap
|
||||
msgid "The <code>Example</code> function will reveive un integer <code>a</code>, a floating point number <code>x</code> and a string <code>s</code>. Parameters are \"passed by value\", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an <code>int</code> to a function, its parameter is a copy of whatever value was being passed as argument, and the function can change its parameter value without affecting values in the code that invoked the function."
|
||||
msgstr "Funkcja <code>Przykład</code> dostaje jako parametry liczbę całkowitą <code>a</code>, liczbę zmiennoprzecinkową <code>x</code> oraz łańcuch <code>s</code>. Parametry są \"przekazywane przez wartość\", czyli są kopią wartości określonych jako zmienne podczas wywołania. Przy przekazaniu zmiennej <code>int</code> funkcji, jej parametr jest kopią wartości przekazanej jako argument, wobec czego funkcja może zmieniać wartość parametru bez zmiany wartości w miejscu, z którego była wywołana funkcja."
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:38
|
||||
#, no-wrap
|
||||
msgid "If you pass a <a cbot|class>class</a> instance or an <a cbot|array>array</a> as parameter to a function, the function only receives a <a cbot|pointer>reference</a> to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actuallay modified."
|
||||
msgstr "Przy przekazaniu instancji <a cbot|class>klasy</a> lub <a cbot|array>tablicy</a> jako parametru, funkcja otrzymuje jedynie <a cbot|pointer>wskaźnik</a> do instancji lub tablicy. Oznacza to, że w przypadku modyfikacji instancji lub tablicy wewnątrz funkcji, w rzeczywistości zostanie zmodyfikowana instancja lub tablica określona podczas wywołania."
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:40
|
||||
#, no-wrap
|
||||
msgid "A function can also return a result with the <code><a cbot|return>return</a></code> instruction. Therefore the function must be declared no longer as void but as a type:"
|
||||
msgstr "Funkcja może również zwrócić wynik przy użyciu instrukcji <code><a cbot|return>return</a></code>. Jednakże powinna być wówczas zadeklarowana nie jako void, ale powinna mieć określony typ:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:42
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Mean( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn (a+b)/2;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Test( )\n"
|
||||
"{\n"
|
||||
"\tfloat value;\n"
|
||||
"\tvalue = Mean(2, 6);\n"
|
||||
"\tmessage( value ); // will display 4\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"float Średnia( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn (a+b)/2;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Test( )\n"
|
||||
"{\n"
|
||||
"\tfloat wartość;\n"
|
||||
"\twartość = Średnia(2, 6);\n"
|
||||
"\tmessage( wartość ); // wyświetli liczbę 4\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:54
|
||||
#, no-wrap
|
||||
msgid "Some other examples¦:"
|
||||
msgstr "I jeszcze kilka przykładów¦:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:56
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pi( )\n"
|
||||
"{\n"
|
||||
"\treturn 3.1415;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"string Sign( float a )\n"
|
||||
"{\n"
|
||||
"\tif ( a > 0 ) return \"positive\";\n"
|
||||
"\tif ( a < 0 ) return \"negative\";\n"
|
||||
"\treturn \"null\";\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"float Pi( )\n"
|
||||
"{\n"
|
||||
"\treturn 3.1415;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"string Znak( float a )\n"
|
||||
"{\n"
|
||||
"\tif ( a > 0 ) return \"dodatnia\";\n"
|
||||
"\tif ( a < 0 ) return \"ujemna\";\n"
|
||||
"\treturn \"zero\";\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:68
|
||||
#, no-wrap
|
||||
msgid "You can declare several functions with the same name but different parameters¦:"
|
||||
msgstr "Można zadeklarować kilka funkcji o tej samej nazwie lecz o różnych parametrach¦:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:70
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pythagoras( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float Pythagoras( float a, float b, float c )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"float Pitagoras( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float Pitagoras( float a, float b, float c )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:80
|
||||
#, no-wrap
|
||||
msgid "CBOT will call either the one or the other function depending on the paramteres passed."
|
||||
msgstr "CBOT wywoła jedną z nich, w zależności od przekazanych parametrów."
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:82
|
||||
#: ../E/function.txt:118
|
||||
#, no-wrap
|
||||
msgid "You can also declare a function <a cbot|public>public</a> so it can be used by other bots."
|
||||
msgstr "Można też zadeklarować funkcję <a cbot|public>publiczną</a>, która będzie dostępna dla wszystkich robotów."
|
||||
|
@ -6932,6 +6730,443 @@ msgstr ""
|
|||
msgid "x: <code><a cbot|float>float</a></code> (default value: <code>0</code>)"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:2
|
||||
#, no-wrap
|
||||
msgid "Function, simply put, is an instruction created by you."
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:4
|
||||
#, no-wrap
|
||||
msgid "Main function"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:5
|
||||
#, no-wrap
|
||||
msgid "You probably already know how to create a function. Every program in CBOT must have a main function, which looks like this:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:7
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"extern void object::ProgramName()\n"
|
||||
"{\n"
|
||||
"\t\n"
|
||||
"\t// instructions\n"
|
||||
"\t\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:14
|
||||
#, no-wrap
|
||||
msgid "Nothing but a name can be changed in a main function. The keyword <code>extern</code> distinguish the main function from others."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:17
|
||||
#, no-wrap
|
||||
msgid "With functions you can divide your program into several parts. Each of them will execute a specific task. For example, see the following program:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:19
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"extern void object::Remote()\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", 1, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 3, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 2, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 4, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:31
|
||||
#, no-wrap
|
||||
msgid "<code><a cbot|send>send</a></code> and <code><a cbot|wait>wait</a></code> are repeated several times. So it would be a good thing if we created a function that executes these two instructions:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:33
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void SendToPost(float op)\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", op, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Remote()\n"
|
||||
"{\n"
|
||||
"\tSendToPost(1);\n"
|
||||
"\tSendToPost(3);\n"
|
||||
"\tSendToPost(2);\n"
|
||||
"\tSendToPost(4);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:49
|
||||
#, no-wrap
|
||||
msgid "Syntax"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:56
|
||||
#, no-wrap
|
||||
msgid "A function must be declared above the main function. Result <a cbot|type>type</a> should be <a cbot/void>void</a> if the function does not give any. Body is just a set of instructions. Function name must be created with the exact same rules applied to <a cbot|var>variables</a>."
|
||||
msgstr ""
|
||||
|
||||
#. type: \t; header
|
||||
#: ../E/function.txt:58
|
||||
#, no-wrap
|
||||
msgid "Parameters"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:59
|
||||
#, no-wrap
|
||||
msgid "A function can have parameters:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:68
|
||||
#, no-wrap
|
||||
msgid "The <code>Example</code> function will receive an <a cbot|int>integer</a> <code>a</code>, a <a cbot|float>floating point number</a> <code>x</code> and a <a cbot|string>string</a> <code>s</code>. Parameters are \"passed by value\", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an <code><a cbot|int>int</a></code> to a function, its parameter is a copy of whatever value was being passed as the argument, and the function can change its parameter value without affecting values in the code that invoked the function."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:70
|
||||
#, no-wrap
|
||||
msgid "If you pass a <a cbot|class>class</a> instance or an <a cbot|array>array</a> as parameter to a function, the function only receives a <a cbot|pointer>reference</a> to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actually modified."
|
||||
msgstr ""
|
||||
|
||||
#. type: \t; header
|
||||
#: ../E/function.txt:72
|
||||
#, no-wrap
|
||||
msgid "Result"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:73
|
||||
#, no-wrap
|
||||
msgid "A function can also return a result with the <code><a cbot|return>return</a></code> instruction. Therefore the function must be declared no longer as <code><a cbot|void>void</a></code> but as an other <a cbot|type>type</a>:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:75
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Average(float a, float b)\n"
|
||||
"{\n"
|
||||
"\treturn (a+b)/2;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Test( )\n"
|
||||
"{\n"
|
||||
"\tfloat value;\n"
|
||||
"\tvalue = Average(2, 6);\n"
|
||||
"\tmessage(value); // will display 4\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:87
|
||||
#, no-wrap
|
||||
msgid "Some other examples:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:89
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pi()\n"
|
||||
"{\n"
|
||||
"\treturn 3.1415;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"string Sign(float a)\n"
|
||||
"{\n"
|
||||
"\tif (a > 0) return \"positive\";\n"
|
||||
"\tif (a < 0) return \"negative\";\n"
|
||||
"\treturn \"null\";\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:102
|
||||
#, no-wrap
|
||||
msgid "Overloading"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:103
|
||||
#, no-wrap
|
||||
msgid "You can declare several functions with the same name but different parameters:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:105
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pythagoras(float a, float b)\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float Pythagoras(float a, float b, float c)\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:115
|
||||
#, no-wrap
|
||||
msgid "CBOT will call either the one or the other function depending on the parameters passed. They must be distinguishable, i.e. you can't declare two functions with the same name and parameter types in the exact same order, e.g. declaring <code>int Pythagoras(float b, float a)</code> will result in error. Note that result type does not matter."
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:117
|
||||
#, no-wrap
|
||||
msgid "Public functions"
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:120
|
||||
#, no-wrap
|
||||
msgid "object::"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:121
|
||||
#, no-wrap
|
||||
msgid "Declaring a function as a part of the <a cbot|object>object</a> namespace gives it access to <code><a cbot|this>this</a></code> <a cbot|pointer>pointer</a>, in other words, to all available properties of the robot which the program is run on."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:47
|
||||
#, no-wrap
|
||||
msgid "Now the program is much easier to read. It is a good practice to split the program into several functions with self-describing names."
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:51
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"result_type FunctionName(optional_parameters)\n"
|
||||
"{\n"
|
||||
"\tbody\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:61
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void Example(int a, float x, string s)\n"
|
||||
"{\n"
|
||||
"\tmessage(a);\n"
|
||||
"\tmessage(x);\n"
|
||||
"\tmessage(s);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:123
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void object::Example()\n"
|
||||
"{\n"
|
||||
"\tmessage(this.category);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#~ msgid "Now the program is much easier to read. It's a good practice to split the program into several functions with self-describing names."
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "result_type FunctionName(optional_parameters)\n"
|
||||
#~ "{\n"
|
||||
#~ " body\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "void Example(int a, float x, string s)\n"
|
||||
#~ "{\n"
|
||||
#~ " message(a);\n"
|
||||
#~ " message(x);\n"
|
||||
#~ " message(s);\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "With functions you can divide your program into several parts, each of them will execute a specific task.\n"
|
||||
#~ "Let's imagine following program¦:"
|
||||
#~ msgstr ""
|
||||
#~ "Używając funkcji można podzielić program na kilka części, z których każda będzie wykonywała określone zadanie.\n"
|
||||
#~ "Wyobraźmy sobie następujący program¦:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "extern void object::Remote( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", 1, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 3, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 2, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 4, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "extern void object::Zdalnie( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", 1, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 3, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 2, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 4, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "<code>send</code> and <code>wait</code> are repeated several times. So it would be a good thing if we created a function that executes these two instructions:"
|
||||
#~ msgstr "Instrukcje <code>send</code> i <code>wait</code> wykonywane są wielokrotnie. Byłoby dobrze utworzyć funkcję wykonującą te dwie instrukcje:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "void object::SendToPost( float op )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", op, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}\n"
|
||||
#~ "extern void object::Remote( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tSendToPost(1);\n"
|
||||
#~ "\tSendToPost(3);\n"
|
||||
#~ "\tSendToPost(2);\n"
|
||||
#~ "\tSendToPost(4);\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "void object::WyślijDoStacji( float op )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", op, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}\n"
|
||||
#~ "extern void object::Zdalnie( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tWyślijDoStacji(1);\n"
|
||||
#~ "\tWyślijDoStacji(3);\n"
|
||||
#~ "\tWyślijDoStacji(2);\n"
|
||||
#~ "\tWyślijDoStacji(4);\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "A function can have paramteters¦:"
|
||||
#~ msgstr "Funkcja może mieć parametry¦:"
|
||||
|
||||
#~ msgid "void Example( int a, float x, string s )"
|
||||
#~ msgstr "void Przykład( int a, float x, string s )"
|
||||
|
||||
#~ msgid "The <code>Example</code> function will reveive un integer <code>a</code>, a floating point number <code>x</code> and a string <code>s</code>. Parameters are \"passed by value\", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an <code>int</code> to a function, its parameter is a copy of whatever value was being passed as argument, and the function can change its parameter value without affecting values in the code that invoked the function."
|
||||
#~ msgstr "Funkcja <code>Przykład</code> dostaje jako parametry liczbę całkowitą <code>a</code>, liczbę zmiennoprzecinkową <code>x</code> oraz łańcuch <code>s</code>. Parametry są \"przekazywane przez wartość\", czyli są kopią wartości określonych jako zmienne podczas wywołania. Przy przekazaniu zmiennej <code>int</code> funkcji, jej parametr jest kopią wartości przekazanej jako argument, wobec czego funkcja może zmieniać wartość parametru bez zmiany wartości w miejscu, z którego była wywołana funkcja."
|
||||
|
||||
#~ msgid "If you pass a <a cbot|class>class</a> instance or an <a cbot|array>array</a> as parameter to a function, the function only receives a <a cbot|pointer>reference</a> to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actuallay modified."
|
||||
#~ msgstr "Przy przekazaniu instancji <a cbot|class>klasy</a> lub <a cbot|array>tablicy</a> jako parametru, funkcja otrzymuje jedynie <a cbot|pointer>wskaźnik</a> do instancji lub tablicy. Oznacza to, że w przypadku modyfikacji instancji lub tablicy wewnątrz funkcji, w rzeczywistości zostanie zmodyfikowana instancja lub tablica określona podczas wywołania."
|
||||
|
||||
#~ msgid "A function can also return a result with the <code><a cbot|return>return</a></code> instruction. Therefore the function must be declared no longer as void but as a type:"
|
||||
#~ msgstr "Funkcja może również zwrócić wynik przy użyciu instrukcji <code><a cbot|return>return</a></code>. Jednakże powinna być wówczas zadeklarowana nie jako void, ale powinna mieć określony typ:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "float Mean( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn (a+b)/2;\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "extern void object::Test( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tfloat value;\n"
|
||||
#~ "\tvalue = Mean(2, 6);\n"
|
||||
#~ "\tmessage( value ); // will display 4\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "float Średnia( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn (a+b)/2;\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "extern void object::Test( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tfloat wartość;\n"
|
||||
#~ "\twartość = Średnia(2, 6);\n"
|
||||
#~ "\tmessage( wartość ); // wyświetli liczbę 4\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "Some other examples¦:"
|
||||
#~ msgstr "I jeszcze kilka przykładów¦:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "float Pi( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn 3.1415;\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "string Sign( float a )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tif ( a > 0 ) return \"positive\";\n"
|
||||
#~ "\tif ( a < 0 ) return \"negative\";\n"
|
||||
#~ "\treturn \"null\";\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "float Pi( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn 3.1415;\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "string Znak( float a )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tif ( a > 0 ) return \"dodatnia\";\n"
|
||||
#~ "\tif ( a < 0 ) return \"ujemna\";\n"
|
||||
#~ "\treturn \"zero\";\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "You can declare several functions with the same name but different parameters¦:"
|
||||
#~ msgstr "Można zadeklarować kilka funkcji o tej samej nazwie lecz o różnych parametrach¦:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "float Pythagoras( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b));\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "float Pythagoras( float a, float b, float c )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "float Pitagoras( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b));\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "float Pitagoras( float a, float b, float c )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "CBOT will call either the one or the other function depending on the paramteres passed."
|
||||
#~ msgstr "CBOT wywoła jedną z nich, w zależności od przekazanych parametrów."
|
||||
|
||||
#~ msgid "x: <code><a cbot|float>float</a></code> (default value: <code>0</code>);"
|
||||
#~ msgstr ""
|
||||
|
||||
|
|
|
@ -53,13 +53,13 @@ msgid "Time in seconds."
|
|||
msgstr ""
|
||||
|
||||
#. type: \t; header
|
||||
#: ../E/abstime.txt:10 ../E/acos.txt:11 ../E/aim.txt:23 ../E/array.txt:30 ../E/asin.txt:11 ../E/atan.txt:11 ../E/atan2.txt:16 ../E/bloc.txt:48 ../E/bool.txt:4 ../E/break.txt:24 ../E/build.txt:27 ../E/buildingenabled.txt:22 ../E/canbuild.txt:22 ../E/category.txt:107 ../E/ceil.txt:12 ../E/class.txt:70 ../E/close.txt:6 ../E/cond.txt:27 ../E/continue.txt:24 ../E/cos.txt:11 ../E/deletef.txt:9 ../E/delinfo.txt:13 ../E/direct.txt:13 ../E/dist.txt:29 ../E/dist2d.txt:13 ../E/do.txt:27 ../E/drop.txt:28 ../E/eof.txt:13 ../E/errmode.txt:32 ../E/expr.txt:74 ../E/extern.txt:29 ../E/false.txt:4 ../E/file.txt:16 ../E/fire.txt:30 ../E/flatgrnd.txt:16 ../E/float.txt:24 ../E/floor.txt:12 ../E/for.txt:38 ../E/function.txt:84 ../E/goto.txt:34 ../E/grab.txt:28 ../E/if.txt:39 ../E/int.txt:18 ../E/jet.txt:14 ../E/message.txt:24 ../E/motor.txt:38 ../E/move.txt:21 ../E/nan.txt:14 ../E/new.txt:20 ../E/null.txt:4 ../E/object.txt:68 ../E/open.txt:18 ../E/openfile.txt:10 ../E/point.txt:35 ../E/pointer.txt:51 ../E/pow.txt:14 ../E/private.txt:17 ../E/public.txt:49 ../E/radar.txt:58 ../E/rand.txt:8 ../E/readln.txt:18 ../E/receive.txt:16 ../E/recycle.txt:12 ../E/retobj.txt:13 ../E/return.txt:29 ../E/round.txt:12 ../E/search.txt:16 ../E/send.txt:17 ../E/shield.txt:18 ../E/sin.txt:11 ../E/sizeof.txt:21 ../E/sniff.txt:16 ../E/space.txt:22 ../E/sqrt.txt:11 ../E/static.txt:20 ../E/strfind.txt:18 ../E/string.txt:32 ../E/strleft.txt:14 ../E/strlen.txt:12 ../E/strlower.txt:10 ../E/strmid.txt:18 ../E/strright.txt:14 ../E/strupper.txt:10 ../E/strval.txt:17 ../E/synchro.txt:23 ../E/tan.txt:11 ../E/term.txt:30 ../E/testinfo.txt:16 ../E/this.txt:52 ../E/thump.txt:12 ../E/topo.txt:13 ../E/true.txt:4 ../E/trunc.txt:12 ../E/turn.txt:32 ../E/type.txt:32 ../E/var.txt:66 ../E/void.txt:10 ../E/wait.txt:21 ../E/while.txt:46 ../E/writeln.txt:19
|
||||
#: ../E/abstime.txt:10 ../E/acos.txt:11 ../E/aim.txt:23 ../E/array.txt:30 ../E/asin.txt:11 ../E/atan.txt:11 ../E/atan2.txt:16 ../E/bloc.txt:48 ../E/bool.txt:4 ../E/break.txt:24 ../E/build.txt:27 ../E/buildingenabled.txt:22 ../E/canbuild.txt:22 ../E/category.txt:107 ../E/ceil.txt:12 ../E/class.txt:70 ../E/close.txt:6 ../E/cond.txt:27 ../E/continue.txt:24 ../E/cos.txt:11 ../E/deletef.txt:9 ../E/delinfo.txt:13 ../E/direct.txt:13 ../E/dist.txt:29 ../E/dist2d.txt:13 ../E/do.txt:27 ../E/drop.txt:28 ../E/eof.txt:13 ../E/errmode.txt:32 ../E/expr.txt:74 ../E/extern.txt:29 ../E/false.txt:4 ../E/file.txt:16 ../E/fire.txt:30 ../E/flatgrnd.txt:16 ../E/float.txt:24 ../E/floor.txt:12 ../E/for.txt:38 ../E/function.txt:129 ../E/goto.txt:34 ../E/grab.txt:28 ../E/if.txt:39 ../E/int.txt:18 ../E/jet.txt:14 ../E/message.txt:24 ../E/motor.txt:38 ../E/move.txt:21 ../E/nan.txt:14 ../E/new.txt:20 ../E/null.txt:4 ../E/object.txt:68 ../E/open.txt:18 ../E/openfile.txt:10 ../E/point.txt:35 ../E/pointer.txt:51 ../E/pow.txt:14 ../E/private.txt:17 ../E/public.txt:49 ../E/radar.txt:58 ../E/rand.txt:8 ../E/readln.txt:18 ../E/receive.txt:16 ../E/recycle.txt:12 ../E/retobj.txt:13 ../E/return.txt:29 ../E/round.txt:12 ../E/search.txt:16 ../E/send.txt:17 ../E/shield.txt:18 ../E/sin.txt:11 ../E/sizeof.txt:21 ../E/sniff.txt:16 ../E/space.txt:22 ../E/sqrt.txt:11 ../E/static.txt:20 ../E/strfind.txt:18 ../E/string.txt:32 ../E/strleft.txt:14 ../E/strlen.txt:12 ../E/strlower.txt:10 ../E/strmid.txt:18 ../E/strright.txt:14 ../E/strupper.txt:10 ../E/strval.txt:17 ../E/synchro.txt:23 ../E/tan.txt:11 ../E/term.txt:30 ../E/testinfo.txt:16 ../E/this.txt:52 ../E/thump.txt:12 ../E/topo.txt:13 ../E/true.txt:4 ../E/trunc.txt:12 ../E/turn.txt:32 ../E/type.txt:32 ../E/var.txt:66 ../E/void.txt:10 ../E/wait.txt:21 ../E/while.txt:46 ../E/writeln.txt:19
|
||||
#, no-wrap
|
||||
msgid "See also"
|
||||
msgstr "См. также"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/abstime.txt:11 ../E/aim.txt:24 ../E/array.txt:31 ../E/bool.txt:5 ../E/break.txt:25 ../E/cond.txt:28 ../E/continue.txt:25 ../E/deletef.txt:10 ../E/direct.txt:14 ../E/dist.txt:30 ../E/dist2d.txt:14 ../E/drop.txt:29 ../E/errmode.txt:33 ../E/expr.txt:75 ../E/extern.txt:30 ../E/false.txt:5 ../E/fire.txt:31 ../E/flatgrnd.txt:17 ../E/float.txt:25 ../E/for.txt:39 ../E/function.txt:85 ../E/goto.txt:35 ../E/grab.txt:29 ../E/if.txt:40 ../E/int.txt:19 ../E/jet.txt:15 ../E/message.txt:25 ../E/move.txt:22 ../E/nan.txt:15 ../E/object.txt:69 ../E/openfile.txt:11 ../E/point.txt:36 ../E/radar.txt:59 ../E/recycle.txt:13 ../E/retobj.txt:14 ../E/return.txt:30 ../E/search.txt:17 ../E/shield.txt:19 ../E/sizeof.txt:22 ../E/sniff.txt:17 ../E/space.txt:23 ../E/string.txt:33 ../E/term.txt:31 ../E/thump.txt:13 ../E/topo.txt:14 ../E/true.txt:5 ../E/turn.txt:33 ../E/type.txt:33 ../E/var.txt:67 ../E/void.txt:11 ../E/wait.txt:22
|
||||
#: ../E/abstime.txt:11 ../E/aim.txt:24 ../E/array.txt:31 ../E/bool.txt:5 ../E/break.txt:25 ../E/cond.txt:28 ../E/continue.txt:25 ../E/deletef.txt:10 ../E/direct.txt:14 ../E/dist.txt:30 ../E/dist2d.txt:14 ../E/drop.txt:29 ../E/errmode.txt:33 ../E/expr.txt:75 ../E/extern.txt:30 ../E/false.txt:5 ../E/fire.txt:31 ../E/flatgrnd.txt:17 ../E/float.txt:25 ../E/for.txt:39 ../E/function.txt:130 ../E/goto.txt:35 ../E/grab.txt:29 ../E/if.txt:40 ../E/int.txt:19 ../E/jet.txt:15 ../E/message.txt:25 ../E/move.txt:22 ../E/nan.txt:15 ../E/object.txt:69 ../E/openfile.txt:11 ../E/point.txt:36 ../E/radar.txt:59 ../E/recycle.txt:13 ../E/retobj.txt:14 ../E/return.txt:30 ../E/search.txt:17 ../E/shield.txt:19 ../E/sizeof.txt:22 ../E/sniff.txt:17 ../E/space.txt:23 ../E/string.txt:33 ../E/term.txt:31 ../E/thump.txt:13 ../E/topo.txt:14 ../E/true.txt:5 ../E/turn.txt:33 ../E/type.txt:33 ../E/var.txt:67 ../E/void.txt:11 ../E/wait.txt:22
|
||||
#, no-wrap
|
||||
msgid "<a cbot>Programming</a>, <a cbot|type>types</a> and <a cbot|category>categories</a>."
|
||||
msgstr "<a cbot>Программирование</a>, <a cbot|type>типы</a> и <a cbot|category>категории</a>."
|
||||
|
@ -1178,7 +1178,7 @@ msgid "With the instruction <code>distance( , )</code> you can calculate the dis
|
|||
msgstr "С помощью инструкции <code>distance( , )</code> вы можете подсчитывать расстояние между двумя позициями."
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/build.txt:4 ../E/buildingenabled.txt:4 ../E/canbuild.txt:4 ../E/dist.txt:4 ../E/drop.txt:4 ../E/fire.txt:4 ../E/goto.txt:4 ../E/grab.txt:4 ../E/if.txt:4 ../E/motor.txt:4 ../E/move.txt:4 ../E/radar.txt:4 ../E/turn.txt:4 ../E/wait.txt:4 ../E/while.txt:4
|
||||
#: ../E/build.txt:4 ../E/buildingenabled.txt:4 ../E/canbuild.txt:4 ../E/dist.txt:4 ../E/drop.txt:4 ../E/fire.txt:4 ../E/function.txt:16 ../E/goto.txt:4 ../E/grab.txt:4 ../E/if.txt:4 ../E/motor.txt:4 ../E/move.txt:4 ../E/radar.txt:4 ../E/turn.txt:4 ../E/wait.txt:4 ../E/while.txt:4
|
||||
#, no-wrap
|
||||
msgid "Basic use"
|
||||
msgstr "Основное использование"
|
||||
|
@ -2204,211 +2204,7 @@ msgid "Functions"
|
|||
msgstr "Функции"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:2
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"With functions you can divide your program into several parts, each of them will execute a specific task.\n"
|
||||
"Let's imagine following program¦:"
|
||||
msgstr ""
|
||||
"С помощью функций программу можно разделить на несколько частей, которые будут выполнять каждая свою работу.\n"
|
||||
"Давайте представим следующую программу¦:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:5
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"extern void object::Remote( )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", 1, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 3, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 2, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 4, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"extern void object::Remote( )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", 1, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 3, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 2, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 4, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:17
|
||||
#, no-wrap
|
||||
msgid "<code>send</code> and <code>wait</code> are repeated several times. So it would be a good thing if we created a function that executes these two instructions:"
|
||||
msgstr "<code>send</code> и <code>wait</code> повторяются много раз. Поэтому, мы можем сделать функцию, которая заменит их:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:19
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void object::SendToPost( float op )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", op, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}\n"
|
||||
"extern void object::Remote( )\n"
|
||||
"{\n"
|
||||
"\tSendToPost(1);\n"
|
||||
"\tSendToPost(3);\n"
|
||||
"\tSendToPost(2);\n"
|
||||
"\tSendToPost(4);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"void object::SendToPost( float op )\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", op, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}\n"
|
||||
"extern void object::Remote( )\n"
|
||||
"{\n"
|
||||
"\tSendToPost(1);\n"
|
||||
"\tSendToPost(3);\n"
|
||||
"\tSendToPost(2);\n"
|
||||
"\tSendToPost(4);\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:32
|
||||
#, no-wrap
|
||||
msgid "A function can have paramteters¦:"
|
||||
msgstr "Функции могут иметь параметры¦:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:34
|
||||
#, no-wrap
|
||||
msgid "void Example( int a, float x, string s )"
|
||||
msgstr "void Example( int a, float x, string s )"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:36
|
||||
#, no-wrap
|
||||
msgid "The <code>Example</code> function will reveive un integer <code>a</code>, a floating point number <code>x</code> and a string <code>s</code>. Parameters are \"passed by value\", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an <code>int</code> to a function, its parameter is a copy of whatever value was being passed as argument, and the function can change its parameter value without affecting values in the code that invoked the function."
|
||||
msgstr "Функция <code>Example</code> функция получит целое <code>a</code>, число с плавающей точкой <code>x</code> и строку <code>s</code>. Параметры - это ничто иное, как просто копии значений в переменных. Если вы передадите <code>int</code> функции, то ее параметр станет копией этого значения, т.е. функция сможет изменять эту копию незатрагивая оригинал."
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:38
|
||||
#, no-wrap
|
||||
msgid "If you pass a <a cbot|class>class</a> instance or an <a cbot|array>array</a> as parameter to a function, the function only receives a <a cbot|pointer>reference</a> to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actuallay modified."
|
||||
msgstr "Если вы передадите <a cbot|class>классу</a> массив <a cbot|array>array</a> как параметр функции, то функция получит только <a cbot|pointer>ссылку</a> к экземпляру массива. Это означает, что если вы измените массив в функции, то будет модифицирован только экземпляр этой функции."
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:40
|
||||
#, no-wrap
|
||||
msgid "A function can also return a result with the <code><a cbot|return>return</a></code> instruction. Therefore the function must be declared no longer as void but as a type:"
|
||||
msgstr "Функция может возвращать результат с помощью инструкции <code><a cbot|return>return</a></code>. Поэтому функции должны быть объявлены только как тип:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:42
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Mean( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn (a+b)/2;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Test( )\n"
|
||||
"{\n"
|
||||
"\tfloat value;\n"
|
||||
"\tvalue = Mean(2, 6);\n"
|
||||
"\tmessage( value ); // will display 4\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"float Mean( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn (a+b)/2;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Test( )\n"
|
||||
"{\n"
|
||||
"\tfloat value;\n"
|
||||
"\tvalue = Mean(2, 6);\n"
|
||||
"\tmessage( value ); // will display 4\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:54
|
||||
#, no-wrap
|
||||
msgid "Some other examples¦:"
|
||||
msgstr "Пример¦:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:56
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pi( )\n"
|
||||
"{\n"
|
||||
"\treturn 3.1415;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"string Sign( float a )\n"
|
||||
"{\n"
|
||||
"\tif ( a > 0 ) return \"positive\";\n"
|
||||
"\tif ( a < 0 ) return \"negative\";\n"
|
||||
"\treturn \"null\";\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"float Pi( )\n"
|
||||
"{\n"
|
||||
"\treturn 3.1415;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"string Sign( float a )\n"
|
||||
"{\n"
|
||||
"\tif ( a > 0 ) return \"positive\";\n"
|
||||
"\tif ( a < 0 ) return \"negative\";\n"
|
||||
"\treturn \"null\";\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:68
|
||||
#, no-wrap
|
||||
msgid "You can declare several functions with the same name but different parameters¦:"
|
||||
msgstr "вы также можете объявить несколько функций с одинаковыми именами, но разными параметрами¦:"
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:70
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pythagoras( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float Pythagoras( float a, float b, float c )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
"float Pythagoras( float a, float b )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float Pythagoras( float a, float b, float c )\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
"}"
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:80
|
||||
#, no-wrap
|
||||
msgid "CBOT will call either the one or the other function depending on the paramteres passed."
|
||||
msgstr ""
|
||||
"CBOT будет вызывать ту или иную функцию так, что вызов будет зависеть отт параметров.\n"
|
||||
"Вы также можете объявить функцию <a cbot|public>общедоступной</a>, так что ее смогут использовать остальне боты."
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:82
|
||||
#: ../E/function.txt:118
|
||||
#, no-wrap
|
||||
msgid "You can also declare a function <a cbot|public>public</a> so it can be used by other bots."
|
||||
msgstr ""
|
||||
|
@ -6894,6 +6690,445 @@ msgstr ""
|
|||
msgid "x: <code><a cbot|float>float</a></code> (default value: <code>0</code>)"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:2
|
||||
#, no-wrap
|
||||
msgid "Function, simply put, is an instruction created by you."
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:4
|
||||
#, no-wrap
|
||||
msgid "Main function"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:5
|
||||
#, no-wrap
|
||||
msgid "You probably already know how to create a function. Every program in CBOT must have a main function, which looks like this:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:7
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"extern void object::ProgramName()\n"
|
||||
"{\n"
|
||||
"\t\n"
|
||||
"\t// instructions\n"
|
||||
"\t\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:14
|
||||
#, no-wrap
|
||||
msgid "Nothing but a name can be changed in a main function. The keyword <code>extern</code> distinguish the main function from others."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:17
|
||||
#, no-wrap
|
||||
msgid "With functions you can divide your program into several parts. Each of them will execute a specific task. For example, see the following program:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:19
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"extern void object::Remote()\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", 1, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 3, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 2, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"\tsend(\"order\", 4, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:31
|
||||
#, no-wrap
|
||||
msgid "<code><a cbot|send>send</a></code> and <code><a cbot|wait>wait</a></code> are repeated several times. So it would be a good thing if we created a function that executes these two instructions:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:33
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void SendToPost(float op)\n"
|
||||
"{\n"
|
||||
"\tsend(\"order\", op, 100);\n"
|
||||
"\twait(5);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Remote()\n"
|
||||
"{\n"
|
||||
"\tSendToPost(1);\n"
|
||||
"\tSendToPost(3);\n"
|
||||
"\tSendToPost(2);\n"
|
||||
"\tSendToPost(4);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:49
|
||||
#, no-wrap
|
||||
msgid "Syntax"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:56
|
||||
#, no-wrap
|
||||
msgid "A function must be declared above the main function. Result <a cbot|type>type</a> should be <a cbot/void>void</a> if the function does not give any. Body is just a set of instructions. Function name must be created with the exact same rules applied to <a cbot|var>variables</a>."
|
||||
msgstr ""
|
||||
|
||||
#. type: \t; header
|
||||
#: ../E/function.txt:58
|
||||
#, no-wrap
|
||||
msgid "Parameters"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:59
|
||||
#, no-wrap
|
||||
msgid "A function can have parameters:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:68
|
||||
#, no-wrap
|
||||
msgid "The <code>Example</code> function will receive an <a cbot|int>integer</a> <code>a</code>, a <a cbot|float>floating point number</a> <code>x</code> and a <a cbot|string>string</a> <code>s</code>. Parameters are \"passed by value\", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an <code><a cbot|int>int</a></code> to a function, its parameter is a copy of whatever value was being passed as the argument, and the function can change its parameter value without affecting values in the code that invoked the function."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:70
|
||||
#, no-wrap
|
||||
msgid "If you pass a <a cbot|class>class</a> instance or an <a cbot|array>array</a> as parameter to a function, the function only receives a <a cbot|pointer>reference</a> to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actually modified."
|
||||
msgstr ""
|
||||
|
||||
#. type: \t; header
|
||||
#: ../E/function.txt:72
|
||||
#, no-wrap
|
||||
msgid "Result"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:73
|
||||
#, no-wrap
|
||||
msgid "A function can also return a result with the <code><a cbot|return>return</a></code> instruction. Therefore the function must be declared no longer as <code><a cbot|void>void</a></code> but as an other <a cbot|type>type</a>:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:75
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Average(float a, float b)\n"
|
||||
"{\n"
|
||||
"\treturn (a+b)/2;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"extern void object::Test( )\n"
|
||||
"{\n"
|
||||
"\tfloat value;\n"
|
||||
"\tvalue = Average(2, 6);\n"
|
||||
"\tmessage(value); // will display 4\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:87
|
||||
#, no-wrap
|
||||
msgid "Some other examples:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:89
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pi()\n"
|
||||
"{\n"
|
||||
"\treturn 3.1415;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"string Sign(float a)\n"
|
||||
"{\n"
|
||||
"\tif (a > 0) return \"positive\";\n"
|
||||
"\tif (a < 0) return \"negative\";\n"
|
||||
"\treturn \"null\";\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:102
|
||||
#, no-wrap
|
||||
msgid "Overloading"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:103
|
||||
#, no-wrap
|
||||
msgid "You can declare several functions with the same name but different parameters:"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:105
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"float Pythagoras(float a, float b)\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float Pythagoras(float a, float b, float c)\n"
|
||||
"{\n"
|
||||
"\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:115
|
||||
#, no-wrap
|
||||
msgid "CBOT will call either the one or the other function depending on the parameters passed. They must be distinguishable, i.e. you can't declare two functions with the same name and parameter types in the exact same order, e.g. declaring <code>int Pythagoras(float b, float a)</code> will result in error. Note that result type does not matter."
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:117
|
||||
#, no-wrap
|
||||
msgid "Public functions"
|
||||
msgstr ""
|
||||
|
||||
#. type: \b; header
|
||||
#: ../E/function.txt:120
|
||||
#, no-wrap
|
||||
msgid "object::"
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:121
|
||||
#, no-wrap
|
||||
msgid "Declaring a function as a part of the <a cbot|object>object</a> namespace gives it access to <code><a cbot|this>this</a></code> <a cbot|pointer>pointer</a>, in other words, to all available properties of the robot which the program is run on."
|
||||
msgstr ""
|
||||
|
||||
#. type: Plain text
|
||||
#: ../E/function.txt:47
|
||||
#, no-wrap
|
||||
msgid "Now the program is much easier to read. It is a good practice to split the program into several functions with self-describing names."
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:51
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"result_type FunctionName(optional_parameters)\n"
|
||||
"{\n"
|
||||
"\tbody\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:61
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void Example(int a, float x, string s)\n"
|
||||
"{\n"
|
||||
"\tmessage(a);\n"
|
||||
"\tmessage(x);\n"
|
||||
"\tmessage(s);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#. type: Source code
|
||||
#: ../E/function.txt:123
|
||||
#, no-wrap
|
||||
msgid ""
|
||||
"void object::Example()\n"
|
||||
"{\n"
|
||||
"\tmessage(this.category);\n"
|
||||
"}"
|
||||
msgstr ""
|
||||
|
||||
#~ msgid "Now the program is much easier to read. It's a good practice to split the program into several functions with self-describing names."
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "result_type FunctionName(optional_parameters)\n"
|
||||
#~ "{\n"
|
||||
#~ " body\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "void Example(int a, float x, string s)\n"
|
||||
#~ "{\n"
|
||||
#~ " message(a);\n"
|
||||
#~ " message(x);\n"
|
||||
#~ " message(s);\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
|
||||
#~ msgid ""
|
||||
#~ "With functions you can divide your program into several parts, each of them will execute a specific task.\n"
|
||||
#~ "Let's imagine following program¦:"
|
||||
#~ msgstr ""
|
||||
#~ "С помощью функций программу можно разделить на несколько частей, которые будут выполнять каждая свою работу.\n"
|
||||
#~ "Давайте представим следующую программу¦:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "extern void object::Remote( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", 1, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 3, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 2, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 4, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "extern void object::Remote( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", 1, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 3, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 2, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "\tsend(\"order\", 4, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "<code>send</code> and <code>wait</code> are repeated several times. So it would be a good thing if we created a function that executes these two instructions:"
|
||||
#~ msgstr "<code>send</code> и <code>wait</code> повторяются много раз. Поэтому, мы можем сделать функцию, которая заменит их:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "void object::SendToPost( float op )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", op, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}\n"
|
||||
#~ "extern void object::Remote( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tSendToPost(1);\n"
|
||||
#~ "\tSendToPost(3);\n"
|
||||
#~ "\tSendToPost(2);\n"
|
||||
#~ "\tSendToPost(4);\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "void object::SendToPost( float op )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tsend(\"order\", op, 100);\n"
|
||||
#~ "\twait(5);\n"
|
||||
#~ "}\n"
|
||||
#~ "extern void object::Remote( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tSendToPost(1);\n"
|
||||
#~ "\tSendToPost(3);\n"
|
||||
#~ "\tSendToPost(2);\n"
|
||||
#~ "\tSendToPost(4);\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "A function can have paramteters¦:"
|
||||
#~ msgstr "Функции могут иметь параметры¦:"
|
||||
|
||||
#~ msgid "void Example( int a, float x, string s )"
|
||||
#~ msgstr "void Example( int a, float x, string s )"
|
||||
|
||||
#~ msgid "The <code>Example</code> function will reveive un integer <code>a</code>, a floating point number <code>x</code> and a string <code>s</code>. Parameters are \"passed by value\", that is the values of parameter variables in a function are copies of the values the caller specified as variables. If you pass an <code>int</code> to a function, its parameter is a copy of whatever value was being passed as argument, and the function can change its parameter value without affecting values in the code that invoked the function."
|
||||
#~ msgstr "Функция <code>Example</code> функция получит целое <code>a</code>, число с плавающей точкой <code>x</code> и строку <code>s</code>. Параметры - это ничто иное, как просто копии значений в переменных. Если вы передадите <code>int</code> функции, то ее параметр станет копией этого значения, т.е. функция сможет изменять эту копию незатрагивая оригинал."
|
||||
|
||||
#~ msgid "If you pass a <a cbot|class>class</a> instance or an <a cbot|array>array</a> as parameter to a function, the function only receives a <a cbot|pointer>reference</a> to the instance or the array. That means if you modify the instance or the array in the function, the instance or the array that has been specified by the caller will be actuallay modified."
|
||||
#~ msgstr "Если вы передадите <a cbot|class>классу</a> массив <a cbot|array>array</a> как параметр функции, то функция получит только <a cbot|pointer>ссылку</a> к экземпляру массива. Это означает, что если вы измените массив в функции, то будет модифицирован только экземпляр этой функции."
|
||||
|
||||
#~ msgid "A function can also return a result with the <code><a cbot|return>return</a></code> instruction. Therefore the function must be declared no longer as void but as a type:"
|
||||
#~ msgstr "Функция может возвращать результат с помощью инструкции <code><a cbot|return>return</a></code>. Поэтому функции должны быть объявлены только как тип:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "float Mean( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn (a+b)/2;\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "extern void object::Test( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tfloat value;\n"
|
||||
#~ "\tvalue = Mean(2, 6);\n"
|
||||
#~ "\tmessage( value ); // will display 4\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "float Mean( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn (a+b)/2;\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "extern void object::Test( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tfloat value;\n"
|
||||
#~ "\tvalue = Mean(2, 6);\n"
|
||||
#~ "\tmessage( value ); // will display 4\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "Some other examples¦:"
|
||||
#~ msgstr "Пример¦:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "float Pi( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn 3.1415;\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "string Sign( float a )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tif ( a > 0 ) return \"positive\";\n"
|
||||
#~ "\tif ( a < 0 ) return \"negative\";\n"
|
||||
#~ "\treturn \"null\";\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "float Pi( )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn 3.1415;\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "string Sign( float a )\n"
|
||||
#~ "{\n"
|
||||
#~ "\tif ( a > 0 ) return \"positive\";\n"
|
||||
#~ "\tif ( a < 0 ) return \"negative\";\n"
|
||||
#~ "\treturn \"null\";\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "You can declare several functions with the same name but different parameters¦:"
|
||||
#~ msgstr "вы также можете объявить несколько функций с одинаковыми именами, но разными параметрами¦:"
|
||||
|
||||
#~ msgid ""
|
||||
#~ "float Pythagoras( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b));\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "float Pythagoras( float a, float b, float c )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
#~ "}"
|
||||
#~ msgstr ""
|
||||
#~ "float Pythagoras( float a, float b )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b));\n"
|
||||
#~ "}\n"
|
||||
#~ "\n"
|
||||
#~ "float Pythagoras( float a, float b, float c )\n"
|
||||
#~ "{\n"
|
||||
#~ "\treturn sqrt((a*a)+(b*b)+(c*c));\n"
|
||||
#~ "}"
|
||||
|
||||
#~ msgid "CBOT will call either the one or the other function depending on the paramteres passed."
|
||||
#~ msgstr ""
|
||||
#~ "CBOT будет вызывать ту или иную функцию так, что вызов будет зависеть отт параметров.\n"
|
||||
#~ "Вы также можете объявить функцию <a cbot|public>общедоступной</a>, так что ее смогут использовать остальне боты."
|
||||
|
||||
#~ msgid "x: <code><a cbot|float>float</a></code> (default value: <code>0</code>);"
|
||||
#~ msgstr ""
|
||||
|
||||
|
|
Loading…
Reference in New Issue