playMaker

Author Topic: Detecting Objects [SOLVED]  (Read 1600 times)

kitkat29

  • Playmaker Newbie
  • *
  • Posts: 3
Detecting Objects [SOLVED]
« on: July 20, 2018, 04:19:36 PM »
Hello,
I need some help with figuring out how to detect if an object is already inside a square. In the picture I have 2 characters, I don't want them to be able to be inside the same square. I have all of the character movement, so when you click on a character it will ask you to select a square. https://gyazo.com/be6a836ba8d559a7fdb819dc987f67de
« Last Edit: July 23, 2018, 04:15:53 PM by kitkat29 »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Detecting Objects
« Reply #1 on: July 20, 2018, 06:07:26 PM »
Hi.
There are a few ways i can think of.

For example :
Have an array called (for example) "occupied".

once a player is on a square add it to the occupied array by using 'Array Add'.

When the player selects a square, use 'Array Contains' and check with the selected square.

When a character leaves a square, use 'Array Contains' and store the index.
Then use 'Array Delete At' with that index.

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 150
Re: Detecting Objects
« Reply #2 on: July 20, 2018, 08:14:11 PM »
If it's only to check if the square is free or not, why not just have a bool like "isOccupied" for each square?

kitkat29

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Detecting Objects
« Reply #3 on: July 20, 2018, 10:49:13 PM »
So I have it working but the problem is the square is still stored in the array. When the character clicks on a new square should I have something to delete the previous square from the array if so how would I go about doing that.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Detecting Objects
« Reply #4 on: July 22, 2018, 02:19:11 PM »
Hi,
@ start store the object where the player is in a variable (call it currentPosition for example) , then when targeting a new position and it is empty, do this :
Quote
'Array Contains' and store the index.
Then use 'Array Delete At' with that index.
Then store the new position in the 'currentPosition' variable.

kitkat29

  • Playmaker Newbie
  • *
  • Posts: 3
Fixed it
« Reply #5 on: July 23, 2018, 04:15:20 PM »
I fixed it, it was just some arrows pointing in the wrong direction xD.

Thanks, guys I appreciate the help!