Cog Quiz

Week 3 - Answer

Prev - Exit - Next

Show Quiz

Level 1

As "for" is explained here, it repeats the commands inside the routine several times. In this case the "for" loop will start from 0 and goes up to 5, but there's a small line saying

   if(i == 2) i = 4;

Which means when "i" becomes 2 for the third loop, it will turn itself to 4. Thus the result will be "0", "1", "2", "5" printed out in a row.


Level 2

One of the most efficient way to shorten and simplify some lines in cog is using arrays.

As shown in the quiz "i" is placed as "[i]" after "sound0" which adds the value as a part of the variable. In this case, if "i" was 0, then "sound0[i]" will be same as "sound0", while if "i" was 1, then "sound0[i]" will be same as "sound1".

The result will be sounds "sound0", "sound1", "sound2" declared in the symbols section be played in a row.


Level 3

As arrays are very useful, do not try to place any operators inside arrays, as it will not always work in cogs. A workaround can be to make the operators as a variable before the array lines. For example do this.

   soundID = GetNumPlayers() + 4 * 2;
   PlaySoundThing(sounds0[soundID], player, 1, -1, -1, 0);