Adding variables together

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
Luxtizer
Newbie
Posts: 6
Joined: Fri Apr 13, 2012 4:33 am
Contact:

Adding variables together

#1 Post by Luxtizer » Sun Sep 16, 2012 7:03 pm

Hey folks,

I'm having what is probably a very simple to fix issue, but I can't quite figure it out. I'm trying to create a variable which is equal to the value of five other variables added together. I want variable 'x' to be equal to the sum of variables a, b, c, d, and e. So I write the code like this:

$ x == a + b + c + d + e

For some reason, this always seems to give me a value of 0 for x no matter what the other variables are. What am I doing wrong here?

apricotorange
Veteran
Posts: 479
Joined: Tue Jun 05, 2012 2:01 am
Contact:

Re: Adding variables together

#2 Post by apricotorange » Sun Sep 16, 2012 7:05 pm

Assignment is one equal sign, not two.

On a side note, please use

Code: Select all

 tags for code.

User avatar
Minnfae
Regular
Posts: 106
Joined: Mon Dec 07, 2009 5:01 am
Projects: Undecided
Contact:

Re: Adding variables together

#3 Post by Minnfae » Sun Sep 16, 2012 7:07 pm

Two equal signs are only used for comparisons, only one is necessary for assignment
My avatar art is a freebie by SilverHyena. Thanks a lot!

Luxtizer
Newbie
Posts: 6
Joined: Fri Apr 13, 2012 4:33 am
Contact:

Re: Adding variables together

#4 Post by Luxtizer » Sun Sep 16, 2012 7:08 pm

That fixed it. Thank you, and sorry for missing the tag.

User avatar
fantanoice
Newbie
Posts: 8
Joined: Sun Sep 16, 2012 8:23 am
Contact:

Re: Adding variables together

#5 Post by fantanoice » Mon Sep 17, 2012 8:33 am

Yep, basically '==' is for comparing if something 'is equal to' something else. '=' is for assigning a value to something.

Eg: Comparision:
if(something == true)
do stuff
('Do stuff' is only done when 'something' is true).

Eg: Assignment:
something = 1 + 2
('Something' now has the value of '3').


Did that make sense?

Post Reply

Who is online

Users browsing this forum: Google [Bot], Ocelot, zyric