My Ninja Way: need help with the correctness of writing lines of code

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
cuteankle
Newbie
Posts: 17
Joined: Sun Jun 25, 2023 11:04 am
itch: python
Contact:

My Ninja Way: need help with the correctness of writing lines of code

#1 Post by cuteankle »

I still have the same problem with remembering the location, but at least I have achieved some enlightenment, now instead of numbers, the location is enclosed in single quotes under its name and everything really works, but there is a problem that at the end of the cycle, being in a dedicated location, it throws it into the main menu without processing the else function, where if the character he does not sleep, he is transferred to 2 energies on a new day, but at these locations he just crashes into the main menu.

Code: Select all

label newday:
    show screen DayDisplay
    call statlock


    if location == 'street':
        jump house_street
    elif location == 'yard':
        jump house_yard
    else:
        if energy == 3:
            call morning
        elif energy == 2:
            call day
        elif energy == 1:
            call night
        else:
            if extra_rest == True:
                $ energy = 3
                $ extra_rest = False
                call monthchange
                call daychange
            elif extra_rest == False:
                $ energy = 2
                call monthchange
                call daychange

 

    jump newday

User avatar
Alex
Lemma-Class Veteran
Posts: 3097
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: My Ninja Way: need help with the correctness of writing lines of code

#2 Post by Alex »

cuteankle wrote: Thu Jul 06, 2023 4:14 am ...
What do you have at the end of 'house_street' and 'house_yard' labels?
If it's the 'return' statement then game jump to main menu is correct. So, either use 'jump newday' at the end of labels, or call 'house_street' and 'house_yard' labels instead of jumping to them.

cuteankle
Newbie
Posts: 17
Joined: Sun Jun 25, 2023 11:04 am
itch: python
Contact:

Re: My Ninja Way: need help with the correctness of writing lines of code

#3 Post by cuteankle »

Alex wrote: Thu Jul 06, 2023 2:48 pm
cuteankle wrote: Thu Jul 06, 2023 4:14 am ...
Hi, thanks for the answer, I understand your conclusions and it sounds like everything is correct, but your advice does not work for me, which surprises me... I tried to call and return, as you said, but the energy goes to -1, -2,-3,-4, -5 and so on, although the character really stays in place, even though everything else breaks. :(

User avatar
Alex
Lemma-Class Veteran
Posts: 3097
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: My Ninja Way: need help with the correctness of writing lines of code

#4 Post by Alex »

What's the actual code you have for now?

cuteankle
Newbie
Posts: 17
Joined: Sun Jun 25, 2023 11:04 am
itch: python
Contact:

Re: My Ninja Way: need help with the correctness of writing lines of code

#5 Post by cuteankle »

Alex wrote: Sun Jul 09, 2023 5:53 am What's the actual code you have for now?

Code: Select all

label house_street:
    if energy == 3:
        scene oldhouse_morning
    if energy == 2:
        scene oldhouse_day
    if energy == 1:
        scene oldhouse_night

    $ location = 'street'
    

    menu:
        "Back House":
            jump caridor
        "Go house yard":
            jump house_yard
        "Wait":
            $ energy -= 1
            (call/jump newday # i try) :( 2 variant
    (call/jump newday # i try) 1 variant
    return

label house_yard:
    show black

    $ location = 'yard'

    menu:
        "Go swim":
            jump swimming
        "Back Street":
            jump house_street
        "Wait":
            $ energy -= 1
            (call/jump newday # i try) :(
    (call/jump newday # i try)
    return
I'm still working on locations and variables for all sorts of events, also with randomness for random events, there is nothing in the code to break the memorization of the location, which is quite strange... I'm sure you suggested it correctly, but for some reason it didn't work.

I also tried changing jump from call to label newday

User avatar
Alex
Lemma-Class Veteran
Posts: 3097
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: My Ninja Way: need help with the correctness of writing lines of code

#6 Post by Alex »

cuteankle wrote: Sun Jul 09, 2023 6:41 am ...
So, what's wrong with this code?
How does player reach the label 'house_street' (label was called or jumped to) or is it the main location?

When player reaches the 'house_yard' (s)he can return back to 'house_street' without losing energy - is this correct?

If player choose to wait at 'house_yard' it'll cost him/her 1 energy. Then player should 'jump' to 'house_street' label ('cause previously (s)he jumped to 'house_yard' label).

Looks like you should use only jumps to make player move from one location to another.

cuteankle
Newbie
Posts: 17
Joined: Sun Jun 25, 2023 11:04 am
itch: python
Contact:

Re: My Ninja Way: need help with the correctness of writing lines of code

#7 Post by cuteankle »

Alex wrote: Sun Jul 09, 2023 7:15 am
cuteankle wrote: Sun Jul 09, 2023 6:41 am ...
The main location is the house itself, and the yard and the street are secondary locations that are next to each other, which does not require energy costs when moving, but the wait function transfers to a new daily cycle (Morning, day and night). But when waiting after the night instead of the morning, the energy goes to -1, -2,-3,-4, although it should be transferred to the day instead of the morning, because the character spent the night on the street, not in bed, which involved the variable extra_rest == True. I know that this is already arrogance, but could you take my code and try to write what I need? I would be very grateful.

User avatar
Alex
Lemma-Class Veteran
Posts: 3097
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: My Ninja Way: need help with the correctness of writing lines of code

#8 Post by Alex »

cuteankle wrote: Sun Jul 09, 2023 12:20 pm ...

Code: Select all

label newday:
    show screen DayDisplay
    call statlock


    if location == 'street':
        jump house_street
    elif location == 'yard':
        jump house_yard
    else:
        if energy == 3:
            call morning
        elif energy == 2:
            call day
        elif energy == 1:
            call night
        else:
            if extra_rest == True:
You need to correct this part, 'cause for now game jumps to label and not change the energy variable.

cuteankle
Newbie
Posts: 17
Joined: Sun Jun 25, 2023 11:04 am
itch: python
Contact:

Re: My Ninja Way: need help with the correctness of writing lines of code

#9 Post by cuteankle »

Alex wrote: Sun Jul 09, 2023 2:27 pm
cuteankle wrote: Sun Jul 09, 2023 12:20 pm ...

Code: Select all

label newday:
    show screen DayDisplay
    call statlock


    if location == 'street':
        jump house_street
    elif location == 'yard':
        jump house_yard
    else:
        if energy == 3:
            call morning
        elif energy == 2:
            call day
        elif energy == 1:
            call night
        else:
            if extra_rest == True:
You need to correct this part, 'cause for now game jumps to label and not change the energy variable.
I do not know how to fix it. I also changed this part with all the call values, but it doesn't come out.

User avatar
Alex
Lemma-Class Veteran
Posts: 3097
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: My Ninja Way: need help with the correctness of writing lines of code

#10 Post by Alex »

cuteankle wrote: Fri Jul 14, 2023 2:35 am I do not know how to fix it. I also changed this part with all the call values, but it doesn't come out.
Try to "execute" your code line by line by yourself to find the problem part.

As I see it:
- player jumps to some location (like 'house_street' label, so location 'variable' value became 'street'),
- from that label you call (or jump to) 'newday' label to check energy,
- in 'newday' label there is a condition checker that checks that location == 'street' and send player to 'house_street' label again.

You can change the order of checks in 'newday' label - at first check the 'energy' variable and then (in separate condition check) check the 'location' variable value.

I might be wrong, 'cause I don't see the whole script you have, but I hope you got the idea and will be able to test your script.

Post Reply

Who is online

Users browsing this forum: Aceman04, Ocelot