From 791d7046feae0f5b454ef93adf2d58b3558fbd0d Mon Sep 17 00:00:00 2001 From: RayPals Date: Mon, 1 Jun 2026 00:53:54 +0200 Subject: [PATCH] Add docs/V1_15_OBJECTS_CLASSES.md from Claro v1.17.26 zip --- docs/V1_15_OBJECTS_CLASSES.md | 76 +++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 docs/V1_15_OBJECTS_CLASSES.md diff --git a/docs/V1_15_OBJECTS_CLASSES.md b/docs/V1_15_OBJECTS_CLASSES.md new file mode 100644 index 0000000..feccced --- /dev/null +++ b/docs/V1_15_OBJECTS_CLASSES.md @@ -0,0 +1,76 @@ +# Claro v1.15.26 Objects and Classes + +Claro objects are meant to stay plain and readable. Learners can start with variables and functions, then grow into classes when they are ready. + +## Basic class + +```claro +CLASS Player + HAS name TEXT + HAS score NUMBER +END + +NEW Player player +SET player.name "Jon" +SET player.score 10 + +SAY player.name +SAY player.score +``` + +## Methods + +Methods are taught with the same `TEACH` word used for normal functions. + +```claro +CLASS Player + HAS name TEXT + HAS score NUMBER + + TEACH show + SAY name + SAY score + END + + TEACH add points + SET score score + points + END +END + +NEW Player player +SET player.name "Jon" +SET player.score 10 + +DO player.show +DO player.add 5 +SAY player.score +``` + +Inside a method, class fields such as `name` and `score` are available directly. + +## Typed fields + +Fields can have simple Claro types: + +```claro +HAS name TEXT +HAS score NUMBER +HAS ready YESNO +``` + +When an object is created, Claro creates default field values and remembers their types. This means an accidental bad value can be caught: + +```claro +SET player.score "oops" +``` + +will fail because `score` is a `NUMBER` field. + +## Object helper commands + +```claro +OBJECT CLASS player AS kind +OBJECT FIELDS player AS fields +``` + +These are useful for teaching and debugging.