Image button navigation... Am I making a monster?

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
nhguy03276
Regular
Posts: 41
Joined: Thu Jan 29, 2015 12:48 pm
Contact:

Image button navigation... Am I making a monster?

#1 Post by nhguy03276 »

My Project: A Choose your Own Adventure merged with a story and a semi-open world.

A important location in the story/game is the city's storm drains, a maze of tunnels with several entrance/exit points, designed to confound typical maze solving techniques and confuse/disorientate the player, such as the back button is more of a U-turn button, where what was on the right is now on the left as if you turned around. I plan on adding several things to make solving it easier, but for now I'm just trying to get the point and click movement mechanics down. The layout is a 29 X 29X ? XYZ grid (The Z is static at the moment, and a place holder in case I add more layers). And each tunnel section has a XYZ location, with about 350 sections.

What I've done so far seems to be working fine, but I'm just concerned with the number of "call screens" I'm going to hit a point where stability/memory leaks will become an issue. Also, with over 2000 lines of code so far, and less than half of the tunnels done, I'm wondering if there cleaner way to code this.

A sample of the code so far:

Code: Select all

image SD_B_R = "scenes/tunnle_pics/SD_B_R.png"
image SD_B_L = "scenes/tunnle_pics/SD_B_L.png"
image SD_T_1 = "scenes/tunnle_pics/SD_T_1.png"
image SD_T_2 = "scenes/tunnle_pics/SD_T_2.png"
image SD_T_3 = "scenes/tunnle_pics/SD_T_3.png"
image SD_S_1 = "scenes/tunnle_pics/SD_S_1.png"
image SD_E_LAD = "scenes/tunnle_pics/SD_E_LAD.png"
image SD_X_1 = "scenes/tunnle_pics/SD_X_1.png"
image SD_E_2 = "scenes/tunnle_pics/SD_E_2.png"

label stormdrains:
  
    scene black
    if (loc1 == "x24y12z4"):
        hide SD_T_3
        hide SD_T_1
        hide SD_T_2
        show SD_E_LAD 
        call screen x24y12z4
        screen x24y12z4:
            imagebutton auto "maps/arrow_B_%s.png" action [Jump("x24y12z4a")] xpos 500 ypos 600
            
            imagebutton auto "maps/arrow_F_%s.png" action [Jump("outside")] xpos 600 ypos 200

label x24y12z4a:
  $ p_min +=1 
  if (p_min > 59): 
    $ p_min -=60
    call time_call_1
        
  if (loc1 == "x24y12z4"):
    hide SD_E_LAD
    hide SD_T_3
    hide SD_T_1
    hide SD_T_2
    show SD_S_1 with ffade
    

    call screen x24y12z4a
    screen x24y12z4a:
            imagebutton auto "maps/arrow_F_%s.png" action [Jump("x23y12z4")] xpos 500 ypos 350
            
            imagebutton auto "maps/arrow_B_%s.png" action [Jump("stormdrains")] xpos 500 ypos 650
  elif (loc1 == "x23y12z4"):
      hide SD_T_3
      hide SD_T_1
      hide SD_T_2
      show SD_E_LAD with ffade

      $loc1 = "x24y12z4" 
      call screen x24y12z4c
      screen x24y12z4c:
            imagebutton auto "maps/arrow_B_%s.png" action [Jump("x24y12z4a")] xpos 500 ypos 650
            
            imagebutton auto "maps/arrow_F_%s.png" action [Jump("outside")] xpos 600 ypos 200

            
            
            
label x23y12z4:
    $ p_min +=1 
    if (p_min > 59): 
      $ p_min -=60
      call time_call_1
    
    if (loc1 == "x24y12z4"):
        hide SD_E_LAD
        hide SD_S_1        
        show SD_T_3 with ffade

        $ loc1 = "x23y12z4"
        call screen x23y12z4a
        screen x23y12z4a:
            imagebutton auto "maps/arrow_F_%s.png" action [Jump("x22y12z4")] xpos 500 ypos 350
            imagebutton auto "maps/arrow_R_%s.png" action [Jump("x23y13z4")] xpos 900 ypos 350 
            imagebutton auto "maps/arrow_B_%s.png" action [Jump("stormdrains")] xpos 500 ypos 650  
    elif (loc1 == "x22y12z4"):
        hide SD_E_LAD
        hide SD_S_1
        show SD_T_1 with ffade

        $ loc1 = "x23y12z4"
        call screen x23y12z4b
        screen x23y12z4b:
            imagebutton auto "maps/arrow_F_%s.png" action [Jump("x24y12z4a")] xpos 500 ypos 350
            imagebutton auto "maps/arrow_L_%s.png" action [Jump("x23y13z4")] xpos 124 ypos 350 
            imagebutton auto "maps/arrow_B_%s.png" action [Jump("x22y12z4")] xpos 500 ypos 650        

    elif (loc1 == "x23y13z4"):
        hide SD_E_LAD
        hide SD_S_1
        show SD_T_2 with ffade

        $ loc1 = "x23y12z4"
        call screen x23y12z4c
        screen x23y12z4c:
            imagebutton auto "maps/arrow_L_%s.png" action [Jump("x24y12z4a")] xpos 124 ypos 350
            imagebutton auto "maps/arrow_B_%s.png" action [Jump("x23y13z4")] xpos 500 ypos 650 
            imagebutton auto "maps/arrow_R_%s.png" action [Jump("x22y12z4")] xpos 900 ypos 350  



