Adding/defining Numerical Variables

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
Blantech
Newbie
Posts: 5
Joined: Tue Jun 12, 2018 4:22 am
Contact:

Adding/defining Numerical Variables

#1 Post by Blantech »

So I am doing good with my progress thus far just sorted out how to use the if system and True/False variables to trigger different content based on past choices player made. So now I am writing away the script for dialogue in another easier to storyboard up program so I can swap order of scenes and what not at will, and it hit me I want to use some numerical variables as well like a_like or a_romance then set off a event if they hit a_romance = 10 do a little event with the girl, then flip on the tag a_romance_event1= True

I am doing content with idea of player repeating some common interactions here and there with the characters and using that to build up their score to trigger the next stage from strangers to acquaintances and what not so relations ship builds up over time. So as much as I live the True/False set up I am looking at adding variable with numeric values as well, to give it more depth.

I got a pal who knows python who was saying I should be able to just ad a_romance +=1 to get a plus one to the players score but he knows python not renpy, and also isn't clear on how I define it as a variable but made sure to remind me before I defined it I started writing that into the script. I found lots of guides on basic True/false variables but nothing on numerical value ones.

pumpkin spike
Regular
Posts: 76
Joined: Fri Mar 09, 2018 6:13 pm
Projects: A Bureau of Monsters
itch: pumpkin-spike
Location: A Pumpkin Patch
Contact:

Re: Adding/defining Numerical Variables

#2 Post by pumpkin spike »

You can define a numerical variable at the beginning (before label start)

Code: Select all

default a_romance = 0
Then, to change it throughout the script

Code: Select all

$ a_romance+= 1
or

Code: Select all

$ a_romance = romance + 1
The single = sign is important since that means you're setting/changing the value of the variable. It is better in practice to use the first one (the one your friend mentioned).

To compare:

Code: Select all

if a_romance == 10:
    jump event
The double equal sign is for comparing. You can also use << for less than a certain number of points, or >> for greater than a certain number of points.
Image
WIP AllxAll game with turn based fighting (Demo 2.0 out!)

Image
WIP Yaoi game Demo 1.0 out! (haitus)

Blantech
Newbie
Posts: 5
Joined: Tue Jun 12, 2018 4:22 am
Contact:

Re: Adding/defining Numerical Variables

#3 Post by Blantech »

Thanks I figured it was easier then I thought, now the fun part writing story, in script format with these codes, and sorting out how I use multiple .rpy files I seen others do for their games like having one for each characters event chain...

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Adding/defining Numerical Variables

#4 Post by kivik »

You just create the multiple script files (make sure they have extension .rpy) and put it anywhere inside your game/ folder. Renpy automatically crawl through your folders looking for .rpy files.

Be careful if you ever rename your .rpy files, you'll need to rename / delete the corresponding .rpyc file.

The way Renpy works is: every time you launch your game, all the .rpy file gets compiled into .rpyc files, and all the .rpyc files found will be loaded. When you rename a .rpy file, it'll generate a new .rpyc file at launch, the old .rpyc doesn't get touched. This means you'll end up with two copies of the same compiled script file, and you'll have label and variable collisions and other things.

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: Adding/defining Numerical Variables

#5 Post by Remix »

Just as an aside:

pumpkin spike probably meant <= (less than or equal to) and >= (greater than or equal to)

>> and << in python are used for bit shifting and will likely really confuse a non programmer:
27 << 2 = 108 ... ( 27 is 11011 in binary, left shift 2 is 1101100 which is 108 in decimal )
Frameworks & Scriptlets:

pumpkin spike
Regular
Posts: 76
Joined: Fri Mar 09, 2018 6:13 pm
Projects: A Bureau of Monsters
itch: pumpkin-spike
Location: A Pumpkin Patch
Contact:

Re: Adding/defining Numerical Variables

#6 Post by pumpkin spike »

Remix wrote: Fri Jun 15, 2018 5:24 am Just as an aside:

pumpkin spike probably meant <= (less than or equal to) and >= (greater than or equal to)

>> and << in python are used for bit shifting and will likely really confuse a non programmer:
27 << 2 = 108 ... ( 27 is 11011 in binary, left shift 2 is 1101100 which is 108 in decimal )
Yes! I did, sorry about that, thank you for explaining it!
Image
WIP AllxAll game with turn based fighting (Demo 2.0 out!)

Image
WIP Yaoi game Demo 1.0 out! (haitus)

Post Reply

Who is online

Users browsing this forum: Google [Bot], Rhapsy