Rolling back array

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
RewindTheGame
Regular
Posts: 80
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Rolling back array

#1 Post by RewindTheGame »

I'm a bit confused about why this isn't working properly. In my game, I have an array of 7x7 elements representing a maze the player has to navigate - each element of the array is a position in the maze represented by a 0 or a 1. When the player visits a location in the maze, the corresponding x and y array element is set to 1 to show they've been there, and when they've visited all 49 locations, they get an award.

The maze is navigated via simple menus where the player can choose North, South, East or West to move to another location - so after they've moved around the maze for a bit, the array will have 1s in all the places they've been. The problem is that, if the user chooses to rollback at any point while exploring the maze, the array doesn't roll back and continues to show all the places the player had visited before they rolled back. It's as if the array variable isn't restored when rolling back, which I don't understand because all other variables in my game roll back fine.

This is a problem because there's also a separate variable called squareswalked which counts the number of rooms visited on the grid, and this rolls back correctly - so you end up with the squareswalked variable not representing the number of 1s in the array - screwing the game up.

What's happening here?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2447
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Rolling back array

#2 Post by Ocelot »

Can't say without looking at the code. The simplest explanation would be that maze array is not declared using default, but I suspect that it could be something more nuanced.
< < insert Rick Cook quote here > >

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1057
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Rolling back array

#3 Post by m_from_space »

RewindTheGame wrote: Sat May 25, 2024 12:31 pm What's happening here?
How is the "array" (you probably mean a "list" of lists or some kind of dictionary?) initialized in your project and how do you change variables as part of the menu navigation? Can you give me some example code?

giorgi1111
Regular
Posts: 83
Joined: Sat May 04, 2024 10:40 pm
Contact:

Re: Rolling back array

#4 Post by giorgi1111 »

Renpy works differently.when i first created map had screens with mostly 3 imagebuttons . First and third active and second current innactive button .this buttons had actions to show hide screens some other functions.but it was not saving . Than i took actions in labels and imagebuttons action was to jump on labels. it worked perfectly.and if mean in roll back renpy roll back i dont think it sets variables back.i am disabling rollback in all my projects as they are not visual nowels

RewindTheGame
Regular
Posts: 80
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Re: Rolling back array

#5 Post by RewindTheGame »

giorgi1111 wrote: Sat May 25, 2024 2:30 pm Renpy works differently.when i first created map had screens with mostly 3 imagebuttons . First and third active and second current innactive button .this buttons had actions to show hide screens some other functions.but it was not saving . Than i took actions in labels and imagebuttons action was to jump on labels. it worked perfectly.and if mean in roll back renpy roll back i dont think it sets variables back.i am disabling rollback in all my projects as they are not visual nowels
That's how I've got around the problem, by disabling rollback in the maze. To be honest, having rollback in a maze sort of defeats the purpose of having a maze in the first place as you can pretty much force your way to the exit.

VictoriaCox
Newbie
Posts: 1
Joined: Thu May 23, 2024 9:38 am
Contact:

Re: Rolling back array

#6 Post by VictoriaCox »

You are right, I agree with you on that.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], voluorem