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

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
henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

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

#1 Post 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
Last edited by henvu50 on Fri Aug 27, 2021 1:30 pm, edited 2 times in total.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

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

#2 Post 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

User avatar
midgethetree
Regular
Posts: 39
Joined: Wed Dec 30, 2020 3:51 pm
Completed: Back When, The Mother of Pearls, various jam games
Projects: When Everyone's Watching, Deliberation
Github: midgethetree
itch: midge-the-tree
Discord: rainafc#3353
Contact:

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

#3 Post 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.


Post Reply

Who is online

Users browsing this forum: Google [Bot]