Page 1 of 2

Android Screen Problem [solved]

Posted: Tue Dec 15, 2015 3:40 pm
by Lightworker
So... I borrowed code from akakyouryuu http://lemmasoft.renai.us/forums/viewto ... 51&t=26257

Code: Select all

##############################################################################
# These screens are for "phone".
# These work in ren'py 6.17 or later.
# This file is in the public domain.

# 2014/04/21
##############################################################################
# Main Menu
#
# Screen that's used to display the main menu, when Ren'Py first starts
# http://www.renpy.org/doc/html/screen_special.html#main-menu

screen main_menu:

    # This ensures that any other menu screen is replaced.
    tag menu
    variant "phone"

    # The background of the main menu.
    window:
        style "mm_root"

    # The main menu buttons.
    frame:
        style_group "mm"
        xalign .98
        yalign .98

        has hbox

        textbutton _("Start Game") action Start()
        textbutton _("Load Game") action ShowMenu("load")
        textbutton _("Preferences") action ShowMenu("preferences")
        textbutton _("Help") action Help()
        textbutton _("Quit") action Quit(confirm=False)

init -2:
    style mm_button:
        variant "phone"
        yminimum 100

##############################################################################
# Navigation
#
screen navigation:
   
    tag menu
    variant "phone"

    # The background of the game menu.
    window:
        style "gm_root"

    # The various buttons.
    frame:
        style_group "gm_nav"
        xalign .5
        yalign .5
        xminimum .9
        yminimum .9

        has vbox

        hbox:
            textbutton _("Save") action ShowMenu('save')
            textbutton _("Load Game") action ShowMenu("load")
            textbutton _("Q.Save") action QuickSave()
            textbutton _("Q.Load") action QuickLoad()
        hbox:
            textbutton _("Auto") action [Preference("auto-forward", "toggle"), Return()]
            textbutton _("Skip") action Skip()
            textbutton _("F.Skip") action Skip(fast=True, confirm=True)
        hbox:
            textbutton _("Preferences") action ShowMenu("preferences")
            textbutton _("Main Menu") action MainMenu()
            textbutton _("Help") action Help()
            textbutton _("Quit") action Quit()

init -1:

    style gm_nav_vbox:
        variant "phone"
        spacing 60
    style gm_nav_hbox:
        variant "phone"
        spacing 10
        xalign .5
    style gm_nav_button:
        variant "phone"
        xminimum int(( config.screen_width / 4 ) - 20)
        yminimum int(( config.screen_height / 3 ) - 60)
    style gm_nav_button_text:
        variant "phone"
        size 25
    # If "phone", a "menu" button opens the "navigation" screen.
    if renpy.variant("phone"):
        $ _game_menu_screen = "navigation"

##############################################################################
# Save, Load
#
# Screens that allow the user to save and load the game.
# http://www.renpy.org/doc/html/screen_special.html#save
# http://www.renpy.org/doc/html/screen_special.html#load

# Since saving and loading are so similar, we combine them into
# a single screen, file_picker. We then use the file_picker screen
# from simple load and save screens.

screen file_picker:

    variant "phone"
    key "game_menu" action Return()

    # The background of the game menu.
    window:
        style "gm_root"

    frame:
        style "file_picker_frame"

        has vbox

        # The buttons at the top allow the user to pick a
        # page of files.
        hbox:
            style_group "file_picker_nav1"
            xfill True
            xalign .5

            textbutton _("Previous"):
                action FilePagePrevious()

            textbutton _("Auto"):
                action FilePage("auto")

            textbutton _("Quick"):
                action FilePage("quick")

            textbutton _("Next"):
                action FilePageNext()
           
        hbox:
            style_group "file_picker_nav2"
            xfill True
            xalign .5

            for i in range(1, 9):
                textbutton str(i):
                    action FilePage(i)

        $ columns = 2
        $ rows = 5

        # Display a grid of file slots.
        grid columns rows:
            transpose True
            xfill True
            yfill True
            style_group "file_picker"

            # Display ten file slots, numbered 1 - 10.
            for i in range(1, columns * rows + 1):

                # Each file slot is a button.
                button:
                    action FileAction(i)
                    xfill True
                    yfill True

                    has hbox

                    # Add the screenshot.
                    add FileScreenshot(i)

                    $ file_name = FileSlotName(i, columns * rows)
                    $ file_time = FileTime(i, empty=_("Empty Slot."))
                    $ save_name = FileSaveName(i)

                    text "[file_name]. [file_time!t]\n[save_name!t]"

                    key "save_delete" action FileDelete(i)

screen save:

    # This ensures that any other menu screen is replaced.
    tag menu
    variant "phone"

    use file_picker

screen load:

    # This ensures that any other menu screen is replaced.
    tag menu
    variant "phone"

    use file_picker