label x22y12z4:
    $ p_min +=1 
    if (p_min > 59): 
      $ p_min -=60
      call time_call_1
      
    if (loc1 == "x23y12z4"):
        hide SD_T_3
        hide SD_T_1
        hide SD_T_2
        show SD_S_1 with ffade

        $ loc1 = "x22y12z4"
        call screen x22y12z4a
        screen x22y12z4a:
            imagebutton auto "maps/arrow_F_%s.png" action [Jump("x21y12z4")] xpos 500 ypos 350            
            imagebutton auto "maps/arrow_B_%s.png" action [Jump("x23y12z4")] xpos 500 ypos 650  


    elif (loc1 == "x21y12z4"):
        hide SD_T_3
        hide SD_T_1
        hide SD_T_2
        show SD_S_1 with ffade

        $ loc1 = "x22y12z4"
        call screen x22y12z4b
        screen x22y12z4b:
            imagebutton auto "maps/arrow_F_%s.png" action [Jump("x23y12z4")] xpos 500 ypos 350            
            imagebutton auto "maps/arrow_B_%s.png" action [Jump("x21y12z4")] xpos 500 ypos 650           
         
         
         
         
#############     X21 corridor     #######   

label x21y10z4:
    $ p_min +=1 
    if (p_min > 59): 
      $ p_min -=60
      call time_call_1    
  
    if (loc1 == "x21y11z4"):
        hide SD_S_1
        show SD_B_R with ffade
        $ loc1 = "x21y10z4"
        call screen x21y10z4
        screen x21y10z4:
            imagebutton auto "maps/arrow_R_%s.png" action [Jump("x20y10z4")] xpos 900 ypos 350             
            imagebutton auto "maps/arrow_B_%s.png" action [Jump("x21y11z4")] xpos 500 ypos 650 
    elif (loc1 == "x20y10z4"):
        hide SD_S_1
        show SD_B_L with ffade

        $ loc1 = "x21y10z4"
        call screen x21y10z4a
        screen x21y10z4a:
            imagebutton auto "maps/arrow_L_%s.png" action [Jump("x21y11z4")] xpos 124 ypos 350             
            imagebutton auto "maps/arrow_B_%s.png" action [Jump("x20y10z4")] xpos 500 ypos 650             
            


 ETC. ETC... 
Any thoughts, tips, concerns?

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Image button navigation... Am I making a monster?

#2 Post by philat »

Well, if you're making a 350 section maze, it's inevitable that it will be a lot of code, I guess, but there's got to be a way to code it with less hassle. Have you looked at Wolf's and nyaatrap's 3d dungeon crawler code?

http://lemmasoft.renai.us/forums/viewto ... 51&t=32260

http://lemmasoft.renai.us/forums/viewto ... 51&t=19245

I don't mean you should use these as they are, but that you can probably get some ideas around wrangling your code into manageable data classes to semi-automate the creation of the maze and movement mechanisms.

For instance, from what I recall, the dungeon crawler code keeps track of direction, which informs the arrow keys movement (if you're facing north, pressing forward increases the y cell count, but if you're facing south, it does the opposite), which in turn allows the same set of arrow keys to be used in every cell without need to manually specify what each key does.

Also, semi-unrelatedly, it seems like you wrap the whole time thing into a function rather than spell it out each time.

nhguy03276
Regular
Posts: 41
Joined: Thu Jan 29, 2015 12:48 pm
Contact:

Re: Image button navigation... Am I making a monster?

#3 Post by nhguy03276 »

philat wrote:Well, if you're making a 350 section maze, it's inevitable that it will be a lot of code, I guess, but there's got to be a way to code it with less hassle. Have you looked at Wolf's and nyaatrap's 3d dungeon crawler code?

http://lemmasoft.renai.us/forums/viewto ... 51&t=32260

http://lemmasoft.renai.us/forums/viewto ... 51&t=19245

I don't mean you should use these as they are, but that you can probably get some ideas around wrangling your code into manageable data classes to semi-automate the creation of the maze and movement mechanisms.

For instance, from what I recall, the dungeon crawler code keeps track of direction, which informs the arrow keys movement (if you're facing north, pressing forward increases the y cell count, but if you're facing south, it does the opposite), which in turn allows the same set of arrow keys to be used in every cell without need to manually specify what each key does.

Also, semi-unrelatedly, it seems like you wrap the whole time thing into a function rather than spell it out each time.

Thanks, yeah, I knew it was gonna get big when I started, but I was most concerned that with that many calls, I'd run into some "stack overflow error" or some other such mess... also It somehow feels like I'm missing a close type command and was wondering if it would end up with a 200 GB ram requirement... Like if you don't hide your images. But since no one has chimed in on my missing something like that I can hope I'm good.

Thanks for those links, I'll definitely look into them. Luckily as much as the code is starting to get large, I drew the map out ahead of time, and am treating it much like a crossword puzzle. X down, Y across, all the blocks in the corridor go together... It helps. and now that I've got a large area done, it's a lot of cut and paste with 5 or 6 numbers changed. I can do a hallway in a few minutes... even still I do take frequent breaks when the number start to blur.

As for the time... Yeah, that one has been a bit of a issue for me to get to work the way I need it to. The problem is when combining free play with static story, trying to keep the illusion that you are free to move at will, while I puppet master you to where/when I want you... It's far from perfect, but at least this way I can set the amounts of time encounters take, while allowing the player to decide how much time they want to spend in the Library, Pub, or the Storm Drains. From what I've seen in the forums, Time is one of the more challenging things to write.

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Image button navigation... Am I making a monster?

#4 Post by philat »

I'm not super familiar with the ins and outs of all screen actions, but I don't think call screen with Jump actually creates a stack the way a call label and jump command would. (For example, if you call a testscreen that jumps to a label, then end that label with return, the game ends rather than returning to the point where you called the screen.) I'm also not very knowledgeable about performance issues, so I don't know how prediction or memory management etc. would interact with something like this, so someone else will have to chime in, but as no one has so far, I would think positive...?

Post Reply

Who is online

Users browsing this forum: Ocelot, Toma