1. Hey! Guest! The XXX GMC Jam will take place between August 24th, 12:00 UTC (Friday noon) and August 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Question - Code Check for the existence of a physics world?

Discussion in 'GameMaker Studio 2 Community Tech Support' started by Sinaz20, Aug 9, 2018.

  1. Sinaz20

    Sinaz20 Member GMC Elder

    Joined:
    Aug 22, 2016
    Posts:
    131
    We can set the physics flag in the room. And we can use physics_world_create() to create a physics system in a room...

    But it doesn't seem like we can check to see if a physics system currently exists.

    I'd like to roll out an all-in-one pause solution, but calling physics_pause_enable() agnostically in a room that doesn't have a physics system throws an error.

    How can I make a call to pause a physics system conditional on there actually being a physics system?
     
  2. AlanDavison

    AlanDavison Member

    Joined:
    Aug 9, 2018
    Posts:
    1
    I thought I would have a quick look, but it doesn't even look like any of the physics functions return a value at all. I was hoping that one of the physics functions would return a true or a false based on whether a physics system exists or not, but it doesn't look like it does.

    Looks like we just have to wait for the ability to catch exceptions so something doing something so simple doesn't force the game to crash.
     
    Sinaz20 likes this.
  3. chance

    chance predictably random Forum Staff Moderator

    Joined:
    Apr 22, 2016
    Posts:
    678
    I always enable the physics world with a dedicated "physics controller" object, rather than using IDE check boxes. So if an instance of that object exists in a room, that room has a physics system by definition.

    So you can check with the instance_exists() function, before calling physics_pause_enable().

    (Or use the with() construct for the controller instance, if it exists in the room.)
     
    Sinaz20, Toque and MarceloP like this.
  4. Sinaz20

    Sinaz20 Member GMC Elder

    Joined:
    Aug 22, 2016
    Posts:
    131
    @chance Thanks- that's a great solution and actually more in line with how I am developing other aspects of my project.
     
    MarceloP likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice