(SOLVED!) Resetting Your Point System Mid-game

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
Wudgeous
Regular
Posts: 58
Joined: Tue Apr 30, 2019 5:59 am
Tumblr: herotome
itch: wudgeous
Contact:

(SOLVED!) Resetting Your Point System Mid-game

#1 Post by Wudgeous »

Hi all! I'm a self-taught going-on-intermediate coder and I'm rather at my wit's end -- I've searched the documentation and forums to no avail. I could be looking in the wrong places or using the wrong search terms - in which case, some guidance would be deeply appreciated.


Context
In my game, I'm using the basic point-based system that works as such:

Code: Select all

label start:
    $ boy1_points = 5
    $ boy2_points = 5
    $ boy3_points = 5
    $ boy4_points = 5
    $ girl1_points = 5
    $ girl2_points = 5
    
As the game progresses, the character points(/affection) will increase/decrease. For example:

Code: Select all

"I give girl2 some flowers."
$ girl2_points += 1

My Dilemma is This:
During periodic checkpoints in the game, I would like to reset all these character affection points to 0. Obviously, I can manually put in

Code: Select all

$ boy1_points = 0
$ boy2_points = 0
$ boy3_points = 0
$ boy4_points = 0... (and so on)
...every single time. But seems terribly inefficient, considering there are a handful of characters to reset. :\


One of my Half-Baked Attempts at a Solution is This:
I tried the following (function? action?) for starters - not sure if I've just got the wrong syntax or if I'm even on the right track;

Code: Select all

init python:
	def resetallPoints():
		boy1_points = 0
		boy2_points = 0
		boy3_points = 0
		boy4_points = 0
		girl1_points = 0
		girl2_points = 0
      
label start:            
	$ boy1_points = 5
	$ girl1_points = 2
	
	girl1 "Right now, you have [boy1_points] points with boy1 and [girl1_points] points with me."
	girl1 "Let's go ahead and reset that..."
	$ resetallPoints
	girl1 "Now we have [boy1_points] and [girl1_points]!"

...but obviously running this just spat out an error. :( Thoughts? Alternatives? Links? Examples? I'll love you forever.
Last edited by Wudgeous on Sun Sep 22, 2019 9:35 am, edited 1 time in total.
Have confidence. Let go of perfectionism. I love you!
Image
A superhero dating sim in fresh hot development!


You can also keep up with me on Twitter and Itch!

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Resetting Your Point System Mid-game?

#2 Post by hell_oh_world »

Wudgeous wrote: Sun Sep 22, 2019 7:27 am Hi all! I'm a self-taught going-on-intermediate coder and I'm rather at my wit's end -- I've searched the documentation and forums to no avail. I could be looking in the wrong places or using the wrong search terms - in which case, some guidance would be deeply appreciated.


Context
In my game, I'm using the basic point-based system that works as such:

Code: Select all

label start:
    $ boy1_points = 5
    $ boy2_points = 5
    $ boy3_points = 5
    $ boy4_points = 5
    $ girl1_points = 5
    $ girl2_points = 5
    
As the game progresses, the character points(/affection) will increase/decrease. For example:

Code: Select all

"I give girl2 some flowers."
$ girl2_points += 1

My Dilemma is This:
During periodic checkpoints in the game, I would like to reset all these character affection points to 0. Obviously, I can manually put in

Code: Select all

$ boy1_points = 0
$ boy2_points = 0
$ boy3_points = 0
$ boy4_points = 0... (and so on)
...every single time. But seems terribly inefficient, considering there are a handful of characters to reset. :\


One of my Half-Baked Attempts at a Solution is This:
I tried the following (function? action?) for starters - not sure if I've just got the wrong syntax or if I'm even on the right track;

Code: Select all

init python:
	def resetallPoints():
		boy1_points = 0
		boy2_points = 0
		boy3_points = 0
		boy4_points = 0
		girl1_points = 0
		girl2_points = 0
      
label start:            
	$ boy1_points = 5
	$ girl1_points = 2
	
	girl1 "Right now, you have [boy1_points] points with boy1 and [girl1_points] points with me."
	girl1 "Let's go ahead and reset that..."
	$ resetallPoints
	girl1 "Now we have [boy1_points] and [girl1_points]!"

...but obviously running this just spat out an error. :( Thoughts? Alternatives? Links? Examples? I'll love you forever.
Just put parentheses on the function.
Also just to be sure, use namespace if you're using variables inside an init block.

Code: Select all

default boy1_points = 0
## and so on...
init python:
	def resetallPoints():
		store.boy1_points = 0
		store.boy2_points = 0
		store.boy3_points = 0
		store.boy4_points = 0
		store.girl1_points = 0
		store.girl2_points = 0
		## and so on...
      
label start:            
	$ boy1_points = 5
	$ girl1_points = 2
	
	girl1 "Right now, you have [boy1_points] points with boy1 and [girl1_points] points with me."
	girl1 "Let's go ahead and reset that..."
	$ resetallPoints() ## Parentheses here.
	girl1 "Now we have [boy1_points] and [girl1_points]!"

User avatar
Wudgeous
Regular
Posts: 58
Joined: Tue Apr 30, 2019 5:59 am
Tumblr: herotome
itch: wudgeous
Contact:

Re: (SOLVED!) Resetting Your Point System Mid-game

#3 Post by Wudgeous »

It works!! And I learned something!

Thank you Toby Maguire! <3



Edit: to reiterate to my future self: "store.boy1_points " is the namespace.
Have confidence. Let go of perfectionism. I love you!
Image
A superhero dating sim in fresh hot development!


You can also keep up with me on Twitter and Itch!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]