Attempting to make a code lock

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
User avatar
burnt_offering
Regular
Posts: 107
Joined: Sun Feb 23, 2014 4:21 pm
Completed: The Stroke of Midnight
Organization: Ace Of Spades
IRC Nick: burnt_offering or TheTapDancer
Skype: aceofspadesvn
itch: aceofspadesvn
Location: London
Contact:

Attempting to make a code lock

#1 Post by burnt_offering »

Basically, I've been trying to code a gameplay element, in which at one point there's a door with a number lock on it.
Now, the code was fairly okay:

Code: Select all

screen GenCodeInput:
    tag puzzle
    use navigation
    imagemap:
        ground "gencode.png"
        idle "gencode.png"
        hover "gencodehover.png"
        
        hbox:
            for i in (0,9):
                textbutton str(i):
                    if code==0:
                        code=i
                    elif code<10:
                        code= 10*code + i
                    elif code>9999:
                        codestring=str(code)
                        for ch in codestring:
                            codestring2 = str(codestring[-4:])
                            code = int(codestring2)
                            code = 10*code + i
                    ground "gencode(%code).png"
            textbutton clear:
                code=0
        
The problem is that this requires 10000 images, one for each possible number, which simply isn't feasible. Is there some way I can do this more efficiently?
[url]http:\\aceofspades@vnovel.com[/url]
Or just follow me at @AceOfSpades_VN

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Attempting to make a code lock

#2 Post by Milkymalk »

How about the way real code locks do it? 10 images for the numbers 0-9, 4 of them to display a 4-digit number?
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
burnt_offering
Regular
Posts: 107
Joined: Sun Feb 23, 2014 4:21 pm
Completed: The Stroke of Midnight
Organization: Ace Of Spades
IRC Nick: burnt_offering or TheTapDancer
Skype: aceofspadesvn
itch: aceofspadesvn
Location: London
Contact:

Re: Attempting to make a code lock

#3 Post by burnt_offering »

Milkymalk wrote:How about the way real code locks do it? 10 images for the numbers 0-9, 4 of them to display a 4-digit number?
I guess if I used a different variable for each position I could do that.
[url]http:\\aceofspades@vnovel.com[/url]
Or just follow me at @AceOfSpades_VN

Post Reply

Who is online

Users browsing this forum: No registered users