image buttons

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
VorrAkkagi
Newbie
Posts: 21
Joined: Tue Dec 11, 2018 5:41 am
Contact:

image buttons

#1 Post by VorrAkkagi » Thu Dec 27, 2018 10:49 am

Ok, going bonkers on this really simple thing..

I want to put a couple of image buttons up on the top right corner of my screen. One is to call up another window in which I want to list the Character's attribute and skill levels - which will update as the character gains or loses in those skills. The second button is more to pull up a map for the player to 'fast travel' to places.

So I've been reading up on hbox and vbox, etc. watching tutorials on this. But where to you put this code in the script file? Before game start, after?

And also, I've seen in these tutorials that in come cases, people make a seperate script to handle things such as this. That I can do, but how do you call this second script from the main script?

Thanks in advance for your expert advice! Still working the 'noob' kinks out =P

PS - There is that downloadable tutorial posted here which I tried. It came up with an error so I was never able to run it and see how it explains things =/

User avatar
Per K Grok
Miko-Class Veteran
Posts: 611
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1
Projects: Defenders of Adacan Part 2
Deviantart: pekj
itch: per-k-grok
Location: Sverige
Contact:

Re: image buttons

#2 Post by Per K Grok » Thu Dec 27, 2018 1:51 pm

VorrAkkagi wrote:
Thu Dec 27, 2018 10:49 am
Ok, going bonkers on this really simple thing..

I want to put a couple of image buttons up on the top right corner of my screen. One is to call up another window in which I want to list the Character's attribute and skill levels - which will update as the character gains or loses in those skills. The second button is more to pull up a map for the player to 'fast travel' to places.

So I've been reading up on hbox and vbox, etc. watching tutorials on this. But where to you put this code in the script file? Before game start, after?

And also, I've seen in these tutorials that in come cases, people make a seperate script to handle things such as this. That I can do, but how do you call this second script from the main script?

Thanks in advance for your expert advice! Still working the 'noob' kinks out =P

PS - There is that downloadable tutorial posted here which I tried. It came up with an error so I was never able to run it and see how it explains things =/

You can really put your code for your screens in any rpy-file in the game-folder. When you call for a screen in a script "show screen something" the engine will find the code for the screen based only on the name of the screen, even if that code is inside a different rpy-file. You don't have to tell the first script file the name of the second script file.

If you want a separate file to hold the screens and call that file "myscreens.rpy" and place that together with the other rpy-files You can call those screens from other script files using only the name of the screen.

The same thing goes for labels.
Image Visual Story Telling, DeviantArt Group for animations, comics, games and illustrations https://www.deviantart.com/acgi

User avatar
trooper6
Lemma-Class Veteran
Posts: 3645
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: image buttons

#3 Post by trooper6 » Thu Dec 27, 2018 2:05 pm

VorrAkkagi wrote:
Thu Dec 27, 2018 10:49 am
PS - There is that downloadable tutorial posted here which I tried. It came up with an error so I was never able to run it and see how it explains things =/
Did you download the updated version of the tutorial that is linked in the comments thread: viewtopic.php?p=455107#p455107
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

VorrAkkagi
Newbie
Posts: 21
Joined: Tue Dec 11, 2018 5:41 am
Contact:

Re: image buttons

#4 Post by VorrAkkagi » Thu Dec 27, 2018 2:13 pm

Ahh thank you Per K Grok! Clears that up a bunch!

Progress report: (I can keep the screen code separate to keep the script cleaner = very good!)

I've managed to get text buttons lined up where I want them to be on my main screen, but am now trying to convert them to image buttons. But I keep getting errors...

Code: Select all

screen custom_screen:
    hbox:
        xalign .975
        yalign 0.01
        spacing 5
        textbutton "Map"
        imagebutton auto "stats_hover.png, stats_idle.png" action ShowMenu NULL #('statBak2')   <<<<---- my current headache comes from this line
        textbutton "Inv"

label start:
    show screen custom_screen
