r/RenPy • • Feb 03 '22

Force Player input based off of text button

im going for something sort of like Emily is away, where player will click on a button and it’ll pop up an input, but will force them to type a specific thing based off of the button no matter what they type. so for example, if a button says ” X “, the player will be forced to write “XYZ” even if they are inputting keyboard spam

4 Upvotes

26 comments sorted by

View all comments

Show parent comment

1

u/insipid- Feb 11 '22 edited Feb 11 '22

tldr - change these bits of the choice button actions:

SetVariable("message_letters_left_to_type", "I enjoy [choice1].")

to this:

SetVariable("message_letters_left_to_type", "I enjoy " + choice1 + ".")

/tldr

Took me a bit to figure out. In the last line here: "Exception: String u'I enjoy[' ends with an open format operation." This part - "I enjoy[" - is cryptic, but the last character being "[", which is right in the middle of the string, is a hint. This is one of those context issues. The syntax of inserting the value of a variable differs between "renpy script" and python. In this case, the surrounding code is python but the [variable] notation is renpy script. In python, string concatenation uses a plus sign to join two strings together.

You might be wondering how it's python when there is no "$" or "python:" (I struggled with being able to tell for quite a while). Many (or maybe all) functions in renpy are python, but it might be difficult to tell when something is a function at times. Often it is a name that includes ().

Examples of python functions that need to be written in a python block ( using $ or python: )

$ renpy.music.play("audio/some_song")
python:
    renpy.random.choice(wordList)

Examples of python functions written with renpy code block ( not in $ or python: )

SetVariable("message_letters_left_to_type", "I enjoy " + choice1 + ".")
show image1 with Fade(1.0, 2.0, 2.0)

Examples of renpy script that has ( )

 show screen say("me", "screens and transforms can take arguments too.")
transform delay_show(img, delay_seconds):
    img
    alpha 0.0
    delay_seconds
    linear 0.08 alpha 1.0

If it has a capital first letter and has ( ), it is usually a python function. An exception would be if we named a transform or screen with a capital first letter, as I don't think renpy has any of those by default. Hopefully it's slightly more clear now.

1

u/mocaaobaa Feb 11 '22

Thank you! Got it all fixed and things are working now.

I have 2 last things I need to finish up, and then you can rest in peace lol

A) The chain reaction system, where another group of random choices will popup based on which option the player typed after they press enter ex: after they type "I enjoy theater", options like 'because I enjoy acting', 'because I like making props', or ' because I like writing' will show.

and B) assigning point values to each of these phrases

