Using Actions in Screen Language to Append to arrays?

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
User avatar
babyfish
Veteran
Posts: 203
Joined: Mon Mar 07, 2011 3:57 pm
Projects: Maid of Midsummer (LifeSim)
Location: (' )< Swimming in your fishbowl, nomming on flakes.
Contact:

Using Actions in Screen Language to Append to arrays?

#1 Post by babyfish » Fri Jan 18, 2013 3:13 am

A certain headscratcher has been bugging me for quite some time now (Yes, I'm back to working on my project again, bits and pieces at a time), and I'm hoping someone could help me out.

Is there any action at all in Screen Language that allows me to somehow append to arrays?

For example, at initialization, I have an array that determines the inventory that the character has in possession at the start of the game.

Code: Select all

    python:
        inventory= [
            (potion),
            (item_uniform),
            (item_partydress),        
            ]
I also have a screen, a shop function basically, that I would like to be able to inventory.append using Screen Language. More specifically, through a textbutton. Think this is possible with an action? or will I have to recreate my screen in python code in order to do this?

Thanks bunches, hope I didn't confuse anyone~

~fish
Image
(Work in progress)

(' )< -babyfish

User avatar
saguaro
Miko-Class Veteran
Posts: 557
Joined: Sun Feb 12, 2012 9:17 am
Completed: Locked-In, Sunrise, The Censor
Projects: ?
Organization: Lucky Special Games
Tumblr: saguarofoo
itch: saguarofoo
Location: USA
Contact:

Re: Using Actions in Screen Language to Append to arrays?

#2 Post by saguaro » Fri Jan 18, 2013 9:33 am

You can have the textbutton action use a function that appends an element to a list. If the function has an argument, you curry it first.

Code: Select all

screen shop:
    ...
    textbutton "Buy" action BuyItem(item)

...

init python:
    def buy_item(item):
        ...
        inventory.append(item)

    BuyItem = renpy.curry(buy_item)

User avatar
babyfish
Veteran
Posts: 203
Joined: Mon Mar 07, 2011 3:57 pm
Projects: Maid of Midsummer (LifeSim)
Location: (' )< Swimming in your fishbowl, nomming on flakes.
Contact:

Re: Using Actions in Screen Language to Append to arrays?

#3 Post by babyfish » Sun Jan 20, 2013 11:32 pm

managed to find a way around this problem, but nice to know I can define new screen actions if I need to

Thanks!
Image
(Work in progress)

(' )< -babyfish

Post Reply

Who is online

Users browsing this forum: No registered users