[Solved] Why do values change when you open the developer console?

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
Chekhov
Regular
Posts: 113
Joined: Tue Jun 26, 2018 9:19 am
Projects: Pluton
Contact:

[Solved] Why do values change when you open the developer console?

#1 Post by Chekhov »

Here's a problem that has me stumped. I've tried to cleanup the code and only leave the relevant bits. Sorry if it's still a little on the long side.

The weird thing that's happening is that when I open the developer console, some variables seem to change.

(you can run this code without any images and see it work).

Basically, every turn each player controlled dude gets to choose an attack, then each ai controlled dude gets to choose an attack(which are still controlled by player for testing purposes).

active_char tracks who's turn it is. dudeslist is a list of all characters and the active_char is the index of the character who's turn it is.
Perhaps superfluously, active_dude also points directly to the dude class who's turn it currently is.

Now if you run this code, you can click an attack, it will do the attack, and it will cycle to the next dude, exactly as it should.

But somehow, if you open the developer console, it always reverts back to the very first character in dudeslist. Does that happen because of the line "$ active_char = 0"? Why would it run that again, simply when I open the developer console?

You can test it out. Be sure to click an attack first. Then press shift+O and you see the name change instantly. I can't figure this one out.

Code: Select all

label start:


scene bg background

init python:
    import random
    import copy

$ active_char = 0 #Whose turn is it? Active char

define ai_list = {1 : "defensive", 2 : "offensive", 3 : "tactical"}


init python:

    
    
    def update_char():
        global active_char
        active_char += 1
        if active_char > (len(dudeslist) -1):
            active_char = 0
        active_dude = dudeslist[active_char]
        # print "active char = " + str(active_char)

    class Attack(object):
        def __init__(self, name = "Unnamed attack", damage = 0, cha_multiplier = 1, dex_multiplier = 1, int_multiplier = 1, chu_multiplier = 1, special = False):
            self.name = name
            self.damage = damage
            self.cha_multiplier = cha_multiplier
            self.dex_multiplier = dex_multiplier
            self.int_multiplier = int_multiplier
            self.chu_multiplier = chu_multiplier
            self.special = special

    class Dude_Class(object):
        def __init__(self, attack1, attack2, attack3):
            self.attack1 = attack1 
            self.attack2 = attack2
            self.attack3 = attack3


    class Dude(object):
        def __init__(self, name = "unnamed", control = "AI" , role="melee", xaxis=0, yaxis=0):

            self.name = name

            self.role = role
            self.control = control #player or AI
            
            self.x = xaxis
            self.y = yaxis

            self.ainumber = 1

            self.speed = 3
            self.range = 1
            self.update_dude_class()

        def rotate_ai(self):
            self.ainumber += 1
            if self.ainumber > (len(ai_list)-1):
                self.ainumber = 0
            self.ai = ai_list[self.ainumber]
            self.update_ai()

        def update_ai(self):
            self.ai = ai_list[self.ainumber]

        def move(self):
            #temporary move test
            self.x = self.x + 1
            self.y = self.y + 1

        def update_dude_class(self):
            #temp class decider
            self.dudeclass = Dude_Class(
                                        Attack("Recite poetry", 10, cha_multiplier= 1.5),
                                        Attack("Wink", 4, int_multiplier= 3),
                                        Attack("Flee", 0)
                                        )
        

python:
    dudeslist = []
    player_dudeslist = []
    AI_dudeslist = []

    player_dudeslist.append(Dude("Chosen", "player", "melee", 1, 1))
    player_dudeslist.append(Dude("Friend", "player", "melee", 0, 2))
    AI_dudeslist.append(Dude("Paramour", "AI", "melee", 5, 2))
    AI_dudeslist.append(Dude("Rival", "AI", "melee", 5, 4))
    dudeslist = player_dudeslist + AI_dudeslist

    active_dude = dudeslist[active_char]


screen MoveAI():
    frame:
        xpos 300 ypos 300
        button:
            action Function(active_dude.move)
            text _("Move automatically") style "button_text"

screen Continue():
    frame:
        xpos 400 ypos 400
        button:
            action Return()
            text _("Continue") style "button_text"


screen ChooseAttack():

    vbox:
        xpos 400 ypos 40
        text "{}'s turn".format(dudeslist[active_char].name)

        button:
            action [Function(update_char), Notify("You chose {} attack for {} damage".format(dudeslist[active_char].dudeclass.attack1.name, dudeslist[active_char].dudeclass.attack1.damage))]
            text "> {}".format(dudeslist[active_char].dudeclass.attack1.name)
        button:
            action [Function(update_char), Notify("You chose {} attack for {} damage".format(dudeslist[active_char].dudeclass.attack2.name, dudeslist[active_char].dudeclass.attack2.damage))]
            text "> {}".format(dudeslist[active_char].dudeclass.attack2.name) 
        button:
            action [Function(update_char), Notify("You chose {} attack for {} damage".format(dudeslist[active_char].dudeclass.attack3.name, dudeslist[active_char].dudeclass.attack3.damage))]
            text "> {}".format(dudeslist[active_char].dudeclass.attack3.name) 


