Using Multiple Screen Actions within One Action?

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
ShadowBoxGames
Newbie
Posts: 18
Joined: Fri Oct 07, 2016 9:58 pm
Tumblr: dozenroses.tumblr.com
Contact:

Using Multiple Screen Actions within One Action?

#1 Post by ShadowBoxGames »

Ok I've been finagling and searching endlessly through the forums and the documentation for an answer, and maybe I'm just looking for the wrong term, but I need help!

Here's what I want to do:
Create a shop screen using an imagemap, where the hotspots act as the buying options. A tooltip appears when you hover over the items, and then a new one appears if you choose to buy it. When you buy the item it will set a variable to True, as well as subtract a sum of money.

Here's the issue:
I have no idea, what Screen Action I should be using within the hotspot when it is True so that it:
1) Subtracts a certain amount of money AND
2) Sets a variable to False AND
3) Lets a new tooltip appear.

Here is my current code for the whole screen. Note that the first hotspot is different, as I was changing that up a bunch to try and figure it out first, before I applied it to the next hotspots (basically, I want all the hotspots to have the same actions, but I've only adjusted the first one for now):

Code: Select all

screen bookstore_screen:
    zorder 55
    default tt = Tooltip("")
    imagemap:
        ground "shop/bookstore_ground.png"
        idle "shop/bookstore_idle.png"
        hover "shop/bookstore_hover.png"
        #tact
        if not tactbook_bought:
            hotspot(292,122,144,126) action [If(money >= 45, true = tt.Action("Thank you for your purchase!"), false = tt.Action("I don't have enough money for that"))]hover_sound "Sounds/glass_button.mp3" activate_sound "Sounds/triangle.mp3" hovered tt.Action("Long sentence.... (+15 Tact)")
        #charisma
        if not charismabook_bought:
            hotspot(466,123,144,126) action Show("charismabook_screen") hover_sound "Sounds/glass_button.mp3" activate_sound "Sounds/triangle.mp3"hovered tt.Action("Long sentence.... (+15 Charisma)")
                                                                                
        #fashion
        if not fashionbook_bought:
            hotspot(641,123,144,126) action Show("fashionbook_screen") hover_sound "Sounds/glass_button.mp3" activate_sound "Sounds/triangle.mp3"hovered tt.Action("Long sentence.... (+15 Fashion Sense)")
        #wit
        if not witbook_bought:
            hotspot(813,123,144,126) action Show("witbook_screen") hover_sound "Sounds/glass_button.mp3" activate_sound "Sounds/triangle.mp3"hovered tt.Action("Long sentence.... (+15 Wit)")
        #fitness
        if not fitnessbook_bought:
            hotspot(989,123,144,126) action Show("fitnessbook_screen") hover_sound "Sounds/glass_button.mp3" activate_sound "Sounds/triangle.mp3"hovered tt.Action("Long sentence.... (+15 Fitness)")
            
        #henry +20
        if not henrybook_bought:
            hotspot(381,279,144,126) action Show("henrybook_screen") hover_sound "Sounds/glass_button.mp3" activate_sound "Sounds/triangle.mp3"hovered tt.Action("Long sentence.... .")
        #frank +20
        if not frankbook_bought:
            hotspot(555,278,144,126) action Show("frankbook_screen") hover_sound "Sounds/glass_button.mp3" activate_sound "Sounds/triangle.mp3"hovered tt.Action("Long sentence.... ")
        #joe +20
        if not joebook_bought:
            hotspot(728,279,144,126) action Show("joebook_screen") hover_sound "Sounds/glass_button.mp3" activate_sound "Sounds/triangle.mp3"hovered tt.Action("Long sentence.... ")
             
        if not nedbook_bought:
            hotspot (903,283,144,126) action Show("nedbook_screen") hover_sound "Sounds/glass_button.mp3" activate_sound "Sounds/triangle.mp3"hovered tt.Action("Long sentence.... ")
        #Done
        hotspot (11,123,222,55) action Return() hover_sound "Sounds/triangle.mp3" activate_sound "Sounds/da_ding.mp3"
        
        frame:
            xmaximum 747
            vbox:
                xpos 295
                ypos 558
                text tt.value size 20 font "Font/Contra.ttf" color "#682a14" outlines [ (1, "#efcba5", 1, 1) ]
        
        frame:
            xpos 50
            ypos 27
            has vbox
            text ("$ %d" %money)

        
This specific section is what I need help solving:

Code: Select all

if not tactbook_bought:
            hotspot(292,122,144,126) action [If(money >= 45, true = tt.Action("Thank you for your purchase!"), false = tt.Action("I don't have enough money for that"))]hover_sound "Sounds/glass_button.mp3" activate_sound "Sounds/triangle.mp3" hovered tt.Action("Long sentence... (+15 Tact)")
Basically, I want the action of clicking on this hotspot to not JUST show the tooltip

Code: Select all

tt.Action("Thank you for your purchase!")
but also
make

Code: Select all

$ tactbook_bought = True 
AND make

Code: Select all

 $ money -= 45 
Sorry if this is a confusing explanation. Just add a comment if you need more clarification! If anyone can help, I would much appreciate it! Or if maybe there is a simpler way to do this without creating a long string of Actions for the hotspot. Right now that is the only way I can think of, and I've tried several different actions shown in the Documentation and they've all just created more issues because I'm just confused by how exactly to code them in.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Using Multiple Screen Actions within One Action?

#2 Post by kivik »

So the short answer to your question is, you put your actions in a list, and weirdly you've started a list already, but you've put one action in it only.

Code: Select all

hotspot(292,122,144,126):
    action [If(money >= 45, true = tt.Action("Thank you for your purchase!"), false = tt.Action("I don't have enough money for that")), SetVariable("tactbook_bought", True), SetVariable("money", money-45)]
    hover_sound "Sounds/glass_button.mp3"
    activate_sound "Sounds/triangle.mp3"
    hovered tt.Action("Long sentence... (+15 Tact)")
The longer answer is - you may want to separate the logic from your screen code a bit, and perhaps use objects to manage your items. If you use objects to represent your items, you can actually use a single function and the object can determine the outcome (can you afford it? If so, buy it and subtract it's own value, else tell you that you can't afford it). It'd make your code a lot more flexible, want to add a new item? Just create another item object with its value and descriptions etc.

That said, if you don't think you'd be changing the number of items or editing them - then it may be more effort than it's worth to get into it. Object Orientation is one of those things where it's really powerful if you know how to do it, but you may need to invest in a bit of time to understand how they work first.

ShadowBoxGames
Newbie
Posts: 18
Joined: Fri Oct 07, 2016 9:58 pm
Tumblr: dozenroses.tumblr.com
Contact:

Re: Using Multiple Screen Actions within One Action?

#3 Post by ShadowBoxGames »

kivik wrote: Mon Jun 18, 2018 7:39 pm So the short answer to your question is, you put your actions in a list, and weirdly you've started a list already, but you've put one action in it only.

Code: Select all

hotspot(292,122,144,126):
    action [If(money >= 45, true = tt.Action("Thank you for your purchase!"), false = tt.Action("I don't have enough money for that")), SetVariable("tactbook_bought", True), SetVariable("money", money-45)]
    hover_sound "Sounds/glass_button.mp3"
    activate_sound "Sounds/triangle.mp3"
    hovered tt.Action("Long sentence... (+15 Tact)")
The longer answer is - you may want to separate the logic from your screen code a bit, and perhaps use objects to manage your items. If you use objects to represent your items, you can actually use a single function and the object can determine the outcome (can you afford it? If so, buy it and subtract it's own value, else tell you that you can't afford it). It'd make your code a lot more flexible, want to add a new item? Just create another item object with its value and descriptions etc.

That said, if you don't think you'd be changing the number of items or editing them - then it may be more effort than it's worth to get into it. Object Orientation is one of those things where it's really powerful if you know how to do it, but you may need to invest in a bit of time to understand how they work first.
Thank you for the help! Yeah I started the list and was trying different actions, like the SetVariable action, but it wasn't working (I believe it was because I was putting the commas and parentheses in the wrong place). So this really helps! Thank you!
Also, I would love to learn more about how Object Orientation works if it will be beneficial in the long run. I'm still new to understanding code in general, and am starting here with Ren'py. Do you have any helpful links that could explain more in depth about Object Orientation?

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Using Multiple Screen Actions within One Action?

#4 Post by kivik »

It's tricky for me to give good recommendations unfortunately as I learnt the concept of OOP years ago so I just had to learn the syntax for python. CodeAcademy has a good reputation and I can see they have a topic on Python Classes: https://www.codecademy.com/courses/lear ... se-classes

I don't know how detailed it gets into it as it's an interactive course - but it also means you get to try examples. Maybe have a look and let us know if it's any good (useful for future reference!). Same if you manage to come across any good ones on your findings so we know what to recommend in the future :)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]