Page 1 of 1

Manual Key Binding to Variables/Show Image

Posted: Sun Jan 21, 2018 8:53 am
by Foray
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.

Re: Manual Key Binding to Variables/Show Image

Posted: Sun Jan 21, 2018 10:13 am
by Empish
For an action, screen language expects a Screen Action rather than just code.

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.

Re: Manual Key Binding to Variables/Show Image

Posted: Sun Jan 21, 2018 8:45 pm
by Foray
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?