Manual Key Binding to Variables/Show Image

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Foray
Newbie
Posts: 7
Joined: Sun Jan 21, 2018 8:06 am
Contact:

Manual Key Binding to Variables/Show Image

#1 Post by Foray » Sun Jan 21, 2018 8:53 am

I'm afraid I'm a complete novice with Ren'Py and Python code, so I apologize in advance for any confusing vocabulary or oversights.

I am currently trying to assign keyboard keys to specific actions. I've managed to bind keys to jump to specific scenes, but other commands that I can enter normally (or make follow from standard "menu" buttons) return errors following the key assignment. To be more specific, I wish to make a key trigger a temporary show event (~1 second) as well as modify a variable counter.

In the sample code below, the "W" key functions as assigned. The middle three keys return errors, saying: "expected a keyword argument, colon, or end of line."
The game will launch with the final key ("F"), but if the key is pressed, the game will crash, returning an error that "Screen Hikage 1 is not known."

Code: Select all

    image Hikage 1 = "Hikage.png"
    $ hikage_pt = 10

screen actionkeys:
     key "K_w" action Jump ("start.mirailand")
     key "K_a" action $ hikage_pt -= 1
     key "K_s" action $ hikage_pt -= 5
     key "K_d" action hikage_pt += 5
     key "K_f" action show ("Hikage 1")
I've tried messing with the format a bit (adding colons and trying different statements), but with no success. It's interesting to me that the formatting here reads the "show" as a Scene rather than an Image, when writing "show" normally will simply add images atop the pre-existing Scene. Perhaps I'm meant to include a "transformation" clause of some kind? I honestly have no guesses regarding the counters.

Any help in setting me straight would be appreciated.

User avatar
Empish
Veteran
Posts: 221
Joined: Thu Jan 14, 2016 9:52 pm
Projects: Efemural Hearts, It Ends With Graduation
itch: empish
Contact:

Re: Manual Key Binding to Variables/Show Image

#2 Post by Empish » Sun Jan 21, 2018 10:13 am

For an action, screen language expects a Screen Action rather than just code. https://www.renpy.org/doc/html/screen_actions.html

For example, for your 'a' key one, you'd want the following:

Code: Select all

key "K_a" action SetVariable("hikage_pt", hikage_pt - 1)
As for the last one, the Show action expects a screen rather than an image, so this won't work. However you can jump to or call a label that will show Hikage 1 instead.

Foray
Newbie
Posts: 7
Joined: Sun Jan 21, 2018 8:06 am
Contact:

Re: Manual Key Binding to Variables/Show Image

#3 Post by Foray » Sun Jan 21, 2018 8:45 pm

That answers my question perfectly! I actually tried the SetVariable before, but I formatted it wrong (now I feel like such a klutz).
Thank-you so much!

Unless I work out a new conundrum of mine I may be asking another question here soon, but I think the admin would prefer that it be under a new thread given that the problem is of a different nature than the title, no?

Post Reply

Who is online

Users browsing this forum: IaMe, zeroTheHero