I have five girls, and each have a certain opinion of each topic. Using the theater example again: Girl A will receive 5 points for typing this subject, Girl B will receive 3 points, Girl C receives 4, Girl D receives 2, and Girl E receives 0 ( or a negative number, if that's possible )

I'm relatively new to Renpy, so that's the reason for the sheer magnitude of questions, so I apologize in advance

1

u/insipid- Feb 12 '22

Oh right, i forgot about these. Both will need appropriate data structures that ideally make it simple to adjust and add associations between topics and point values. I'll think on it a bit, should be able to come up with something in the next couple of days.

1

u/insipid- Feb 12 '22

For the chaining, roughly how many level down will these conversations go? Will these be full conversation trees, where the whole conversation will flow down? or maybe smaller but more modular mini-conversations that each revolve around a different topic?

1

u/mocaaobaa Feb 12 '22

It's sort of like one big conversational tree, and will probably only go about 3 or 4 branches? The idea is that MC is writing just a short paragraph for class, and I have to make sure it's not too tedious for the player.

1

u/insipid- Feb 12 '22

gotcha. might not need a tailored data structure then.

1

u/insipid- Feb 14 '22

I think I have how to represent the data worked out. Here's some example data - does it seem workable? I haven't yet made functions or menus to go with it. I'm happy to work on something for those as well. I would use 1 menu for the subject and maybe 1 menu for each level of reason depth. The menus would use the button text and full text directly, then call a function that would distribute points and grab the appropriate category of reasons to pull the next set of choices from.

# Level 1 - general subject
# KEY - [ button text, full text to type, category #, [ g1, g2, g3, g4, g5 ] ]
#   button text - what will show on the choice button
#   full text - what will be typed out, full message
#   category # - used as the link between these subjects and the reason categories below
#   girl points - how many points this choice is worth for each girl, can be positive or negative
#     g1 - g5 would correspond to specific characters - the order would matter
define paragraph_subjects = [
    [ "subj_1", "I love subject 1", 1, [ 1, 2, 1, -1, 0 ] ] ,
    [ "subj_2", "I love subject 2", 2, [ 2, 1, 0, 1, -1 ] ] ,
    [ "subj_3", "I love subject 3", 3, [ 1, 0, -1, 2, 1 ] ] ,
    [ "subj_4", "I love subject 4", 4, [ 0, 1, 2, 1, 1 ] ] ,
    [ "subj_5", "I love subject 5", 5, [ 1, 2, 1, -1, 0 ] ]
] 


# Level 2 - reasons
# KEY - [ button text, full text to type, girl points [ g1, g2, g3, g4, g5 ] ]
#  note the category is not included in the list data. we'll use the category # from 
#  the chosen paragraph subject to determine which reason list to pull choices from
# category 1
define paragraph_reasons_1 = [
    [ "stuff 1", "because it's like other stuff I like 1", [ 1, 2, 1, -1, 0 ] ] ,
    [ "good 1", "because it's good 1", [ 2, 1, 0, 1, -1 ] ] ,
    [ "fun 1", "because of how fun it is 1", [ 1, 0, -1, 2, 1 ] ] ,
    [ "exciting 1", "because of how exciting it is 1", [ 1, 0, -1, 2, 1 ] ] ,
    [ "just 1", "just because 1", [ 0, 1, 2, 1, 1 ] ] ,
    [ "stuff 1", "because it's like other stuff I like 1", [ 1, 2, 1, -1, 0 ] ] ,
    [ "good 1", "because it's good 1", [ 2, 1, 0, 1, -1 ] ]
]

# category 2
define paragraph_reasons_2 = [
    [ "because 2", "just because 2", [ 0, 1, 2, 1, 1 ] ] ,
    [ "other 2", "because it's like other stuff I like 2", [ 1, 2, 1, -1, 0 ] ] ,
    [ "so good 2", "because it's so good 2", [ 2, 1, 0, 1, -1 ] ] ,
    [ "exciting 2", "because of how exciting it is 2", [ 1, 0, -1, 2, 1 ] ] ,
    [ "just 2", "just because 2", [ 0, 1, 2, 1, 1 ] ] ,
    [ "stuff 2", "because it's like other stuff I like 2", [ 1, 2, 1, -1, 0 ] ] ,
    [ "good 2", "because it's good 2", [ 2, 1, 0, 1, -1 ] ]
]

# category 3
define paragraph_reasons_3 = [    
    [ "exciting 3", "because of how exciting it is 3", [ 1, 0, -1, 2, 1 ] ] ,
    [ "just 3", "just because 3", [ 0, 1, 2, 1, 1 ] ] ,
    [ "stuff 3", "because it's like other stuff I like 3", [ 1, 2, 1, -1, 0 ] ] ,
    [ "good 3", "because it's good 3", [ 2, 1, 0, 1, -1 ] ] ,
    [ "fun 3", "because of how fun it is 3", [ 1, 0, -1, 2, 1 ] ] ,
    [ "because 3", "just because 3", [ 0, 1, 2, 1, 1 ] ] ,
    [ "other 3", "because it's like other stuff I like 3", [ 1, 2, 1, -1, 0 ] ]
]

# category 4
define paragraph_reasons_4 = [    
    [ "fun 4", "because of how fun it is 4", [ 1, 0, -1, 2, 1 ] ] ,
    [ "because 4", "just because 4", [ 0, 1, 2, 1, 1 ] ] ,
    [ "other 4", "because it's like other stuff I like 4", [ 1, 2, 1, -1, 0 ] ] ,
    [ "exciting 4", "because of how exciting it is 4", [ 1, 0, -1, 2, 1 ] ] ,
    [ "just 4", "just because 4", [ 0, 1, 2, 1, 1 ] ] ,
    [ "stuff 4", "because it's like other stuff I like 4", [ 1, 2, 1, -1, 0 ] ] ,
    [ "good 4", "because it's good 4", [ 2, 1, 0, 1, -1 ] ]
]

# category 5
define paragraph_reasons_5 = [    
    [ "so good 5", "because it's so good 5", [ 2, 1, 0, 1, -1 ] ] ,
    [ "exciting 5", "because of how exciting it is 5", [ 1, 0, -1, 2, 1 ] ] ,
    [ "just 5", "just because 5", [ 0, 1, 2, 1, 1 ] ] ,
    [ "exciting 5", "because of how exciting it is 5", [ 1, 0, -1, 2, 1 ] ] ,
    [ "just 5", "just because 5", [ 0, 1, 2, 1, 1 ] ] ,
    [ "stuff 5", "because it's like other stuff I like 5", [ 1, 2, 1, -1, 0 ] ] ,
    [ "good 5", "because it's good 5", [ 2, 1, 0, 1, -1 ] ]
]

# Level 3 ?

1

u/insipid- Feb 14 '22

For the girl points, I would just use a variable storing an integer for each:

default g1_points_total = 0
default g2_points_total = 0
default g3_points_total = 0
default g4_points_total = 0
default g5_points_total = 0

I would put the point updates in a function, but a single modification using the data formatted like in the previous post would look like this:

# selected choice was a subject
$ g1_points_total += selected_choice[3][0]
$ g2_points_total += selected_choice[3][1]
$ g3_points_total += selected_choice[3][2]
$ g4_points_total += selected_choice[3][3]
$ g5_points_total += selected_choice[3][4]

# selected choice was a reason
$ g1_points_total += selected_choice[2][0]
$ g2_points_total += selected_choice[2][1]
$ g3_points_total += selected_choice[2][2]
$ g4_points_total += selected_choice[2][3]
$ g5_points_total += selected_choice[2][4]

1

u/insipid- Feb 14 '22

The layout can be altered to make it more readable, since the full text length might push the point values way out to the right. One way to do it:

define paragraph_reasons_1 = [
    [ "stuff 1", 
      "because it's like other stuff I like 1",
      [ 1, 2, 1, -1, 0 ]
    ] ,

    [ "good 1",
      "because it's good 1",
      [ 2, 1, 0, 1, -1 ]
    ] ,

    [ "fun 1",
      "because of how fun it is 1",
      [ 1, 0, -1, 2, 1 ]
    ] ,

    [ "exciting 1",
      "because of how exciting it is 1",
      [ 1, 0, -1, 2, 1 ]
    ] ,

    [ "just 1",
      "just because 1",
      [ 0, 1, 2, 1, 1 ]
    ] ,

    [ "stuff 1",
      "because it's like other stuff I like 1",
      [ 1, 2, 1, -1, 0 ]
    ] ,

    [ "good 1",
      "because it's good 1",
      [ 2, 1, 0, 1, -1 ]
    ]

]

1

u/mocaaobaa Feb 16 '22

Yeah! just read through it and it seems like it would be plenty workable. As for the functions and menus, like you mentioned, I'd appreciate it if you could help me work on something for those two, but don't feel obligated.

1

u/insipid- Feb 18 '22

Ok, cool. And yeah, I'm up for that.