home *** CD-ROM | disk | FTP | other *** search
/ Revista CD Expert 51 / PCGamer51_17Demos.iso / games / colobotdemo / colobotdemo10e.exe / help / Ttit2.TXT < prev    next >
Text File  |  2001-06-29  |  4KB  |  52 lines

  1. \b;Objective
  2. Take a chunk of \l;titanium ore\u object\titanore; the exact location of which we do not know. Use the bot's radar to find it. Bring the titanium ore to the \l;converter\u object\convert;.
  3.  
  4. \t;Program
  5. As you have certainly noticed, the programs written in the previous exercises were completely "blind": if the titanium ore, the power cell or the spiders had been at another location, the bot would not have found them.
  6.  
  7. The radar represents the "eyes" of the bot. With the radar, it can detect the objects around it. For example the instruction \c;\l;radar\u cbot\radar;(TitaniumOre);\n; will return information about the closest chunk of \l;titanium ore\u object\titanore;. However, we will have to "store" the information returned by the instruction \c;\l;radar\u cbot\radar;(TitaniumOre);\n; somewhere. For this task we will need a \l;variable\u cbot\var;.
  8.  
  9. A \l;variable\u cbot\var; is like a small box with a name where you can put some information, retrieve it, change it, etc. Before you can use a variable, you have got to declare it. First you must indicate the \l;type\u cbot\type; of the variable, in this case \c;object\n;. A variable of this type can contain all the information describing an object such as a chunk of titanium ore, a spider, an ant, a bot, a power cell, etc. Then you must write the name that you want to give to the variable, for example \c;item\n;. If we put this together, we get the following line:
  10. \c;
  11. \s;\l;object\u cbot\type; item;
  12. \n;
  13. Then we must put the information returned by the instruction \c;\l;radar\u cbot\radar;(TitaniumOre)\n; into this variable:
  14. \c;
  15. \s;item = \l;radar\u cbot\radar;(TitaniumOre);
  16. \n;
  17. The variable \c;item\n; contains many different kinds of information: it contains the position, the orientation, the pitch, etc. In order to get the position of the chunk of titanium ore, write \c;item.position\n;. Then we use the instruction \c;goto();\n; in order to move the bot to this position. Here is a line that puts all this together:
  18. \c;
  19. \s;\l;goto\u cbot\goto;(item.position);
  20. \n;
  21. If we "translate" this into English, this would mean: go to the position of the object described by the variable \c;item\n;.
  22.  
  23. You can then just pick up what is at this position with the instruction \c;\l;grab\u cbot\grab;();\n;.
  24.  
  25. If we put all this together, we get the following program:
  26. \c;
  27. \s;extern void object::Titanium2( )
  28. \s;{
  29. \s;    
  30. \s;    \l;object\u cbot\type; item;
  31. \s;    item = \l;radar\u cbot\radar;(TitaniumOre);
  32. \s;    \l;goto\u cbot\goto;(item.position);
  33. \s;    grab();
  34. \s;    
  35. \s;}
  36. \n;
  37. Then you must look for the \l;converter\u cbot\convert;, and put the information about the converter into the variable \c;item\n;:
  38. \c;
  39. \s;item = \l;radar\u cbot\radar;(Converter);
  40. \n;
  41. Go to the converter with the same instruction \c;\l;goto\u cbot\goto;(item.position);\n; as above, drop the titanium, and step back. The converter will take care of the rest.
  42.  
  43. If you want to know more about the "names" of the different objects in the programming language, please refer to the \l;text about categories\u cbot\category;.
  44.  
  45. \t;Remarks
  46. A \l;variable\u cbot\var; must be declared only once at the beginning of the program! You can then use it as often as you want.
  47.  
  48. In order to avoid retyping the instructions explained above, you can select them with the mouse, and copy-paste \button 61; them into your program.
  49.  
  50. \t;See also
  51. \l;Programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.
  52.