What am I doing wrong here? trying to use python within rpy

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.
Message
Author
pk space jam
Newbie
Posts: 22
Joined: Mon Nov 18, 2013 2:46 am
Contact:

What am I doing wrong here? trying to use python within rpy

#1 Post by pk space jam »

I thought I was calling a python block correctly, but my game wont launch, suggestions?

Code: Select all

# Python Setup Dicts and other stuff.
    
    import python:
        major_npcs = {'bf' : 'Barry Fandling', 'sf' : 'Sherry Fandling',
                      'ag' : 'Angles Gator', 't' : 'Troid', 'pw' : 'Playton Williams',
                      'btf' : 'Barret Falster'}
        
        campers = {'pb' : 'Pooder Bennet', 'jf' : 'Jupiter Fargo', 
                   'rb' : 'Randy Buffet', 'bl' : 'Botany Lynn', 
                   'bt' : 'Boris Tortavich', 'tn' : 'Trinda Noober',
                   'fj' : 'Freetus Jaunders', 'nt' : 'Ninar Tetras',
                   'gm' : 'Gloobin Marfo', 'nk' : 'Niche Kaguya',
                   'bd' : 'Brent Drago', 'vt' : 'Volga Toober',
                   'kt' : 'Kinser Talebearing', 'br' : 'Bnola Rae',
                   'nb' : 'Nugget Beano', 'yk' : 'Yeldstat Krong',
                   'gy' : 'Gelliot Yabelor', 'il' : 'Illetia Dorfson',
                   'ct' : 'Can Tabber', 'tv' : 'Trinoba Vyder'}

        camper_gender = {'pb' : 'm', 'jf' : 'f',
                         'rb' : 'm', 'bl' : 'f', 
                         'bt' : 'm', 'tn' : 'f',
                         'fj' : 'm', 'nt' : 'f',
                         'gm' : 'm', 'nk' : 'f',
                         'bd' : 'm', 'vt' : 'f',
                         'kt' : 'm', 'br' : 'f',
                         'nb' : 'm', 'yk' : 'f',
                         'gy' : 'm', 'il' : 'f',
                         'ct' : 'm', 'tv' : 'f'}

        #Setting Some Disposistion values for characters in a dict

        dispo_couter = {'pb' : 0, 'jf' : 0,
                        'rb' : 0, 'bl' : 0, 
                        'bt' : 0, 'tn' : 0,
                        'fj' : 0, 'nt' : 0,
                        'gm' : 0, 'nk' : 0,
                        'bd' : 0, 'vt' : 0,
                        'kt' : 0, 'br' : 0,
                        'nb' : 0, 'yk' : 0,
                        'gy' : 0, 'il' : 0,
                        'ct' : 0, 'tv' : 0}

User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: What am I doing wrong here? trying to use python within

#2 Post by xavimat »

It should be "python:" not "import python:"
Also, maybe you need this in an init block (init python:)
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

pk space jam
Newbie
Posts: 22
Joined: Mon Nov 18, 2013 2:46 am
Contact:

Re: What am I doing wrong here? trying to use python within

#3 Post by pk space jam »

I keep getting this error! I switched it to init.

http://tinypic.com/r/eqv6g1/5

pk space jam
Newbie
Posts: 22
Joined: Mon Nov 18, 2013 2:46 am
Contact:

Re: What am I doing wrong here? trying to use python within

#4 Post by pk space jam »

Ok now I dont get it, fixed some things around, and now it wont open at all...

pk space jam
Newbie
Posts: 22
Joined: Mon Nov 18, 2013 2:46 am
Contact:

Re: What am I doing wrong here? Project crashing my computer

#5 Post by pk space jam »

I really dont get it, now when i try to open my project, it crashes my computer.


please help! i was making such progress!

Code: Select all

# You can place the script of your game in this file.

# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"

# Declare characters used by this game.

define pk = Character('Pickett', color="#c8ffc8")
    
