Let us make a Boop that gives two people a random challenge. It needs one Sugar text and no variables.
Set up the Boop
Create a Boop and set its participant count to 2. This tells JOI that the Boop needs the person using it and one other person.
Paste this into the Boop’s Code editor:
text "@1 challenges @2 to {}." with Rand::pick("tell a secret", "send a saved photo", "answer one honest question");
A possible result is:
Run it again and Sugar may choose a different challenge.
Read the text piece by piece
text declares one possible message. The quotation marks contain the parts that should appear exactly as written.
@1 is the person using the Boop. @2 is the other participant.
This part asks Sugar to choose one value:
Rand::pick("tell a secret", "send a saved photo", "answer one honest question")
Rand is a group of random tools called a namespace. The :: symbol accesses pick() inside that group. A later lesson teaches functions and namespaces from the beginning; here, you only need to replace the quoted choices.
The empty braces {} mark the place where the chosen challenge appears. with supplies the value for that place. The semicolon ; finishes the declaration.
Change it into your Boop
Replace the three challenges with options that fit your idea. Keep quotation marks around each option and commas between them.
For example:
text "@1 gives @2 {}." with Rand::pick("a kiss", "a playful bite", "a tight hug");
Try it before publishing
Press Run in the Boop editor. Add names for both participants and run it several times.
The test does not post anything. When the text reads the way you want, save the Boop.
You now know the basic shape of a Sugar text. The course will explain values, variables, comparisons, and longer programs before asking you to write them.