show screen ChooseAttack()
show screen MoveAI()
call screen Continue()
Last edited by Chekhov on Sat Oct 05, 2019 12:56 am, edited 1 time in total.

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

Re: Why do values change when you open the developer console?

#2 Post by philat »

Besides the fact that that code obviously won't run (indentation, organization, etc.) -- you're still in the same ren'py statement (call screen Continue) and opening the console boots you to the beginning of the statement. If you were in a loop (call screen, return and do stuff, call screen again) rather than suspended in the same statement, it wouldn't be happening.

User avatar
Chekhov
Regular
Posts: 113
Joined: Tue Jun 26, 2018 9:19 am
Projects: Pluton
Contact:

Re: Why do values change when you open the developer console?

#3 Post by Chekhov »

philat wrote: Fri Oct 04, 2019 9:21 pm Besides the fact that that code obviously won't run (indentation, organization, etc.) -- you're still in the same ren'py statement (call screen Continue) and opening the console boots you to the beginning of the statement. If you were in a loop (call screen, return and do stuff, call screen again) rather than suspended in the same statement, it wouldn't be happening.
Thanks for the assist!


This code does run, you can copy paste it into a new renpy project and see that it works.

The entire code I'm testing is about 600 lines, but I've broken off as small a part as possible that reproduces the same error.

This code as posted absolutely works. Perhaps it's working despite the fact that it shouldn't? If there's something off about the indentation or organization, I'd love to hear it.

---

When I tried to break it in another way (for example with renpy dialogue), the same thing happened. Each time it's set back to the first character. You say that it goes to the beginning of the statement. Does that mean it goes back to the last label?

Are there any other ways to halt the game and let the player interact with screens for gameplay elements?

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

Re: Why do values change when you open the developer console?

#4 Post by philat »

Huh. I have no idea when Ren'Py was patched not to throw an error after an empty label -- logically, everything under a label should be indented and it definitely used to throw an error if not. (I am referring to the empty label start).

In any case, the way you organized your code is difficult to parse -- why are the two init pythons broken up? Why are there are screens in the middle of renpy label flow? Why are you setting up variables you're using (like dudeslist etc) in a python block instead of defaulting (this is likely to lead to reference or save/load issues)? etc.

Just returning from the screen call and re-calling it should work fine; what is the concern re: your last question?

User avatar
PyTom
Ren'Py Creator
Posts: 16093
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: Why do values change when you open the developer console?

#5 Post by PyTom »

I'll note that Ren'Py does a small rollback twhen it enters the console, which may reset some data.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
Chekhov
Regular
Posts: 113
Joined: Tue Jun 26, 2018 9:19 am
Projects: Pluton
Contact:

Re: Why do values change when you open the developer console?

#6 Post by Chekhov »

philat wrote: Fri Oct 04, 2019 11:26 pm Huh. I have no idea when Ren'Py was patched not to throw an error after an empty label -- logically, everything under a label should be indented and it definitely used to throw an error if not. (I am referring to the empty label start).

In any case, the way you organized your code is difficult to parse -- why are the two init pythons broken up? Why are there are screens in the middle of renpy label flow? Why are you setting up variables you're using (like dudeslist etc) in a python block instead of defaulting (this is likely to lead to reference or save/load issues)? etc.

Just returning from the screen call and re-calling it should work fine; what is the concern re: your last question?
Most answers to those questions is that I normally organize things into seperate files, but I like to have things in a certain order when I'm testing.

I continually learn and forget the lesson about setting up variables correctly and as a result I continue to have save/load issues. Thanks for pointing it out. I think the full understanding of how I should do it eludes me at the moment (I've known it previously, but I have a terrible forgetful mind). How do I make sure the variables get retained properly after load? Wouldn't using default just set them back to their default on load?

I suppose my concern for the last question is that I was using the developer console to test some things (using the print function, as well as calling certain functions from the developer console). However, it seems I can expect it to recall a little rollback on opening it, so I'll have to see if there's an alternate way to achieve testing the things I want to test.

In any case, Tom, Philat, thank you for the support!

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

Re: [Solved] Why do values change when you open the developer console?

#7 Post by Alex »

Chekhov wrote: Fri Oct 04, 2019 8:29 pm ...
My two cents - sometime values, that you show using screen, don't update onscreen. They have changed, but player will see it only when screen will be redrawn (updated), so try to read some more about screens and maybe rearrange your code.

Also, check this article - https://www.renpy.org/doc/html/save_load_rollback.html and try to use this function as an action when you showing the screen (on show) - https://www.renpy.org/doc/html/save_loa ... after-load

And there's a good article about code organization and its working flow - viewtopic.php?f=51&t=39572#p422964

Post Reply

Who is online

Users browsing this forum: Draida