So above, taking it one step at a time - I want that image button (this button is the 'Stats' button) to call up another 'image' perhaps 'image map'? That will show in a box on the (right side of the screen) a list of the character's skills and stats. I probably need to make a 2 column wide grid to have the name on the left and the value on the right, with the value updatable as the game progresses. I tried putting the image map on %auto but it kept not seeing the button.pngs I created... And I have found no documentation that lists what has to be hand typed if not using 'auto'. And I created a bg graphic for this 'information screen'.

Your further coding wisdom is much appreciated!

VorrAkkagi
Newbie
Posts: 21
Joined: Tue Dec 11, 2018 5:41 am
Contact:

Re: image buttons

#5 Post by VorrAkkagi » Thu Dec 27, 2018 2:21 pm

Ahh Trooper 6, that one works! Thanks a bunch!!!

VorrAkkagi
Newbie
Posts: 21
Joined: Tue Dec 11, 2018 5:41 am
Contact:

Re: image buttons

#6 Post by VorrAkkagi » Thu Dec 27, 2018 2:38 pm

Ok, pulling my hair out now....

the imagebutton code... I've copied it straight out of the tutorial with the exception of naming my own graphics ( the auto '%s.png didn't work either) and just get errors, errors errors
(if you hear distant screaming...it's just me... =P )

Code: Select all

screen custom_screen:
    hbox:
        xalign .975
        yalign 0.01
        spacing 5
        textbutton "Map"
        imagebutton auto "gui/stats_idle.png, stats_hover.png" action Null    # <<<<<----- that line right there!!!!
        textbutton "Inv"

label start:
    show screen custom_screen

"Do we have lift-off?"

return

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 2806
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: image buttons

#7 Post by Imperf3kt » Thu Dec 27, 2018 2:59 pm

If you use imagebuttons, you need at least two files.

If you are using auto then you also need to name the files appropriately.
MyPicture_idle.png and MyPicture_hover.png
You don't have to use png files, they can be .jpg or any other format Ren'Py supports, the important part is that they include idle and hover - the %s is replaced with the appropriate suffix by renpy.

In your case, you've supplied the images not quite the right way.

Try one of the following

Code: Select all

imagebutton auto "gui/stats_%s.png" action Null

Code: Select all

imagebutton idle "gui/stats_idle.png" hover "gui/stats_hover.png" action Null
Last edited by Imperf3kt on Thu Dec 27, 2018 3:04 pm, edited 1 time in total.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Twitter

VorrAkkagi
Newbie
Posts: 21
Joined: Tue Dec 11, 2018 5:41 am
Contact:

Re: image buttons

#8 Post by VorrAkkagi » Thu Dec 27, 2018 3:03 pm

I have both of those files. The one thing I AM good at is graphic arts, because that's what I did for a living 'once upon a time'. =P I made both and put them into the game/gui folder. stats_idle.png and stats_hover.png. Do I need to define these in any way - declare size, etc.?

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 2806
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: image buttons

#9 Post by Imperf3kt » Thu Dec 27, 2018 3:05 pm

Yeah, sorry I reread your post and saw that after I posted.
I've adjusted my post. It should help I hope.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Twitter

VorrAkkagi
Newbie
Posts: 21
Joined: Tue Dec 11, 2018 5:41 am
Contact:

Re: image buttons

#10 Post by VorrAkkagi » Thu Dec 27, 2018 3:20 pm

Thank you sir! and....

Picture me banging my head on my desk a few hundred times.....

My graphics were in the wrong project folder!!! When I loaded the imagebutton tutorial project that didn't work a week or two back, it screwed up my folders somehow. I reloaded ren'py into a different folder, but still get a duplicate of my main project (listed twice, etc.)... SOOOO, now I'll have to pay more attention to which folder I'm dumping graphics =P idiotidiotidiotidiot....

Thanks for your help all! Next is to tackle making these image buttons do something! =)

Post Reply

Who is online

Users browsing this forum: No registered users