Array values reset when reloading (Solved)

In this forum we discuss the future of Ren'Py, both bug fixes and longer-term development. Pre-releases are announced and discussed here.
Post Reply
Message
Author
User avatar
Steamgirl
Veteran
Posts: 322
Joined: Sat Jul 28, 2012 4:39 am
Completed: My Cup of Coffee, Queen at Arms (co-wrote a battle scene)
Projects: Stranded Hearts, Emma: A Lady's Maid
Deviantart: steamgirlgame
Contact:

Array values reset when reloading (Solved)

#1 Post by Steamgirl » Thu Jul 23, 2015 7:04 am

So I came across this weird bug this morning that I couldn't for the life of me figure out. I had a menu that showed buttons depending on some values in an array, and everything worked in the game until about halfway through when suddenly all the values reset. I searched my script to see what on Earth could be causing it, but couldn't find anything. I played through the game again (from a fresh start) and it worked this time round. Then later it didn't work again.

I spend a bunch of time tracking it down until I thought... hang on, it happened after I reloaded. Surely it couldn't be resetting the values?! Then I tested it by running the game, going to the custom menu - everything looked correct. I reload and VOILA the bug happened! Reproduceable 5/5 times.

Unlike variables outside of arrays, which don't reset to default upon reload, variables in arrays do! Is this a bug or intentional?
Last edited by Steamgirl on Thu Jul 23, 2015 2:25 pm, edited 1 time in total.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Array values reset when reloading

#2 Post by xela » Thu Jul 23, 2015 7:27 am

It's neither, you need to define your list (and all variables) either using the define statement or after label start.
Like what we're doing? Support us at:
Image

User avatar
Steamgirl
Veteran
Posts: 322
Joined: Sat Jul 28, 2012 4:39 am
Completed: My Cup of Coffee, Queen at Arms (co-wrote a battle scene)
Projects: Stranded Hearts, Emma: A Lady's Maid
Deviantart: steamgirlgame
Contact:

Re: Array values reset when reloading

#3 Post by Steamgirl » Thu Jul 23, 2015 7:55 am

Hi xela,

Thanks for the suggestion! I tried using define but the issue still happens? Is it because it's in "init"?

Code: Select all

init:
    $ wedding_choice = 0
    define wedding_choice_text = ["Rings", "Wedding Dress", "Cake", "Flowers", "Venue", "Guest List", "Register Office", "Bridesmaids", "Photographer"]
    define wedding_choice_done = [False, False, False, False, False, False, False, False, False]
    define wedding_choice_cost = [10, 25, 25, 10, 50, 5, 10, 10, 25]

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Array values reset when reloading

#4 Post by xela » Thu Jul 23, 2015 8:08 am

My bad, I always use python after label start.

Correct way is:

Code: Select all

    $ wedding_choice = 0
    default wedding_choice_text = ["Rings", "Wedding Dress", "Cake", "Flowers", "Venue", "Guest List", "Register Office", "Bridesmaids", "Photographer"]
    default wedding_choice_done = [False, False, False, False, False, False, False, False, False]
    default wedding_choice_cost = [10, 25, 25, 10, 50, 5, 10, 10, 25]
It does not matter if it is in the init or not.

Wedding choice should also be declared in the same way or it will also reset.
Like what we're doing? Support us at:
Image

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Array values reset when reloading

#5 Post by trooper6 » Thu Jul 23, 2015 8:14 am

ETA: Ninja'd

Xela is correct, but made a typo with the keyword.

Either do this (which is the brand new way):

Code: Select all

default wedding_choice_text = ["Rings", "Wedding Dress", "Cake", "Flowers", "Venue", "Guest List", "Register Office", "Bridesmaids", "Photographer"]
Or do this:

Code: Select all

label start:
    $wedding_choice_text = ["Rings", "Wedding Dress", "Cake", "Flowers", "Venue", "Guest List", "Register Office", "Bridesmaids", "Photographer"]
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Steamgirl
Veteran
Posts: 322
Joined: Sat Jul 28, 2012 4:39 am
Completed: My Cup of Coffee, Queen at Arms (co-wrote a battle scene)
Projects: Stranded Hearts, Emma: A Lady's Maid
Deviantart: steamgirlgame
Contact:

Re: Array values reset when reloading

#6 Post by Steamgirl » Thu Jul 23, 2015 8:22 am

Well that's just the thing, variables outside of arrays don't reset upon reloading so it doesn't matter for wedding_choice. It's never mattered for any variables before which is why I didn't think it would matter for arrays.

When I use default it gives me an "expected statement" error?

default wedding_choice_text (pointy red arrow)= ["Rings", "Wedding Dress", "Cake", "Flowers", "Venue", "Guest List", "Register Office", "Bridesmaids", "Photographer"]

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Array values reset when reloading

#7 Post by trooper6 » Thu Jul 23, 2015 11:49 am

First off, this should be in the questions thread.
Secondly, could you post your code and error message?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

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: Array values reset when reloading

#8 Post by PyTom » Thu Jul 23, 2015 11:51 am

Also, Steamgirl should update to 6.99.5, as the default statement was recently introduced.
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
Steamgirl
Veteran
Posts: 322
Joined: Sat Jul 28, 2012 4:39 am
Completed: My Cup of Coffee, Queen at Arms (co-wrote a battle scene)
Projects: Stranded Hearts, Emma: A Lady's Maid
Deviantart: steamgirlgame
Contact:

Re: Array values reset when reloading

#9 Post by Steamgirl » Thu Jul 23, 2015 2:25 pm

Thanks for all the help everyone! I just saw another similar thread so I feel like a right derp for duplication!
Also, I'm an idiot for not trying to update my version of renpy before posting here, hehe. :)

Default works! Hurrah! :)

Post Reply

Who is online

Users browsing this forum: No registered users