How do I make stats formulas?[Solved]

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
zaWarrrdo
Newbie
Posts: 3
Joined: Tue Aug 28, 2018 10:10 am
Contact:

How do I make stats formulas?[Solved]

#1 Post by zaWarrrdo »

Hi!

How can I make formulas with variables for stats?
With this code I'm getting error "bsmth is not defined"
How do we define them ?

Code: Select all

default bsmth = 0
default alch = 0
default herb = 0
default comb = 0
define lvl = 1+bsmth+alch+herb+comb
define hp = (18+lvl+3**herb)+(18+lvl+3**herb)*alch*0,01
define defph = (0+lvl%2+2,4**bsmth)+(0+lvl%2+2,4**bsmth)*alch*0,02
define dps = (0+lvl%4+2**comb)+(0+lvl%4+2**comb)*alch*0,03
Last edited by zaWarrrdo on Wed Aug 29, 2018 3:33 am, edited 1 time in total.

User avatar
Morhighan
Miko-Class Veteran
Posts: 975
Joined: Sun Jun 27, 2010 12:54 pm
Completed: AIdol, When Our Journey Ends, Forgotten Not Lost
Organization: MysteryCorgi
Tumblr: MysteryCorgi
Deviantart: MysteryCorgi
Soundcloud: MysteryCorgi
itch: MysteryCorgi
Location: USA
Contact:

Re: How do I make stats formulas?

#2 Post by Morhighan »

I am using this Ren'Py Documentation Page for reference and my best guess for what is happening is this:
Variables that are defined using the define statement are treated as constant, are not saved or loaded, and should not be changed. (Ren'Py does not enforce this, but will produce undefined behavior when this is not the case.)
My best guess for remedying this error is something like having the following in option.rpy or its own script file.

Code: Select all

#define all values
default bsmth = 0
default alch = 0
default herb = 0
default comb = 0
default lvl = 1
default hp = 10 #or whatever the inital number you want it to be is
default defph = 10 #or whatever the inital number you want it to be is
default dps = 10 #or whatever the inital number you want it to be is
#now that values are defined they can be changed after the start of the game in script.rpy:

Code: Select all

label start:
	
	"Hello world! I am a new adventurer."
	
	$ lvl = 1+bsmth+alch+herb+comb
	$ hp = (18+lvl+3**herb)+(18+lvl+3**herb)*alch*0,01
	$ defph = (0+lvl%2+2,4**bsmth)+(0+lvl%2+2,4**bsmth)*alch*0,02
	$ dps = (0+lvl%4+2**comb)+(0+lvl%4+2**comb)*alch*0,03
	
	"My level is [lvl]. My HP is [hp]. My defph is [defph]. My DPS is [dps]."
	

I haven't tested this myself, but I'm hoping this gives you a good place to start. Let me know if you have any questions. :)

zaWarrrdo
Newbie
Posts: 3
Joined: Tue Aug 28, 2018 10:10 am
Contact:

Re: How do I make stats formulas?

#3 Post by zaWarrrdo »

Thank you very much!

Another question:

Why do I get tuple instead of number, when I use this formula?
How can I rewrite it?
The main idea is that Health Points depend on lvl, skill of herbalism "herb" and skill of alchemy "alch"

Code: Select all

$hp = (18+lvl+3**herb)+(18+lvl+3**herb)*alch*0,01
while lvl=1 herb=0 alch=0
It should be 18+1+3**0=20
But instead I get (20,1) as tuple.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How do I make stats formulas?

#4 Post by Remix »

alch*0.01

Python (and most of the world uses a dot/period . to indicate decimal point)
Frameworks & Scriptlets:

zaWarrrdo
Newbie
Posts: 3
Joined: Tue Aug 28, 2018 10:10 am
Contact:

Re: How do I make stats formulas?[Solved]

#5 Post by zaWarrrdo »

Thank you, Remix!

Post Reply

Who is online

Users browsing this forum: Google [Bot]