====== Code Type ======
A Code value is a character string used specifically to hold source code — the Python or R script run by [[Calculate Python Expression]] and [[Calculate R Expression]], for instance. It's a distinct type from [[String Type|String]] rather than a subtype of it: moving between the two goes through an ordinary registered conversion, which is what lets the interface present a dedicated code editor for Code inputs instead of the plain text field used for String.
===== GUI Editor =====
[{{ :editors:code_editor.png?nolink |Graphical representation of the code editor}}]
The code editor presents a larger, code-oriented text area suited to writing multi-line source, rather than the single-line field used for a String.
===== EGO Script =====
Code Type has no literal syntax of its own. A Code value is stored as base64 in the underlying script, which makes it impractical to write directly — instead, a Code constant is always represented as a base64-encoded [[String Type|String]] literal, converted to Code automatically by the ''String → Code'' conversion. This is why a Code value in a script always appears as this conversion rather than as a direct literal. Base64 lets the encoded source keep any characters, quoting, or exact whitespace and line breaks without needing to escape anything for the script's own text syntax:
"aW1wb3J0IG51bXB5IGFzIG5wCmRpbmFtaWNhLm91dHB1dHNbJ3Jlc3VsdCddID0gbnAubWVhbihbMSwgMiwgM10p"
Decoded, this represents:
import numpy as np
dinamica.outputs['result'] = np.mean([1, 2, 3])
Because of this, Code constants are normally produced by the GUI rather than typed by hand — writing or editing the base64 text manually risks introducing invalid base64, which the conversion below rejects.
===== Automatic Conversions =====
* **Converted from**: [[String Type]] — can fail; the string must be valid base64. This is most likely to happen if the text was written or edited by hand rather than generated by the GUI.
* **Converted to**: [[String Type]] — the Code value is base64-encoded.
See [[type_system|Type System]] for the complete conversion reference across all types.