[rated unnecessary] navigation system: while and break

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
Ayutac
Regular
Posts: 150
Joined: Thu Oct 18, 2012 2:23 pm
Projects: Pokémon Dating Sim
Organization: A Breeze Of Science
Deviantart: Ubro
Location: Mayence, Germany
Contact:

[rated unnecessary] navigation system: while and break

#1 Post by Ayutac » Fri Jan 25, 2013 9:01 pm

Hello there! I'm aware there is no break for while in Ren'Py and I should either use jumps directly or work with some control variable. However, my goal is not to use jumps because they remain in the stack and I would have very much of them. So using jumps is inappropiate and the control variables wouldn't work either if we happen to enter the same navigation point/loop twice, which is possible. Of course there is no problem to break a while loop within the python environment. But using this would force me to transform my menus into python code which would make the code more complicated. So I would need either the break in Ren'Py language (which would probably mean a lot of work for PyTom) or a nopython environment for within a python environment, I don't know if any of you know something about this. Or the third option is that one of you guys have another idea to solve my problem, by any chance.
I would also be interested how any of you coded a navigation system for your games, if any.

And I'm proud of my research xD

EDIT: related question: What is the python-equivalent to the return (of a call) of Ren'Py? Because it is not the return of python.

EDIT: The pop_return could be a solution, but I would judge it as a huge workaround where you have to keep track of where you actually came from. I would wish for a more simple solution.

EDIT: Should have attached my navigation.rpy (copyrighted with CC-BY-NC-SA) in the first place.
Attachments
navigation.rpy
(12.14 KiB) Downloaded 48 times
Last edited by Ayutac on Sat Jan 26, 2013 6:53 am, edited 3 times in total.
Up next: An original, open source, text-based Dating Sim. Stay tuned ;)

User avatar
astrobread
Newbie
Posts: 13
Joined: Mon Jan 21, 2013 4:01 am
Contact:

Re: navigation system: while and break OR nopython environme

#2 Post by astrobread » Sat Jan 26, 2013 12:24 am

Why wouldn't the control variable solution work? All you'd have to do is reset it directly prior to the while loop, and make sure that's the point your navigation targets. Alternatively, you could reset the control variable immediately after a loop ends in order to prep for the next time.

Based on the research you've listed I suspect I'm missing something. If there's a reason this won't work with your navigation system, could you post an example showing why?

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: navigation system: while and break OR nopython environme

#3 Post by PyTom » Sat Jan 26, 2013 1:11 am

Ayutac wrote:Hello there! I'm aware there is no break for while in Ren'Py and I should either use jumps directly or work with some control variable. However, my goal is not to use jumps because they remain in the stack and I would have very much of them. So using jumps is inappropiate and the control variables wouldn't work either if we happen to enter the same navigation point/loop twice, which is possible. Of course there is no problem to break a while loop within the python environment. But using this would force me to transform my menus into python code which would make the code more complicated. So I would need either the break in Ren'Py language (which would probably mean a lot of work for PyTom) or a nopython environment for within a python environment, I don't know if any of you know something about this. Or the third option is that one of you guys have another idea to solve my problem, by any chance.
I would also be interested how any of you coded a navigation system for your games, if any.

And I'm proud of my research xD

EDIT: related question: What is the python-equivalent to the return (of a call) of Ren'Py? Because it is not the return of python.
Break is exactly equivalent to jump.

Code: Select all

while True:
     if enemy_dead:
          break

     # Fighting code here.
is equivalent to:

Code: Select all

while True:
     if enemy_dead:
          jump done

     # Fighting code here.
label done:
The call-stack issue seems irrelevant - you can't cause a break in an outer function in Python, and you can't cause a break in an outer while loop from an inner while loop in Ren'Py.

There is no proper python equivalent to Ren'Py return. You could do renpy.jump("_return"), which is a label that calls return, but it seems that your code is weirdly organized if you have to do this.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
Ayutac
Regular
Posts: 150
Joined: Thu Oct 18, 2012 2:23 pm
Projects: Pokémon Dating Sim
Organization: A Breeze Of Science
Deviantart: Ubro
Location: Mayence, Germany
Contact:

Re: navigation system: while and break OR nopython environme

#4 Post by Ayutac » Sat Jan 26, 2013 4:21 am

