Page 1 of 1

[Solved] Can I use renpy.variant('small') instead of renpy.variant('mobile'), touch, pc, web?

Posted: Thu Aug 26, 2021 12:15 pm
by henvu50
Edit: solutions in comments below.

For the sake of keeping things simple.

Instead of doing this:

Code: Select all

if renpy.variant('mobile') or renpy.variant('touch'):
#or
if renpy.variant('pc') or renpy.variant('web'):
[code]

Can I get away with using this instead in 99% of cases? If this returns true, I know it has to be either mobile or touch. If it' false, I know it's gotta be pc or web.
[code]
if renpy.variant('small'):  #if true mobile/touch, if false pc/web

Re: Can I use renpy.variant('small') instead of renpy.variant('mobile'), touch, pc, web?

Posted: Thu Aug 26, 2021 2:53 pm
by hell_oh_world
Have you tried using creating a helper function?

Code: Select all

init python:
  def is_mobile():
    mobile = ("mobile", "touch")
    for m in mobile:
      if renpy.variant(m): return True
    return False

Re: Can I use renpy.variant('small') instead of renpy.variant('mobile'), touch, pc, web?

Posted: Thu Aug 26, 2021 4:13 pm
by midgethetree

Code: Select all

renpy.variant('mobile') or renpy.variant('touch')
will return true for tablets but not TV consoles (and also the mobile check in that is redundant and should be removed, since I don't know of any mobile phone that isn't also a touchscreen device).

Code: Select all

renpy.variant('small')
will return true for TV consoles (since screen elements need to be enlarged for visibility from further away) but not tablets (which are viewed as medium-sized screens).

Chances are you aren't targeting TV consoles, but if you're targeting mobile putting some thought into whether you really mean small screens or touch screens can improve the experience of anyone who installs your game on a tablet and is a good habit.

Code: Select all

renpy.variant('pc') or renpy.variant('web')
returns true on mobile browsers, so if what you really mean is not a mobile phone you should be using not small or not touch depending on which is more relevant.

A lot of the time you want to check for small (since a lot needs to change to accommodate smaller screens), but there might be cases where you want to, say, increase button borders on touch screens (which should affect tablets but is unnecessary for TVs) so you check for touch, or where you want to add buttons like "quit" that only make sense on PC so you check for pc.

A check like

Code: Select all

renpy.variant("pc") or (renpy.variant("web") and not renpy.variant("mobile"))
might also occasionally be helpful to guess if the player can use a keyboard/mouse setup, as happens in the default UI in deciding whether to show the default help screen (which assumes keyboard/mouse are available to the player and doesn't make sense on platforms where that's not generally true). This is likely only rarely useful though, most of the time you shouldn't need and/or statements.

https://www.renpy.org/doc/html/screens. ... n-variants explains all the variants so you can better understand which applies when.

Re: Can I use renpy.variant('small') instead of renpy.variant('mobile'), touch, pc, web?

Posted: Fri Aug 27, 2021 1:29 pm
by henvu50
Thanks.