init -1:
    style file_picker_nav1_button:
        variant "phone"
        xsize int(( config.screen_width / 4 ) - 5)
    style file_picker_nav2_button:
        variant "phone"
        xsize int(config.screen_width / 8 - 5)

##############################################################################
# Preferences
#
# Screen that allows the user to change the preferences.
# http://www.renpy.org/doc/html/screen_special.html#prefereces

screen preference_page:

    variant "phone"
    key "game_menu" action Return()

    # The background of the game menu.
    window:
        style "gm_root"
    frame:
        style_group "pref_page"

        vbox:
            textbutton _("Display") action ShowMenu("preferences")
            textbutton _("Skip") action ShowMenu("preference2")
            textbutton _("Sound") action ShowMenu("preference3")

screen preferences:

    variant "phone"
    tag menu
    use preference_page

    vbox:
        style_group "prefs"
        xfill True

        frame:
            style_group "pref"
            has vbox

            label _("Transitions")
            textbutton _("All") action Preference("transitions", "all")
            textbutton _("None") action Preference("transitions", "none")

        frame:
            style_group "pref"
            has vbox

            label _("Text Speed")
            bar value Preference("text speed")

        frame:
            style_group "pref"
            has vbox

            label _("Auto-Forward Time")
            bar value Preference("auto-forward time")

            if config.has_voice:
                textbutton _("Wait for Voice") action Preference("wait for voice", "toggle")

screen preference2:

    tag menu
    variant "phone"

    use preference_page

    vbox:
        style_group "prefs"
        xfill True

        frame:
            style_group "pref"
            has vbox

            label _("Skip")
            textbutton _("Seen Messages") action Preference("skip", "seen")
            textbutton _("All Messages") action Preference("skip", "all")

        frame:
            style_group "pref"
            has vbox

            label _("After Choices")
            textbutton _("Stop Skipping") action Preference("after choices", "stop")
            textbutton _("Keep Skipping") action Preference("after choices", "skip")

screen preference3:

    tag menu
    variant "phone"

    use preference_page

    vbox:
        style_group "prefs"
        xfill True

        frame:
            style_group "pref"
            has vbox

            label _("Music Volume")
            bar value Preference("music volume")

        frame:
            style_group "pref"
            has vbox

            label _("Sound Volume")
            bar value Preference("sound volume")

            if config.sample_sound:
                textbutton _("Test"):
                    action Play("sound", config.sample_sound)
                    style "soundtest_button"

        if config.has_voice:
            frame:
                style_group "pref"
                has vbox

                label _("Voice Volume")
                bar value Preference("voice volume")

                textbutton _("Voice Sustain") action Preference("voice sustain", "toggle")
                if config.sample_voice:
                    textbutton _("Test"):
                        action Play("voice", config.sample_voice)
                        style "soundtest_button"

        # Can a phone have a joystick?
        # frame:
        #     style_group "pref"
        #     has vbox
        #
        #     textbutton _("Joystick...") action Preference("joystick")

init -1:
    style pref_button_text:
        variant "phone"
        size 30
    style pref_button:
        variant "phone"
        xminimum 300
        yminimum 100
    style pref_label_text:
        variant "phone"
        size 30
    style pref_frame:
        variant "phone"
        xsize int(config.screen_width - 350)
    style pref_page_frame:
        variant "phone"
        xalign .98
        yalign .98
        xmaximum 340
    style pref_page_button:
        variant "phone"
        xminimum 300
        yminimum 100
    style pref_slider:
        variant "phone"
        xsize 350
    style pref_page_button_text:
        variant "phone"
        size 30
##############################################################################
# Yes/No Prompt
#
# Screen that asks the user a yes or no question.
# http://www.renpy.org/doc/html/screen_special.html#yesno-prompt

screen yesno_prompt:

    modal True
    variant "phone"

    # The background of the game menu.
    window:
        style "gm_root"

    frame:
        style_group "yesno"

        xfill True
        xmargin .05
        ypos .1
        xalign .5
        yanchor 0
        ypadding .05
        xsize .99
        ysize .8

        label _(message):
            xalign 0.1
            yalign 0.1

        vbox:
            xalign 0.98
            yalign 0.98

            textbutton _("Yes") action yes_action
            textbutton _("No") action no_action

    # Right-click and escape answer "no".
    key "game_menu" action no_action

init -1:
    style yesno_label_text:
        variant "phone"
        size 30
    style yesno_button:
        variant "phone"
        xminimum 300
        yminimum 100
    style yesno_button_text:
        variant "phone"
        size 30

##############################################################################
# Quick Menu
#
# Quick Menu doesn't used in the screens for Phone.
screen quick_menu:
    variant "phone"
    fixed:
        null

init -1:
    style menu_choice_button:
        variant "phone"
        yminimum 100
However, the problem is that once I launch the project I get this error.

Code: Select all

I'm sorry, but an uncaught exception occurred.