# Python Setup Dicts and other stuff.
    
init python:
    major_npcs = {'bf' : 'Barry Fandling', 'sf' : 'Sherry Fandling',
                  'ag' : 'Angles Gator', 't' : 'Troid', 'pw' : 'Playton Williams',
                  'btf' : 'Barret Falster'}

    campers = {'pb' : 'Pooder Bennet', 'jf' : 'Jupiter Fargo', 
               'rb' : 'Randy Buffet', 'bl' : 'Botany Lynn', 
               'bt' : 'Boris Tortavich', 'tn' : 'Trinda Noober',
               'fj' : 'Freetus Jaunders', 'nt' : 'Ninar Tetras',
               'gm' : 'Gloobin Marfo', 'nk' : 'Niche Kaguya',
               'bd' : 'Brent Drago', 'vt' : 'Volga Toober',
               'kt' : 'Kinser Talebearing', 'br' : 'Bnola Rae',
               'nb' : 'Nugget Beano', 'yk' : 'Yeldstat Krong',
               'gy' : 'Gelliot Yabelor', 'il' : 'Illetia Dorfson',
               'ct' : 'Can Tabber', 'tv' : 'Trinoba Vyder'}

    camper_gender = {'pb' : 'm', 'jf' : 'f',
                     'rb' : 'm', 'bl' : 'f', 
                     'bt' : 'm', 'tn' : 'f',
                     'fj' : 'm', 'nt' : 'f',
                     'gm' : 'm', 'nk' : 'f',
                     'bd' : 'm', 'vt' : 'f',
                     'kt' : 'm', 'br' : 'f',
                     'nb' : 'm', 'yk' : 'f',
                     'gy' : 'm', 'il' : 'f',
                     'ct' : 'm', 'tv' : 'f'}

    #Setting Some Disposistion values for characters in a dict

    dispo_couter = {'pb' : 0, 'jf' : 0,
                    'rb' : 0, 'bl' : 0, 
                    'bt' : 0, 'tn' : 0,
                    'fj' : 0, 'nt' : 0,
                    'gm' : 0, 'nk' : 0,
                    'bd' : 0, 'vt' : 0,
                    'kt' : 0, 'br' : 0,
                    'nb' : 0, 'yk' : 0,
                    'gy' : 0, 'il' : 0,
                    'ct' : 0, 'tv' : 0}

# The game starts here.
label start:

    scene black
    with dissolve

    show text 'The Year Is 199X' with Pause(3.5)

    scene black
    with dissolve
    
    show text 'A 10 Year Old Boy Is Leaving For Summer Camp' with Pause(3.5)
    
    scene black
    with dissolve

    show text 'His Name, Is Pickett, & He Is The Hero Of This Story' with Pause(3.5)

    scene black
    with dissolve

    show text 'His Parents Shove Him On The Bus\nHe Takes A Seat Alone.' with Pause(3.5)

    scene black
    with dissolve

    #bully python code
    
    init python:

        from random import choice

        bully = choice(campers.keys())

        while bully != 'm':
            bully = choice(campers.keys())

        dispo_counter[bully] -= 1
 
    'Bully' 'Hey you kid, is that game kid? What is that?'

    return

User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: What am I doing wrong here? trying to use python within

#6 Post by xavimat »

Of course:
bully never will be 'm', it's an infinite loop.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

pk space jam
Newbie
Posts: 22
Joined: Mon Nov 18, 2013 2:46 am
Contact:

Re: What am I doing wrong here? trying to use python within

#7 Post by pk space jam »

xavimat wrote:Of course:
bully never will be 'm', it's an infinite loop.
How is that so? I dont think thats it, I think it was the init python statement, im getting a whole new error now, lol

I'm sorry, but an uncaught exception occurred.

Code: Select all

While executing init code:
  File "game/script.rpy", line 80, in script
  File "game/script.rpy", line 84, in python
NameError: name 'campers' is not defined

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

