0 Favourites

Using Overlaps(object) in Python

This forum is currently in read-only mode.
  • I've run into a problem with the Overlaps condition in Python. In my test file, I've got a moving block (object1) and a stationary block (object2). When the moving block is overlapping the stationary block, I want a text object (text) to display "True." When the moving block is not overlapping the stationary block, I want the text object to display "False."

    I've gotten this to work using the normal events on the event sheet, but I want to do it using a Python script. I've tried the following, but it doesn't work:

    if object1.Overlaps(object2) == True:

    text.Text = "True"

    else:

    text.Text = "False"

    What am I doing wrong? The text object displays "False" even when object1 is overlapping object2. Overlaps doesn't seem to work how I expect it to. Does anyone have any suggestions about how to get this to work? Any help would be greatly appreciated.

    -Zumbooruk

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • object2 should be in quotes:

    object1.Overlaps("object2")[/code:2x3quw2v]
    but that, although correct, causes construct to crash.
    
    Use OverlapsOffset instead:
    [code:2x3quw2v]if object1.OverlapsOffset("object2",0,0):
       Text.Text = "True"
    else:
       Text.Text = "False"[/code:2x3quw2v]
  • Thanks! OverlapsOffset works perfectly.

    I was starting to go crazy. I was trying Overlaps with double quotes, single quotes, and without quotes -- none of which works.

    -Zumbooruk

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
76 9,273
Pandadoor's avatar
Pandadoor
Unread hot topic
0 Favourites
[plugin] 3D using Copperlicht
72 25,984
Reken's avatar
Reken
Unread hot topic
67 9,855
spartacuswell's avatar
spartacuswell