After initialization, but before game start.
  File "game/screens.rpy", line 265, in prepare_screen
    screen preference2:
  File "game/screens.rpy", line 265, in prepare
    screen preference2:
Exception: A screen named preference_page does not exist.
Could anyone help me?

Re: Android Screen Problem

Posted: Tue Dec 15, 2015 7:52 pm
by Zetsubou
Do you have a "preference_page" screen that isn't a "phone" variant?
Other screens like "yesno_prompt" are in your screens.rpy file by default, but there is no "preference_page" (there should be "preferences" though).
So I'm guessing you need a "preference_page" screen for non-phone devices. This could be as simple as renaming the "preferences" screen (and any references to it) to "preference_page", or vice-versa.

Re: Android Screen Problem

Posted: Tue Dec 15, 2015 10:55 pm
by Lightworker
How do I rename the "preferences" screen to "preference_page"? Is the file in my library?

Re: Android Screen Problem

Posted: Tue Dec 15, 2015 11:04 pm
by Zetsubou
Ah... forget about that. On closer inspection, that isn't what you want.
I think you need a "preference_page" screen that doesn't have "touch" as the variant.

eg. In that file, try adding:

Code: Select all

screen preference_page:
    key "game_menu" action Return()

    # The background of the game menu.
    window:
        style "gm_root"

Re: Android Screen Problem

Posted: Wed Dec 16, 2015 4:08 pm
by Lightworker
I added your code and got this error.

Code: Select all

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


File "game/screens.rpy", line 215: screen expects a non-empty block.
    screen preference_page:
                           ^

Ren'Py Version: Ren'Py 6.99.6.739
What does this mean? Did I put the code in the wrong place?

Re: Android Screen Problem

Posted: Wed Dec 16, 2015 4:13 pm
by Zetsubou
"screen expects a non-empty block" means you either didn't put any content in the screen, or your indentation is wrong.
eg. If you have

Code: Select all

    screen preference_page:
    key "game_menu" action Return()

    window:
        style "gm_root"
or

Code: Select all

screen preference_page:
key "game_menu" action Return()

window:
    style "gm_root"
then it isn't going to work.

Re: Android Screen Problem

Posted: Wed Dec 16, 2015 6:16 pm
by Lightworker
Oh I see, I have it done in the first one. How do I fix it?

Re: Android Screen Problem

Posted: Wed Dec 16, 2015 6:20 pm
by Zetsubou
Unindent the "screen" line, so it matches [url=http://lemmasoft.renai.us/forums/viewto ... 02#p396209]my first example.
It should match the other screen blocks in your file.

Re: Android Screen Problem

Posted: Wed Dec 16, 2015 8:22 pm
by Lightworker
Something does not make sense. The game is launches as though I never changed anything. I added your code to screens.rpy however, it does not look like https://www.youtube.com/watch?v=RxtCK3pO6vQI have no idea what's going on with this code.

Re: Android Screen Problem

Posted: Wed Dec 16, 2015 8:30 pm
by Zetsubou
The "preference_page" I posted was to stop the crash you were getting.

Does your game still crash?
If not, what is the problem with your game currently?

Re: Android Screen Problem

Posted: Thu Dec 17, 2015 12:16 am
by Donmai
Ah, I see. The game runs, but not with the big buttons and sub-menus. And it throwed me another error when I clicked on the Start button.

Re: Android Screen Problem

Posted: Thu Dec 17, 2015 12:45 am
by Lightworker
The problem is that nothing changed; I am back at square one. Originally it just keep crashing because in the original code, there was no preference_page without a phone variant. When I fixed that, the game appears the same way as though I did not use akakyouryuu's code at all. I grabbed his screenshots to illustrate exactly what I am trying to accomplish.

Re: Android Screen Problem

Posted: Thu Dec 17, 2015 10:20 pm
by philat
You are misunderstanding what the code you implemented actually does. It's not meant to be run on the PC. It's meant to be run on Android. The variant "phone" means that those screens are ONLY USED if you are running the game on Android. You can certainly emulate an Android environment using RAPT, but if you're just launching the game, then of course it's not going to work.

Re: Android Screen Problem

Posted: Thu Dec 17, 2015 10:55 pm
by Lightworker
Holy crap. That makes so much sense now. Ohhh.... What exactly is RAPT and how do I emulate an andriod environment?

Re: Android Screen Problem

Posted: Fri Dec 18, 2015 12:26 am
by Zetsubou
Lightworker wrote:What exactly is RAPT and how do I emulate an andriod environment?
http://www.renpy.org/doc/html/android.html
RAPT = Ren'Py Android Packaging Tool

In the Renpy Launcher, click on "Android".
Before you can start building games for and launching on Android, Renpy will ask if you want to download RAPT.

In the Android section, up the top left is the text "Emulation", with Phone, Tablet and Television listed.
Click on one of those and you'll receive information/prompts about emulating Android.