help with set-variable for image buttons - I think

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.
Message
Author
Kaldonis
Newbie
Posts: 15
Joined: Tue Dec 12, 2017 6:37 pm
Contact:

help with set-variable for image buttons - I think

#1 Post by Kaldonis »

Hello all,
First of all for any who take the time to read this, you have my thanks. This is the first post I have ever made to the forum, this place has helped me in so many ways and possibly this question has been answered before but I can't seem to put in the right search criteria to find what i'm looking for.
I think I will need to do something with the set variable function. My programming language is limited to say the lease but i'm learning from the forums here.

My problem is this.
I have an image button that is part of the user interface (which appears on every screen) The user can click a button and is given a general description of the area or tips for the location.

I've set the location to default = none at the start of the game then when the first scene is called the new location is set like this

Code: Select all

screen mc_bedroom:
    $ location = "mcbedroom"
    imagemap:
        ground 'bg/mc_bedroom.png'
        idle 'bg/mc_bedroom.png'
       
        alpha False
Currently I've got the following code for the image button (I know this isn't going to work but its the best I could come up with at the time)

Code: Select all

imagebutton auto "buttons/talk_%s.png" xpos 0 ypos 0 focus_mask True action show("location_talk")
I've got a separate file for all the locations and what I want the character to say per location but I do not want a new screen to be called, just the character to say in the a dialogue box.
A brief example is below

Code: Select all

$ location_talk
        if location = mcbedroom
            "this is my room".
        if location = park
            "this is a nice park"
        if location = beach
            "Time to work on my tan"
