Skip to content

Commit

Permalink
feat(examples): add Creator-Defined Statements (CDS)
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Aug 28, 2024
1 parent 90b94c4 commit bbc9ad6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
30 changes: 30 additions & 0 deletions game/examples/_creator_defined_statements.rpy
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# https://www.renpy.org/doc/html/cds.html
python early:
def parse_random(lexer):
subblock_lexer = lexer.subblock_lexer()
choices = []

while subblock_lexer.advance():
with subblock_lexer.catch_error():
statement = subblock_lexer.renpy_statement()
choices.append(statement)

return choices


def next_random(choices):
return renpy.random.choice(choices)


def lint_random(parsed_object):
for i in parsed_object:
renpy.error(renpy.check_text_tags(i.what))


renpy.register_statement(
name="random",
block=True,
parse=parse_random,
next=next_random,
lint=lint_random,
)
9 changes: 9 additions & 0 deletions game/examples/creator_defined_statements.rpy
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
label creator_defined_statements:

# see `game/examples/_creator_defined_statements.rpy`
random:
"Hello."
"Welcome."
"Can I help you?"

jump start
3 changes: 3 additions & 0 deletions game/examples/start.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ label start:
menu:
"Which example do you want to see?"

"Creator-Defined Statements (CDS)":
jump creator_defined_statements

"Dialogue":
jump dialogue

Expand Down

0 comments on commit bbc9ad6

Please sign in to comment.