Page 1 of 2

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

Posted: Mon Nov 18, 2013 6:28 pm
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}

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

Posted: Mon Nov 18, 2013 6:34 pm
by xavimat
It should be "python:" not "import python:"
Also, maybe you need this in an init block (init python:)

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

Posted: Mon Nov 18, 2013 6:48 pm
by pk space jam
I keep getting this error! I switched it to init.

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

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

Posted: Mon Nov 18, 2013 6:51 pm
by pk space jam
Ok now I dont get it, fixed some things around, and now it wont open at all...

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

Posted: Mon Nov 18, 2013 6:57 pm
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

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

Posted: Mon Nov 18, 2013 7:06 pm
by xavimat
Of course:
bully never will be 'm', it's an infinite loop.

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

Posted: Mon Nov 18, 2013 7:09 pm
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?

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

Posted: Mon Nov 18, 2013 7:11 pm
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', ....]

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

Posted: Mon Nov 18, 2013 7:14 pm
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

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

Posted: Mon Nov 18, 2013 7:15 pm
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.

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

Posted: Mon Nov 18, 2013 7:17 pm
by xavimat
With the code you've posted the second time I don't get the error, the dict it's correctly defined.

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

Posted: Mon Nov 18, 2013 7:18 pm
by xavimat
And it chooses a key, but the key is never 'm', then the loop is infinite.

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

Posted: Mon Nov 18, 2013 7:22 pm
by xavimat
Maybe this works:?
while campers[bully] != 'm':

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

Posted: Mon Nov 18, 2013 7:26 pm
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'

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

Posted: Mon Nov 18, 2013 7:32 pm
by pk space jam
Did I break RenPy? lol