Point System

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
Kaen
Regular
Posts: 148
Joined: Tue Oct 16, 2012 10:49 pm
Contact:

Point System

#1 Post by Kaen » Sat Jul 12, 2014 7:05 pm

I want to implement a point system on my game, but I'm facing a problem.

I'm storing the points on a persistent object, so even when the game is closed the points will remain saved:

Code: Select all

    $ persistent.coin_bronze = 1
    $ persistent.coin_silver = 2
    $ persistent.coin_gold = 3
The problem is, even if I don't save the game before closing, the points are still saved. So if I save before gaining points, I could easily farm points by loading after gaining points:

Code: Select all

    #saved the game here
    "now let's get some points!"
    $ persistent.coin_bronze += 1
    #load game
How can I prevent this?

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

Re: Point System

#2 Post by xela » Sat Jul 12, 2014 7:14 pm

Don't save your points as a part of persistent? Otherwise you could implement the counter as a class and control the input.
Like what we're doing? Support us at:
Image

User avatar
Kaen
Regular
Posts: 148
Joined: Tue Oct 16, 2012 10:49 pm
Contact:

Re: Point System

#3 Post by Kaen » Sat Jul 12, 2014 7:26 pm

I tried not using it as a persistent data but if I use those variables on other screens like the gallery screen it give me an error.

I don't know if I'm doing something wrong but normal variables I declare and use on the main script (after the start label) seems to not exist on the gallery screen (it's on the main menu, so I don't need to go to the main script to load this screen).

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

Re: Point System

#4 Post by xela » Sat Jul 12, 2014 7:38 pm

Ah, I see, you should have lead with that :)

You need to create a class or a function that would govern adding data to persistent or any other form of persistent data. Like if you save a dict:

Code: Select all

    $ persistent.coins_bronze = dict() # (Somewhere in the beginning of the game)
    #saved the game here
    "now let's get some points!"
    $ persistent.coins_bronze["location_1"] = 1
    #load game
Then in the main menu you can do something like $ bronze = sum(persistent.coins_bronze.values()) to get the total. You can do a lot of cool stuff with classes/function here to simplify this but it will only make sense if player can gather a few dozens of points at least.
Like what we're doing? Support us at:
Image

User avatar
LVUER
King of Lolies
Posts: 4538
Joined: Mon Nov 26, 2007 9:57 pm
Completed: R.S.P
Location: Bandung, West Java, Indonesia
Contact:

Re: Point System

#5 Post by LVUER » Sat Jul 12, 2014 7:42 pm

It's right that you're using a persistent variable for things like that. The problem is that when you get the points but haven't saved, you can just load the game to farm points, right? Even worse, if you don't disable rollback feature, player can just rollback and forth.

So the solution is more to the game design, like you can set a persistent variable to check whether a player already get the points for certain actions. If it's true, then that player will not get those points for doing the same actions... BTW, how player can get points? What action caused it and can it be repeated in same game?
"Double the princesses, quadruple the fun!" - Haken Browning (SRW-OG Endless Frontier)

DeviantArt Account
MoeToMecha Blog (under construction)
Lolicondria Blog (under construction) <- NSFW

User avatar
Kaen
Regular
Posts: 148
Joined: Tue Oct 16, 2012 10:49 pm
Contact:

Re: Point System

#6 Post by Kaen » Sat Jul 12, 2014 7:52 pm

LVUER wrote:It's right that you're using a persistent variable for things like that. The problem is that when you get the points but haven't saved, you can just load the game to farm points, right? Even worse, if you don't disable rollback feature, player can just rollback and forth.
Exactly, but I got the rollback covered haha!
LVUER wrote:So the solution is more to the game design, like you can set a persistent variable to check whether a player already get the points for certain actions. If it's true, then that player will not get those points for doing the same actions...
OMG that's a really simple solution, I love it! I'm gonna try this... I'm pretty sure it'll work fine with my game!
LVUER wrote:BTW, how player can get points? What action caused it and can it be repeated in same game?
Mostly by making right choices. There is a minigame the player may be able to play more than once through the story, so I'll have to add better control over it...
xela wrote:You need to create a class or a function that would govern adding data to persistent or any other form of persistent data. Like if you save a dict:
Thank you xela, though I still don't understand all of it >_<

Code: Select all

    $ persistent.coins_bronze = dict() #what dict() means/does?
    $ persistent.coins_bronze["location_1"] = 1 #I didn't follow the logic here sorry T-T

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

Re: Point System

#7 Post by xela » Sat Jul 12, 2014 8:07 pm

Dictionary, it's a key/value type of container. Whatever you're trying to do, it's doable. If you cannot figure it out, provide some more details.
Like what we're doing? Support us at:
Image

Post Reply

Who is online

Users browsing this forum: No registered users