astrobread wrote:Why wouldn't the control variable solution work? All you'd have to do is reset it directly prior to the while loop, and make sure that's the point your navigation targets. Alternatively, you could reset the control variable immediately after a loop ends in order to prep for the next time.
I'll do your idea in pseudo code. "eW" is short for endWhile

Code: Select all

label world:
    > jump town
    > jump forest
    > jump beach

label town:
    eW[town] = False
    while not eW:
        > jump hotel
        > jump library
        > back to map (eW[town] = True)

label hotel:
    eW[hotel] = False
    while not eW:
        > jump apartment
        > back to town (eW[hotel] = True)

label forest:
    eW[forest] = False
    while not eW:
        > go this direction
        > go that direction
        > occasionally end up in some place

label beach:
    ew[beach] = False:
    while not eW:
        > drink something good
        > go into forest
        > back to map (eW[beach] = True)
Of course I would have to do a control variable for each navigation point, or when I return from the apartment I would land on the map. That are a lot of additional variables which inflate the code and aren't really necessary elsewhere. Then I would have to set the eWs manually in some cases, e.g. I turn the one of the forest on when I leave it for the beach, so "return to map" on beach really returns there and does not go into the forest again. Instead of keeping track where I came from I would have to keep track where I go to. It is indeed slightly easier, but I was hoping for a better way. (With break, I wouldn't care about the variables anymore). If I use jumps to the end of whiles I would have the same number of unnecessary labels instead of flags, which leads to the same thing. And if I just jump directly, I would have what I have now.

Another method would be to remove the labels change the parts to function calls instead. But from what I know, it seems the "def" command can only be used from within a python environment and like I said I try to keep it in Ren'Py, so another solution would be the existence of a nopython environment (with the python environment forbidden in it to prevent unnecessary nesting). Does this exist, or would it be difficult to implement?
PyTom wrote:The call-stack issue seems irrelevant - you can't cause a break in an outer function in Python, and you can't cause a break in an outer while loop from an inner while loop in Ren'Py.
So, are you basically saying I can leave my navigation how it is, because stack size wouldn't matter? When I have 31 days and say 200 jumps per day and a visit to the forest maze with length n*n, I would have 600 jumps + let's say 30*(n*n)/2. Let n be 100, that would be 150600 jumps per game. You say that amount of jumps wouldn't matter? If yes, I'll leave everything as it is.

EDIT: Just went testing the thesis from before. I'm expecting results in one and a half hour. Generally, where is the upper limit for jump calls?
Up next: An original, open source, text-based Dating Sim. Stay tuned ;)

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: navigation system: while and break OR nopython environme

#5 Post by nyaatrap » Sat Jan 26, 2013 5:16 am

I think you have mistaken "jump" and "call". renpy.jump is just a sequence flow and never return. Where jumped from is only recorded in the rollback function.

Code: Select all

label a:
  pass
label b:
  pass
is equivalent to

Code: Select all

label a:
  jump label b
label b:
  pass
BTW, if your have interested, I made a dungeon navigation system which is using renpy.show_screen and renpy.jump. http://lemmasoft.renai.us/forums/viewto ... 30&t=15755 The code is a bit unsophisticated, but It's a open source.

User avatar
Ayutac
Regular
Posts: 150
Joined: Thu Oct 18, 2012 2:23 pm
Projects: Pokémon Dating Sim
Organization: A Breeze Of Science
Deviantart: Ubro
Location: Mayence, Germany
Contact:

Re: navigation system: while and break OR nopython environme

#6 Post by Ayutac » Sat Jan 26, 2013 6:40 am

nyaatrap wrote:BTW, if your have interested, I made a dungeon navigation system which is using renpy.show_screen and renpy.jump. http://lemmasoft.renai.us/forums/viewto ... 30&t=15755 The code is a bit unsophisticated, but It's a open source.
I managed to die during the prologue in the dungeon xD And I still know to less kanji to actually understand the dialogs.
But I looked through the source. The lack of commentary didn't make it easy and it took me a while to find the exploration label, but I see how this works.

The code for 160k jumps ran through, nothing exciting happened. I guess I can be relieved then and I better do mazes into a while loop, just in case.
Now it would be just interesting to know where the boundarys for the rollback stack are. I didn't understand rollback fully until know anyway :P
Up next: An original, open source, text-based Dating Sim. Stay tuned ;)

Post Reply

Who is online

Users browsing this forum: Bing [Bot]