(which isn't working either, so I have something wrong there too :? )

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/switchtalk.rpy", line 2: Line is indented, but the preceding one-line python statement statement does not expect a block. Please check this line's indentation.
    if location = mcbedroom
From what I have found on the forum I need something like [SetVariable(location_talk), show("location")] or something to that effect. But more than likely I'm totally going about this wrong.

If anyone can help I would be so very grateful.

User avatar
erickcire95
Regular
Posts: 33
Joined: Tue Dec 26, 2017 7:38 pm
Contact:

Re: help with set-variable for image buttons - I think

#2 Post by erickcire95 »

If you don't want a screen to be called then don't use the action Show(), instead use Jump()

I'm not sure if this will work, but hopefully this can lead you to the solution

Try this

Code: Select all

imagebutton:
	auto "buttons/talk_%s.png"
	xpos 0 ypos 0 focus_mask True
	action Jump("location_talk")
	
And for the locations, remember that you must use double "=" to check for equalty. And don't forget to add quotes ' " '

Also, set the label this way:

Code: Select all

label location_talk:
        if location == "mcbedroom"
            "this is my room"
        if location == "park"
            "this is a nice park"
        if location == "beach"
            "Time to work on my tan"
            

These are the basic mistakes I spotted, but I'm not sure if it will work, sorry

Kaldonis
Newbie
Posts: 15
Joined: Tue Dec 12, 2017 6:37 pm
Contact:

Re: help with set-variable for image buttons - I think

#3 Post by Kaldonis »

Thank you very much for responding so quick, I've tried your suggestions and at least the game works now with the changes to the location_talk.
I've changed the button code as suggested and the weirdest thing is happening that now when I press the button it takes me back directly to the main menu.

I'll have another to see if I can work out why its doing that a little later today. Thanks once again for your help it is much appreciated.

Kaldonis
Newbie
Posts: 15
Joined: Tue Dec 12, 2017 6:37 pm
Contact:

Re: help with set-variable for image buttons - I think

#4 Post by Kaldonis »

So I've been trying to get this to stop returning to the main menu with no success.
If I change the Jump to Show or Call I get errors. Afraid I'm stumped on this one.

Kaldonis
Newbie
Posts: 15
Joined: Tue Dec 12, 2017 6:37 pm
Contact:

Re: help with set-variable for image buttons - I think

#5 Post by Kaldonis »

Quick update, I removed the if statement completely and the button brings up the text correctly but now obviously I will get the same text no matter the location.
As soon as the if statements go back in, the button just returns to the main menu.
If anyone else has a solution or could point me in a direction to look in. I would be most grateful.

timdonehy200
Newbie
Posts: 20
Joined: Sun Mar 12, 2017 6:15 am
Deviantart: timdonehy200
Contact:

Re: help with set-variable for image buttons - I think

#6 Post by timdonehy200 »

Shouldn't there be ":" at the end of each "if" line?

Kaldonis
Newbie
Posts: 15
Joined: Tue Dec 12, 2017 6:37 pm
Contact:

Re: help with set-variable for image buttons - I think

#7 Post by Kaldonis »

thanks for the reply. Yeah Renpy gave me that error straight away so its fixed but still doesn't work. the only time it works if there is no other If statement. So I have no idea what i'm to do. :/

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: help with set-variable for image buttons - I think

#8 Post by Remix »

So, what is your code at the moment?
Frameworks & Scriptlets:

Kaldonis
Newbie
Posts: 15
Joined: Tue Dec 12, 2017 6:37 pm
Contact:

Re: help with set-variable for image buttons - I think

#9 Post by Kaldonis »

OMG I am so sorry, I never got an email saying I got a notification.
I'll get it posted shortly

Kaldonis
Newbie
Posts: 15
Joined: Tue Dec 12, 2017 6:37 pm
Contact:

Re: help with set-variable for image buttons - I think

#10 Post by Kaldonis »

The code is pretty much the same as when I last posted, but with what I have at the moment the button highlights and you can click it but it does nothing now. So at least it doesn't just return to the main menu.
I've included what code I think is relevant to this topic.

Code: Select all

default location = "none"

Code: Select all

imagebutton auto "buttons/switch_%s.png" xpos 0 ypos 0 focus_mask True action Jump("location_talk")

Code: Select all

screen mcbedroom_room:
    $ location = "mcbedroom"
    imagemap:
        ground 'bg/mc_bedroom.png'
        idle 'bg/mc_bedroom.png'

Code: Select all

label location_talk:
    if location == "mcbedroom":
        s"this is my room"
    jump mc_bedroom
    if location == "park":
        "this is a nice park"
    if location == "beach":
        "Time to work on my tan"
I have each part of the code in different .rpy file rather than all in my script file, I'm not sure if that makes a difference. Just thought since i'm going to have lots of different areas with stuff happening it would be easier if they were in a separate file.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: help with set-variable for image buttons - I think

#11 Post by Remix »

Separate files is perfectly fine, Ren'py basically pre-compiles them into one big map of lines anyway when it starts. (btw: It is even advised that numerous small files is slightly faster than one big file for script parts)

Nothing looks hugely wrong (though the `jump mc_bedroom` bit in label location_talk could do with being indented one more line).

If the problem is the imagebutton action, we really need to see where that is shown and how the screen that contains it is called (hopefully shown rather than called tbh)
Frameworks & Scriptlets:

Kaldonis
Newbie
Posts: 15
Joined: Tue Dec 12, 2017 6:37 pm
Contact:

Re: help with set-variable for image buttons - I think

#12 Post by Kaldonis »

Thanks once again for the help. Good to know splitting up the game into smaller files was of benefit.
I've indented the lines on the location talk one more time as well thanks. At least the button with the current script just doesn't work, it used to send the game straight back to the main menu.

Code: Select all

default mc_bedroom_visit = False
I have the code above set in a separate file along with all the other locations in the game. The intention is that each room/scene gets a little intro from the character but any visit afterwards will just have the screen with clickable objects/image buttons or an imagemap(trying to use these less as I've read Imagebuttons are the way forward)

Code: Select all

label mc_bedroom:
    if mc_bedroom_visit == False:
        scene mc_bedroom
	(dialogue for 8 lines)
        $ mc_bedroom_visit = True
    call screen mcbedroom_room
This is in my main script file and I'm afriad i did use call screen. I quickly put show screen in place of the call but then the game just returns to the main menu.

The code for the buttons is below and I have this in another separate file. I've included the inventory screen here too as that works. (nothing beyond the menu vbox yet)

Code: Select all

screen guioverlay:
    zorder 99
    add "buttons/buttonbackground.png"
    imagebutton auto "buttons/talk_%s.png" xpos 0 ypos 0 focus_mask True action Jump("location_talk")
    imagebutton auto "buttons/map_%s.png" xpos 128 ypos 120 focus_mask True action Null
    imagebutton auto "buttons/pda_%s.png" xpos 158 ypos -9 focus_mask True action Show("inventory")
    imagebutton auto "buttons/empty_%s.png" xpos -8 ypos 160 focus_mask True action Null

screen inventory:
    modal True
    frame:
        xalign 0.5 yalign 0.5
        vbox:
            label "Inventory"
            text "Items Here"
            label "Stats"
            text "Stats here"
            textbutton "Close" action Hide("inventory")
And I added these extra gui buttons to the screens.rpy file so they show up on every screen unless I hide them (which i've yet to implement but bookmarked some topics on the forums once I have buttons working correctly)

Code: Select all

init python:
    config.overlay_screens.append("quick_menu")
    config.overlay_screens.append("guioverlay")
If there is anything else you need to see please let me know. Once again your help, advice and time is much appreciated.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: help with set-variable for image buttons - I think

#13 Post by Remix »

Could you put together a minimal script.rpy that shows the problem and post all of that?

The problem (if it is going to main menu) could well be that the Return of the called screen is returning to a script point that has no more story, effectively hitting a final return and hence game end. I feel further suggestions without seeing a more complete script will be guesswork and likely just make other glitches.
Frameworks & Scriptlets:

Kaldonis
Newbie
Posts: 15
Joined: Tue Dec 12, 2017 6:37 pm
Contact:

Re: help with set-variable for image buttons - I think

#14 Post by Kaldonis »

Code: Select all

#### this is all in the script.rpy####
define s = Character ('Susan', image='susan', color="#ca0404")
define su = Character ('????', image='susan', color="#ca0404")
define I = Character('[name]', color="#c8c8ff")
define narrator = Character(None, what_italic=True)

init-1:
    $ config.font_replacement_map["DejaVuSans.ttf", False, True] = ("DejaVuSans-Oblique.ttf", False, False)
    
default mc_bedroom_visit = False
default burger_visit = False
default park_visit = False
    
default location = "none"

# The game starts here.

label splashscreen:
    scene black
    with Pause (1)
    
    show bg loading with dissolve
    with Pause (2)
    hide bg loading with dissolve
    with Pause (1)
    show bg logo with dissolve
    with Pause (2)
    hide bg logo with dissolve 
    with Pause (1)

    return

label start:
    $ renpy.transition(dissolve)
    scene black
    $name = renpy.input("What is your name?")
    $name = name.strip()
    if name=="":
         $name="Issac"
         
    scene bg mc bedblur with dissolve
    $ renpy.pause(0.5, hard=True)
    show cg_mc_mirror at top with dissolve

        
    "blah blah" 
    "blah blah"
    su "blah blah""
    
    hide cg_mc_mirror with fade
    
label mc_bedroom:
    if mc_bedroom_visit == False:
        scene mc_bedroom
        show switch with dissolve
        s "blah blah"
        I"blah blah"
        "blah blah"
        "blah blah"
        "blah blah"
        s"blah blah"
        "blah blah"
        I"blah blah"
        s"blah blah"
        I"blah blah"
        s"blah blah"
        hide s with dissolve
        $ mc_bedroom_visit = True
    call screen mcbedroom_room
    
    return (game ends here)

### this is in a separate mcbedroom_screen.rpy file###
screen mcbedroom_room:
    $ location = "mcbedroom"
    imagemap:
        ground 'bg/mc_bedroom.png'
        idle 'bg/mc_bedroom.png'
       
        alpha False

        hotspot(1283,148,82,143) action Jump("bear_fighter")
        hotspot(27,456,254,123) action Jump("computer")
        hotspot(724,462,63,69) action Jump("door")
        hotspot(142,8,207,343) action Jump("big_poster")
        hotspot(508,334,104,237) action Jump("calender")
        hotspot(1028,957,197,100) action Jump("magazines")
        hotspot(369,289,66,101) action Jump("man_picture")
        hotspot(1083,251,139,70) action Jump("books")

label bear_fighter:
    "description"
    jump mc_bedroom
    
label big_poster:
    "description."
    jump mc_bedroom
    
label man_picture:
    "description"
    jump mc_bedroom
    
label books:   
    "description."
    jump mc_bedroom
    
label magazines:    
    "description."
    jump mc_bedroom
        
label computer:
    "description"
    jump mc_bedroom
    
label calender:
    "description"
    jump mc_bedroom
    
label door:
    "description"
    jump mc_bedroom

### this is in a separate custom_screen.rpy file###
screen guioverlay:
    zorder 99
    add "buttons/buttonbackground.png"
    imagebutton auto "buttons/talk_%s.png" xpos 0 ypos 0 focus_mask True action Jump("location_talk")
    imagebutton auto "buttons/map_%s.png" xpos 128 ypos 120 focus_mask True action Null
    imagebutton auto "buttons/pda_%s.png" xpos 158 ypos -9 focus_mask True action Show("inventory")
    imagebutton auto "buttons/empty_%s.png" xpos -8 ypos 160 focus_mask True action Null

screen inventory:
    modal True
    frame:
        xalign 0.5 yalign 0.5
        vbox:
            label "Inventory"
            text "Items Here"
            label "Stats"
            text "Stats here"
            textbutton "Close" action Hide("inventory")

### this is in a separate location_talk.rpy file###
label location_talk:
        if location == "mcbedroom":
            s"this is my room"
        jump mc_bedroom
        if location == "park":
            "this is a nice park"
        if location == "beach":
            "Time to work on my tan"

### this has been added to the screens.rpy file under the quickmenu heading###
init python:
    config.overlay_screens.append("quick_menu")
    config.overlay_screens.append("guioverlay")
I hope this is what you meant as its pretty much all I have at the moment, because I hit this stumbling block early on, I've been working on visuals for the time being. What I find so strange is that the buttons with Null in them end the game too. I thought Null would make the button work visually but not do anything if clicked.
If this can't be solved I think my only choice is to put the guioverlay manually on all scenes and change what the talk button does each time.

Your time and help as always is much appreciated.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: help with set-variable for image buttons - I think

#15 Post by Remix »

I meant Just indent the jump mc_bedroom line, not the lot

Code: Select all

### this is in a separate location_talk.rpy file###
label location_talk:
    if location == "mcbedroom":
        s"this is my room"
        jump mc_bedroom # indented so it Only jumps if location is correct
    if location == "park":
        "this is a nice park"
    if location == "beach":
        "Time to work on my tan"
Let us know if any other glitches are happening once that is fixed. Might look more tomorrow...
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: Andredron