C2G: Difference between revisions

772 bytes added ,  21 May 2021
no edit summary
No edit summary
No edit summary
Line 278: Line 278:
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.
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>
  <nowiki>chdir "anotherdirectory\"
  <nowiki>chdir "anotherdirectory\"
chain "scriptinanotherdirectory.c2g"</nowiki>
chain "scriptinanotherdirectory.c2g"</nowiki>
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.
=== Registers ===
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 the next 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>


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

edits