Problem with variables and force of gravity (a crash)

This forum is currently in read-only mode.
  • First of all, I have a variable called g and 2 istances of the same sprite.

    When a player collides with an instance, it is deleted and if g=0 then g=1 and if g=1 then g=0.

    But construct reads events top-down, so g stays at 0.

    I tried using the tricks (1-Global('g')) but that didn't work because I found a crash :

    make 2 events like this :

    When g = 0 set force of gravity to 20

    When g = 1 set force of gravity to -20

    Try to run the layout, it crashes Construct...

    Is there any work-around this bug? I need it badly for my game.

  • Can you upload the .cap that crashes to the tracker? That way we can fix the crash instead of trying to avoid it...

  • The crash might be a bug that needs fixing, but your (1-Global('g') is wrong.

    +Player collides with sprite
       -Set g to (0 minus g)
       -Set force of gravity to g
    [/code:1c9dxf6b]
    
    This will toggle back and forth between 20 and -20.
  • The crash might be a bug that needs fixing, but your (1-Global('g') is wrong.

    > +Player collides with sprite
       -Set g to (0 minus g)
       -Set force of gravity to g
    [/code:2douikgz]
    
    This will toggle back and forth between 20 and -20.
    

    sorry, won't this toggle between 0 and -1? Also I can't post the cap right now, because im not at the main pc

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • sorry, won't this toggle between 0 and -1?

    Nope. And sorry, I forgot to say "make the initial value for g either 20 or -20."

    So if g is 20 then 0-g (zero minus twenty) will be -20.

    And if g is -20 then 0-g (zero minus minus twenty) will be 20.

    Just try it. It will work

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)