Using Overlaps(object) in Python

For questions about using Classic.

Post » Fri Sep 03, 2010 6:08 pm

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
B
2
G
2
Posts: 10
Reputation: 670

Post » Fri Sep 03, 2010 8:13 pm

object2 should be in quotes:
[code:2x3quw2v]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]
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Fri Sep 03, 2010 8:26 pm

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
B
2
G
2
Posts: 10
Reputation: 670


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests