Coding problems.

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
altartist1
Newbie
Posts: 3
Joined: Wed Jan 09, 2019 1:43 am
Contact:

Coding problems.

#1 Post by altartist1 »

I am having trouble giving affection points to characters in my game. In earlier lines of code, it works for some characters, but for the two I am trying to add, it is not working. It keeps coming up with the same 'undefined' message. I am having trouble trying to figure out what is wrong. Any help would be appreciated.

This is what I typed in for the new character.

Code: Select all

menu:
    "William Shakespeare.":
        $jane_aff += 5 
        jump problem1
    
    "Hemmingway?":
        $jane_aff -= 2
        jump problem2
    
    "I don't know...":
        $jane_aff = 0
        jump problem3
This is the error message that I am getting

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 343, in script
    $jane_aff -= 2
  File "game/script.rpy", line 343, in <module>
    $jane_aff -= 2
NameError: name 'jane_aff' is not defined

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 343, in script
    $jane_aff -= 2
  File "D:\renpy-7.1.1-sdk\renpy\ast.py", line 882, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "D:\renpy-7.1.1-sdk\renpy\python.py", line 1913, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/script.rpy", line 343, in <module>
    $jane_aff -= 2
NameError: name 'jane_aff' is not defined

Windows-7-6.1.7601-SP1
Ren'Py 7.1.1.929
The Clusterf*** that is my Love-Life 1.0
Wed Jan 09 13:40:35 2019

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Coding problems.

#2 Post by trooper6 »

It says that jane_aff is not defined.
Somewhere before the start label have you defined that variable using default?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

altartist1
Newbie
Posts: 3
Joined: Wed Jan 09, 2019 1:43 am
Contact:

Re: Coding problems.

#3 Post by altartist1 »

I did, I tried to set it to zero. Here is the code I used.

Code: Select all

label start:
    
    #Affection levels for potential love interests.
    $mom_aff = 0
    $sis_aff = 0
    $best_aff = 0
    $jane_aff = 0
    
 
It works for the mom and the sister, but it does not work for either best friend or Jane.

User avatar
Nagibator
Newbie
Posts: 16
Joined: Wed Jan 09, 2019 2:42 am
Contact:

Re: Coding problems.

#4 Post by Nagibator »

So, you tried putting the variables before the start label?
Like trooper6 said, I'd imagine it would go something like this:

Code: Select all

# Affection levels for potential love interests.
default mom_aff = 0
default sis_aff = 0
default best_aff = 0
default jane_aff = 0

label start:
I have no experience using "default", so if that doesn't work you could always try using "define" instead.
Regardless, if neither works, there's most likely an issue somewhere else. Are mom_aff and sis_aff used less or more than best_aff and jane_aff? I'd recommend swapping some of your variables (KEEP A LOG ON WHICH ONES YOU ARE DOING THIS TO) to see if they are interchangeable. If they are, there is nothing wrong with the variable but instead what you are trying to do with the variable.
Image

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Coding problems.

#5 Post by Imperf3kt »

altartist1 wrote: Wed Jan 09, 2019 5:13 am I did, I tried to set it to zero. Here is the code I used.

Code: Select all

label start:
    
    #Affection levels for potential love interests.
    $mom_aff = 0
    $sis_aff = 0
    $best_aff = 0
    $jane_aff = 0
    
 
It works for the mom and the sister, but it does not work for either best friend or Jane.
This is exactly the cause of the issue you are seeing. The simple solution is to use default as shown below by Nagibator
Nagibator wrote: Wed Jan 09, 2019 5:55 am

Code: Select all

# Affection levels for potential love interests.
default mom_aff = 0
default sis_aff = 0
default best_aff = 0
default jane_aff = 0

label start:
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Coding problems.

#6 Post by trooper6 »

One should never use define for variables that will change, only default. Things get messed up otherwise.

If after making sure your variables are defined using default before the start label, if there are still problems--but only with one variable--the next most likely cause is a spelling inconsistency. jane_aff in the definition, Jane_aff later, for example.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

altartist1
Newbie
Posts: 3
Joined: Wed Jan 09, 2019 1:43 am
Contact:

Re: Coding problems.

#7 Post by altartist1 »

Okay, thanks guys. I will try these out and see if they work.

Post Reply

Who is online

Users browsing this forum: Semrush [Bot]