To have an imagemapped keypad which then checks your input and gives a 2nd try if you fail:To have your game randomize the code:Code: Select all
screen key_pad: imagemap: ground "keypad.png" hover "keyHover.png" hotspot (765, 635, 100, 100) action Return(1) hotspot (940, 635, 100, 100) action Return(2) hotspot (1120, 635, 100, 100) action Return(3) hotspot (765, 465, 100, 100) action Return(4) hotspot (940, 465, 100, 100) action Return(5) hotspot (1120, 465, 100, 100) action Return(6) hotspot (765, 300, 100, 100) action Return(7) hotspot (940, 300, 100, 100) action Return(8) hotspot (1120, 300, 100, 100) action Return(9) hotspot (800, 825, 380, 83) action Return(0) label start: $ keys = [] $ counter = 0 show screen key_pad jump crack_the_code label crack_the_code: $ counter += 1 python: while len(keys) < 4: $ result = ui.interact() if isinstance(result, int): $ keys.append(result) if keys == [2, 5, 1, 4]: hide screen key_pad play sound "carkeyturn.ogg" jump success else: $ keys = [] if counter == 2: hide screen key_pad jump failed else: "Try again..." jump crack_the_code label failed: "You're a shitty code cracker..." return label success: "Well done, you've cracked the code!" return
xela wrote:For random, we generate a list of 4 integers in range of 0 - 9:
*Note that you can change the four to anything (determines the length of code), it should work with any number.Code: Select all
$ our_code = renpy.random.sample(range(10), 4)
In order to display the code:
To check if the code is correct:Code: Select all
$ our_code_string = ", ".join(str(i) for i in our_code) "Our code is: [our_code_string]"
should become:Code: Select all
while len(keys) < 4:
andCode: Select all
while len(keys) < len(our_code):
should be:Code: Select all
if keys == [2, 5, 1, 4]:
Code: Select all
if keys == our_code:
Original post
PRE-TL;DR
Basically my question is if someone out there knows a of functioning version of "hotspot (1120, 635, 100, 100) clicked [$ keyAttempt1.append("1"), $ inputNumbers1 += 1]" I can implement.
As far as I can tell the instruction you give after the brackets for the hotspot is called an 'action'(?) so basically I'm wondering if there are any actions out there which will tell the hotspot to keyAttempt1.append and then add 1 to the input digit counter.
LONG WINDED EXPLANATION FORTHCOMING:
Hi, it's my first time posting here for my first game, so I'm not used to the specific keywords and stuff that renpy uses. I've been searching all over but my deadline's in less than a week now and I need help sharpish :<
So my game is a heist sort of thing, and I'm trying to put in a functional keypad that will either give you access to what you're going to steal if you successfully input the 4-digit code, or else give you another attempt and then sound an alarm if you fail (twice).
Okay so I got my sample keypad imagemap to work perfectly fine (I don't want to use a normal text menu in the final game, because it's set in the 50's and I wanted an old timey look!).
I also got the keycode input to work in a separate script file (temporarily using a text menu). For the code input, I have $ keyAttempt1 = [] to keep track of the player's choices, and a While statement counting till 4 digits have been input, which then triggers the jump to check if the 4 numbers are correct and in the correct order.
My problem is that when I tried to combine the imagemap code, and the code for the input, it's not working :v
Here's the entire keypad code (I just rewrote it all at 1:30 am so excuse any inconsistencies):
Code: Select all
screen keyPad:
imagemap:
ground "keypad.png"
hover "keyHover.png"
hotspot (1120, 635, 100, 100) clicked [$ keyAttempt1.append("1"), $ inputNumbers1 += 1]
hotspot (940, 635, 100, 100) clicked [$ keyAttempt1.append("2"), $ inputNumbers1 += 1]
hotspot (765, 635, 100, 100) clicked [$ keyAttempt1.append("3"), $ inputNumbers1 += 1]
hotspot (1120, 465, 100, 100) clicked [$ keyAttempt1.append("4"), $ inputNumbers1 += 1]
hotspot (940, 465, 100, 100) clicked [$ keyAttempt1.append("5"), $ inputNumbers1 += 1]
hotspot (765, 465, 100, 100) clicked [$ keyAttempt1.append("6"), $ inputNumbers1 += 1]
hotspot (1120, 300, 100, 100) clicked [$ keyAttempt1.append("7"), $ inputNumbers1 += 1]
hotspot (940, 300, 100, 100) clicked [$ keyAttempt1.append("8"), $ inputNumbers1 += 1]
hotspot (765, 300, 100, 100) clicked [$ keyAttempt1.append("9"), $ inputNumbers1 += 1]
hotspot (800, 825, 380, 83) clicked [$ keyAttempt1.append("0"), $ inputNumbers1 += 1]
screen keyPad2:
imagemap:
ground "keypad.png"
hover "keyHover.png"
hotspot (1120, 635, 100, 100) clicked [$ keyAttempt2.append("1"), $ inputNumbers2 += 1]
hotspot (940, 635, 100, 100) clicked [$ keyAttempt2.append("2"), $ inputNumbers2 += 1]
hotspot (765, 635, 100, 100) clicked [$ keyAttempt2.append("3"), $ inputNumbers2 += 1]
hotspot (1120, 465, 100, 100) clicked [$ keyAttempt2.append("4"), $ inputNumbers2 += 1]
hotspot (940, 465, 100, 100) clicked [$ keyAttempt2.append("5"), $ inputNumbers2 += 1]
hotspot (765, 465, 100, 100) clicked [$ keyAttempt2.append("6"), $ inputNumbers2 += 1]
hotspot (1120, 300, 100, 100) clicked [$ keyAttempt2.append("7"), $ inputNumbers2 += 1]
hotspot (940, 300, 100, 100) clicked [$ keyAttempt2.append("8"), $ inputNumbers2 += 1]
hotspot (765, 300, 100, 100) clicked [$ keyAttempt2.append("9"), $ inputNumbers2 += 1]
hotspot (800, 825, 380, 83) clicked [$ keyAttempt2.append("0"), $ inputNumbers2 += 1]
label start:
$ keyAttempt1 = []
$ keyAttempt2 = []
$ inputNumbers1 = 0
$ inputNumbers2 = 0
label attempt1:
while inputNumbers1 < 4:
call screen keyPad
jump checkCode1
label checkCode1:
if ["2", "5", "1", "4"] in keyAttempt1:
jump codeSuccessful
else:
"One more try"
jump attempt2
label attempt2:
while inputNumbers2 < 4:
call screen keyPad2
jump checkCode2
label checkCode2:
if ["2", "5", "1", "4"] in keyAttempt2:
jump codeSuccessful
else:
jump codeFail
Code: Select all
I'm sorry, but an uncaught exception occurred.
After initialization, but before game start.
File "game/script.rpy", line 17, in prepare
screen keyPad2:
File "game/script.rpy", line 17, in prepare
screen keyPad2:
File "game/script.rpy", line 18, in prepare
imagemap:
File "game/script.rpy", line 18, in prepare
imagemap:
File "game/script.rpy", line 22, in prepare
hotspot (1120, 635, 100, 100) clicked [$ keyAttempt2.append("1"), $ inputNumbers2 += 1]
File "game/script.rpy", line 22, in prepare
hotspot (1120, 635, 100, 100) clicked [$ keyAttempt2.append("1"), $ inputNumbers2 += 1]
SyntaxError: invalid syntax (game/script.rpy, line 22)
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "C:\Users\User\Pictures\Photoshop\Projects\1. Game Fondue\Ren'Py\renpy\bootstrap.py", line 289, in bootstrap
renpy.main.main()
File "C:\Users\User\Pictures\Photoshop\Projects\1. Game Fondue\Ren'Py\renpy\main.py", line 311, in main
renpy.display.screen.prepare_screens()
File "C:\Users\User\Pictures\Photoshop\Projects\1. Game Fondue\Ren'Py\renpy\display\screen.py", line 676, in prepare_screens
s.ast.prepare()
File "game/script.rpy", line 17, in prepare
screen keyPad2:
File "game/script.rpy", line 17, in prepare
screen keyPad2:
File "game/script.rpy", line 18, in prepare
imagemap:
File "game/script.rpy", line 18, in prepare
imagemap:
File "game/script.rpy", line 22, in prepare
hotspot (1120, 635, 100, 100) clicked [$ keyAttempt2.append("1"), $ inputNumbers2 += 1]
File "game/script.rpy", line 22, in prepare
hotspot (1120, 635, 100, 100) clicked [$ keyAttempt2.append("1"), $ inputNumbers2 += 1]
File "C:\Users\User\Pictures\Photoshop\Projects\1. Game Fondue\Ren'Py\renpy\python.py", line 477, in py_compile
raise e
SyntaxError: invalid syntax (game/script.rpy, line 22)
Windows-7-6.1.7601-SP1
Ren'Py 6.18.3.761
keypad 0.0
I found a way around this by adding jumps for each hotspot which then add the keyAttempt1.append and inputNumbers1, before jumping back to the while statement, but I ended up with 20 jumps and it's not pretty. I'd like to implement something a bit more elegant if possible :/
TL;DR
Basically my question is if someone out there knows a of functioning version of "hotspot (1120, 635, 100, 100) clicked [$ keyAttempt1.append("1"), $ inputNumbers1 += 1]" I can implement.
As far as I can tell the instruction you give after the brackets for the hotspot is called an 'action'(?) so basically I'm wondering if there are any actions out there which will tell the hotspot to keyAttempt1.append and then add 1 to the input digit counter.
THANKS SO MUCH! XXXXXX