Ren'Py Running an Action within a Label

Xavster

Well-Known Member
Game Developer
Mar 27, 2018
1,243
7,569
Within my current game I have a screen that updates a series of calculations each time a button is pressed that affects the input variables.

A example of this button code is below:
Python:
imagebutton auto "/pur/bp_buy_1_%s.png" action [SetVariable("manu_plating_iron", manu_plating_iron + 1),Manu()]
This then runs the Manu(), which does the calculation. A subset of this is below (abbrev. manu()).
Python:
    class Manu(Action):
        def __call__(self):
            manu()
            renpy.restart_interaction()

    def manu():
        store.dem_iron = manu_framing_iron * 10 + manu_framing_stainless * 6 + manu_plating_iron * 12
The above all works very well within the screen itself.

The challenge is that I also modify the variables such as manu_plating_iron within a label. Hence I want to recalculate all of the variables in def manu() as part of that label without requiring a button press. Is it possible to run Manu() from within a label?

PS: The simple solution is to just copy all of the formulae into the label, however this is less than elegant.
 

Xavster

Well-Known Member
Game Developer
Mar 27, 2018
1,243
7,569
I think this is what you're looking for:
Just added the following code to the label and certainly updates the calculation from the label however causes a secondary problem.
Python:
    $ manu = store.manu()
When I attempt to use the buttons as before, hence initiating the calculation via a screen action, I get the following error:
'NoneType' object is not callable
 
Last edited:

Xavster

Well-Known Member
Game Developer
Mar 27, 2018
1,243
7,569
Found a fix of the above by adjusting the line of code to the following:
Python:
$ update = store.manu()
I think setting manu to something else caused chaos. Note that 'update' can really be anything from what I can tell. It runs the calculation, however never assigns anything to the update variable.

Note that if you can foresee a problem with doing the above, please let me know.
 
  • Like
Reactions: Saki_Sliz

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,302
15,172
A example of this button code is below:
Python:
imagebutton auto "/pur/bp_buy_1_%s.png" action [SetVariable("manu_plating_iron", manu_plating_iron + 1),Manu()]
This then runs the Manu(), which does the calculation. A subset of this is below (abbrev. manu()).
Python:
    class Manu(Action):
        def __call__(self):
            manu()
            renpy.restart_interaction()

    def manu():
        store.dem_iron = manu_framing_iron * 10 + manu_framing_stainless * 6 + manu_plating_iron * 12

Why all this ?

Python:
init python:
    def manu():
        store.dem_iron = manu_framing_iron * 10 + manu_framing_stainless * 6 + manu_plating_iron * 12

screen whatever():
    imagebutton auto "/pur/bp_buy_1_%s.png" action [SetVariable("manu_plating_iron", manu_plating_iron + 1), Function( manu ) ]
Will do exactly the same. And then when you need to do the computation from a label, you just use $ manu().
 

Xavster

Well-Known Member
Game Developer
Mar 27, 2018
1,243
7,569
Why all this ?
Because I don't know what I am doing. :ROFLMAO:

Grabbed some old code and made it work to my needs. Often though, as I have not had any formal training, my knowledge of the programming fundamentals is lacking.

I'll make the recommended changes and test it out. ;)
 
  • Like
Reactions: Saki_Sliz

Xavster

Well-Known Member
Game Developer
Mar 27, 2018
1,243
7,569
anne O'nymous - Made the changes as recommended and everything seems to be working as intended.(y)

Have implemented a number of game mechanics into Stellar Crossroads already, however v0.5 will see the most challenging game mechanic come into play. Planning on creating a space combat simulator. It will involve design of your fleet composition and then battle strategy. It will then simulate over a number of turns with player having the ability to change strategy if required. I am confident that I can get something working, however will likely post details of this project, such that the community can assist in making it as professional as possible.
 
  • Thinking Face
Reactions: gojira667