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
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 »

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: 560
Joined: Sun Feb 12, 2012 9:17 am
Completed: Locked-In, Sunrise, The Censor
Organization: Lucky Special Games
itch: saguarofoo
Location: USA
Contact:

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

#2 Post by saguaro »

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)

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 »

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: Google [Bot], munni