C2G: Difference between revisions

1,319 bytes added ,  2 June 2021
no edit summary
No edit summary
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 189: Line 189:
=== Entry choices ===
=== Entry choices ===


If a level has several [[Player character]]s, C2G scripting can be used to set the player which will appear based on conditions.
If a level has several [[Player character]]s, C2G scripting can be used to force only one player to appear, and set which player appears based on conditions.


Players are numbered in reading order, starting at 1; there does not appear to be any limit. In order to use the feature, before calling the "map" of the level containing the players, the "enter" variable must be set, for example:
Players are numbered in reading order, starting at 1; there does not appear to be any limit. In order to use the feature, before calling the "map" of the level containing the players, the "enter" variable must be set, for example:
Line 198: Line 198:
map UltimatePain.c2m</nowiki>
map UltimatePain.c2m</nowiki>


In the above example, with about 50% chance, the second players will appear in the level UltimatePain.c2m instead of the first one.
In the above example, with about 50% chance, the second player will appear in the level UltimatePain.c2m instead of the first one.


CC2 crashes if "enter" is set to a value which does not lead to a player.
CC2 crashes if "enter" is set to a value which does not lead to a player. Make sure to reset enter to 0 where necessary!


=== Exit choices ===
=== Exit choices ===
Line 218: Line 218:
script
script
"This is the end."</nowiki>
"This is the end."</nowiki>
In the example above, the game will load the level stored in the file ChooseYourFuture.c2m; if the player exits using the first exit in reading order, the game will then display the THIS IS THE END. message. If the player exits using the second exit, however, the game will load the level in the file SuperSecretFinalLevel.c2m instead, and the THIS IS THE END message will be displayed after the level has been solved.
In the example above, the game will load the level stored in the file ChooseYourFuture.c2m; if the player exits using the first exit in reading order, the game will then display the THIS IS THE END message. If the player exits using the second exit, however, the game will load the level in the file SuperSecretFinalLevel.c2m instead, and the THIS IS THE END message will be displayed after the level has been solved.


If there are several players in the level, the exit used by the last player to finish the level will be the one used by the C2G script. If an invalid label is called, or no label is assigned for the exit that was used, the game will continue to work through the C2G file as it would normally.
If there are several players in the level, the exit used by the last player to finish the level will be the one used by the C2G script. If an invalid label is called, or no label is assigned for the exit that was used, the game will continue to work through the C2G file as it would normally.
Line 247: Line 247:
map "Normal.c2m"</nowiki>
map "Normal.c2m"</nowiki>
In the example above, Normal.c2m will be level 9.
In the example above, Normal.c2m will be level 9.
No matter how your level numbering is set up, completing a level will always briefly display the current level as being its previous value + 1. This is unavoidable.


=== Speed ===
=== Speed ===
Line 274: Line 276:


=== Chaining ===
=== Chaining ===
Scripts can be "chained" using the chain directive. This can be useful for compartmentalizing long scripts associated with particular levels.
Scripts can be "chained" using the chain directive; immediately stopping the parsing of the current script and starting again on the first line of the chained script. This can be useful for compartmentalizing long scripts associated with particular levels.
  <nowiki>chain "anotherscript.c2g"</nowiki>
  <nowiki>chain "anotherscript.c2g"</nowiki>


Line 281: Line 283:
Note that if the first c2g file CC2 reads chains to another script but does not provide a map itself, CC2 will say the levelset is invalid. This is because it specifically checks the first c2g it reads for the use of "map" followed by a valid map. To avoid this, put a valid map ''after'' calling the chain, such that it will never be accessed since the parser will be chained away from the script before reaching it.
Note that if the first c2g file CC2 reads chains to another script but does not provide a map itself, CC2 will say the levelset is invalid. This is because it specifically checks the first c2g it reads for the use of "map" followed by a valid map. To avoid this, put a valid map ''after'' calling the chain, such that it will never be accessed since the parser will be chained away from the script before reaching it.


=== Level flags ===
Variables reg1 to reg4 can be used to store arbitrary flags, will be stored between chained scripts, and will be included in the player's save data. Here, a "switch palace" level includes two exits, the second of which sets the lowest bit in reg4 to 1, which the script then detects to swap out a later level for an alternate version:
<nowiki>map "SwitchPalace.c2m"
1 exit == do goto #afterpalace
script
"You touched the switch!"
"This will swap some"
"walls and floors in"
"a future level"
1 reg4 | reg4 =
#afterpalace
map "BoringLevel.c2m"
map "NormalLevel.c2m"
map "GreatLevel.c2m"
1 reg4 && do goto #switchon
#switchoff
map "AwesomeLevel.c2m"
goto #afterawesome
#switchon
map "AwesomeLevelAlt.c2m"
#afterawesome
map "OkayLevel.c2m"</nowiki>
Unused bits of the "flags" variable itself are also available, but flipping them is unadvised, as, theoretically, future updates to CC2 could add new purposes to unused flags at any moment.


== Comments box ==
== Comments box ==
trusted-editors
331

edits