Full traceback:
  File "C:\Users\Ray\Desktop\Pickett\renpy-6.16.1-sdk\renpy\bootstrap.py", line 265, in bootstrap
    renpy.main.main()
  File "C:\Users\Ray\Desktop\Pickett\renpy-6.16.1-sdk\renpy\main.py", line 263, in main
    game.context().run(node)
  File "C:\Users\Ray\Desktop\Pickett\renpy-6.16.1-sdk\renpy\execution.py", line 288, in run
    node.execute()
  File "C:\Users\Ray\Desktop\Pickett\renpy-6.16.1-sdk\renpy\ast.py", line 720, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\Ray\Desktop\Pickett\renpy-6.16.1-sdk\renpy\python.py", line 1304, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/script.rpy", line 84, in <module>
    bully = choice(campers.keys())
NameError: name 'campers' is not defined
What the hell? I thought i defined campers as a dict?

User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: What am I doing wrong here? trying to use python within

#8 Post by xavimat »

Yes, is a dict, and you choose a key. Try this before the while loop:

Code: Select all

$ testing = campers.keys()
"[testing]"
You get the list of keys: [ 'pb', 'rb', 'bd', ....]
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

pk space jam
Newbie
Posts: 22
Joined: Mon Nov 18, 2013 2:46 am
Contact:

Re: What am I doing wrong here? trying to use python within

#9 Post by pk space jam »

xavimat wrote:Yes, is a dict, and you choose a key. Try this before the while loop:

Code: Select all

$ testing = campers.keys()
"[testing]"
You get the list of keys: [ 'pb', 'rb', 'bd', ....]
right, so how is it not defined? I dont get why im getting an error

pk space jam
Newbie
Posts: 22
Joined: Mon Nov 18, 2013 2:46 am
Contact:

Re: What am I doing wrong here? trying to use python within

#10 Post by pk space jam »

Like if i am doing

bully = choice(campers.keys())

I dont get how that isnt defind, it should assign randomly one of the keys to bully.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: What am I doing wrong here? trying to use python within

#11 Post by xavimat »

With the code you've posted the second time I don't get the error, the dict it's correctly defined.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: What am I doing wrong here? trying to use python within

#12 Post by xavimat »

And it chooses a key, but the key is never 'm', then the loop is infinite.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: What am I doing wrong here? trying to use python within

#13 Post by xavimat »

Maybe this works:?
while campers[bully] != 'm':
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

pk space jam
Newbie
Posts: 22
Joined: Mon Nov 18, 2013 2:46 am
Contact:

Re: What am I doing wrong here? trying to use python within

#14 Post by pk space jam »

Tried it, still getting the same error.

I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/script.rpy", line 80, in script
File "game/script.rpy", line 84, in python
NameError: name 'campers' is not defined

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

Full traceback:
File "C:\Users\Ray\Desktop\Pickett\renpy-6.16.1-sdk\renpy\execution.py", line 288, in run
node.execute()
File "C:\Users\Ray\Desktop\Pickett\renpy-6.16.1-sdk\renpy\ast.py", line 720, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "C:\Users\Ray\Desktop\Pickett\renpy-6.16.1-sdk\renpy\python.py", line 1304, in py_exec_bytecode
exec bytecode in globals, locals
File "game/script.rpy", line 84, in <module>
bully = choice(campers.keys())
NameError: name 'campers' is not defined

Windows-7-6.1.7601-SP1
Ren'Py 6.16.1.409
A Ren'Py Game 0.0



UGHHHHHH


in the meantime, how would it always be m? if it is randomly picking from the keys in the dict, it could be either 'm' or 'f'

pk space jam
Newbie
Posts: 22
Joined: Mon Nov 18, 2013 2:46 am
Contact:

Re: What am I doing wrong here? trying to use python within

#15 Post by pk space jam »

Did I break RenPy? lol

Post Reply

Who is online

Users browsing this forum: No registered users