Page 1 of 1

Coding problems.

Posted: Wed Jan 09, 2019 1:53 am
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

Re: Coding problems.

Posted: Wed Jan 09, 2019 2:19 am
by trooper6
It says that jane_aff is not defined.
Somewhere before the start label have you defined that variable using default?

Re: Coding problems.

Posted: Wed Jan 09, 2019 5:13 am
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.

Re: Coding problems.

Posted: Wed Jan 09, 2019 5:55 am
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.

Re: Coding problems.

Posted: Wed Jan 09, 2019 8:12 am
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:

Re: Coding problems.

Posted: Wed Jan 09, 2019 12:28 pm
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.

Re: Coding problems.

Posted: Wed Jan 09, 2019 9:22 pm
by altartist1
Okay, thanks guys. I will try these out and see if they work.