Page 1 of 1

image buttons

Posted: Thu Dec 27, 2018 10:49 am
by VorrAkkagi
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 =/

Re: image buttons

Posted: Thu Dec 27, 2018 1:51 pm
by Per K Grok
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.

Re: image buttons

Posted: Thu Dec 27, 2018 2:05 pm
by trooper6
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

Re: image buttons

Posted: Thu Dec 27, 2018 2:13 pm
by VorrAkkagi
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!

Re: image buttons

Posted: Thu Dec 27, 2018 2:21 pm
by VorrAkkagi
Ahh Trooper 6, that one works! Thanks a bunch!!!

Re: image buttons

Posted: Thu Dec 27, 2018 2:38 pm
by VorrAkkagi
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

Re: image buttons

Posted: Thu Dec 27, 2018 2:59 pm
by Imperf3kt
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

Re: image buttons

Posted: Thu Dec 27, 2018 3:03 pm
by VorrAkkagi
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.?

Re: image buttons

Posted: Thu Dec 27, 2018 3:05 pm
by Imperf3kt
Yeah, sorry I reread your post and saw that after I posted.
I've adjusted my post. It should help I hope.

Re: image buttons

Posted: Thu Dec 27, 2018 3:20 pm
by VorrAkkagi
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! =)