[Solved] What's the official, correct way, to declare & use variables with custom python function to avoid all 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
henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

[Solved] What's the official, correct way, to declare & use variables with custom python function to avoid all problems?

#1 Post by henvu50 »

From RenpyTom in discord: "I pretty much use global exclusively. Store is used in special cases - for example, SetVariable(...) is actually SetField(store, ...)"

How to fix: local variable 'locCur' referenced before assignment

Code: Select all

default locCur = "testC"
default locN= "testN"

init python:
  global locCur #SOLUTION
  global locN  #SOLUTION
  def func_1():  
    # for reference, the following use of store. also fixes the problem, but RenpyTom uses global, so I'll use global as well.
    # if store.locCur != store.locN
    if locCur != locN:
      # dostuff

Post Reply

Who is online

Users browsing this forum: Google [Bot]