How do I get the right people to go back to the right object

0 favourites
  • 6 posts
From the Asset Store
112 High-Quality destruction sounds for videogames
  • So I've been trying to work this out over a matter of days now, and I'm really desperate for some help.

    To give you a scenario. The player can call multiple 'police cars.'

    For this, I create the police car and add 1 to the global variable for Police Calls

    I then get construct 2 to associate the Global Variable for Police Calls specifically to the police car's instance variable called Call_ID.

    When the Police Car reaches it's destination, it parks, then construct 2 will spawn 2 police officers and will set the police officer's instance variable Call_ID to the same one the police car has, so the police officers from that police car have the same Call_ID instance variables.

    After they search around the place for a time, they will head back to their police car.

    So once the total search timer is 0, the boolean 'ReturningToPoliceCar' is set to true.

    This is where it gets really complicated.

    There is a sprite object that determines when the police officer goes back to the car called PoliceOfficer_GetIntoPoliceCar. This object has the same Call_ID instance variable as the police officers. It will only tell the police officer to go back to the police car if the police officers' boolean "ReturningToPoliceCar" is true and they are overlapping the object that tells them to get into the car.

    The police officer needs to go back to the police car they came out of.

    I can do this if there is only one police car and the 2 police officers from that car, but when it comes to more than one police car present, it stuffs up. Police go to the wrong car!

    Here is what I have:

    I know it's a complete mess. I think I'm going wrong at lines 72, 76 and somewhere between 77-80.

    I've become really lost with this. I've deleted the whole code and started again and I still can't seem to get it right.

    I can get it right if there is 1 police car with the 2 officers for the one police car but once there is 2 police cars with a different pair of police officers, it becomes complicated.

    I need to somehow tell construct 2 which police car is for what police officers so when they overlap or collide with the PoliceOfficer_GetIntoCar object, they go to the right police car and get deleted, but I'm so lost in how I can tell construct 2 that when it doesn't know which police car or what police officers are for what car to begin with. =[ The game has the capacity to provide an unlimited amount of police cars if really necessary, I have to keep it open for that flexibility. If any of this doesn't make sense please add my skype at lukenecklace so I can further explain/show and then once resolved I can share it here. Please help and thanks so much in advance.

  • First thing I noticed and maybe all that is needed..

    When you call the function you have to re-pick the right instance(s)

    Using the UID of the object as a parameter should work for this..

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • First off, your function line 69 will make it so that any instance of "Police officer" will have its boolean set so that it returns to the car.

    You should likely use the Call_ID as parameter to only pick those officers, or at least use a "Pick by UID" and use the UID as parameter from event 68 so that the function will only affect those specific instances, which have stopped searching.

    Event 72 you should have the "PoliceOfficer get into car" condition into the top event 70 or 71 actually. This way, the object is already picked and C2 then knows what object the policers are or are not overlapping.

    You don't need to pick "Police officer" anymore since you already picked it in event 70 and you also filtered what PoliceOfficer_getIntocar object this police officer instance should or should not overlap.

    That's clues to look into already, honestly, posting your capx would be simpler and allow for better debugging on our end.

  • Hey LittleStain and Kyatric,

    Thanks so much for your feedback. It's helped me think so much more.

    Kyatric, I understand that it will be a lot easier if I was to post my Capx. Unfortunately, I don't feel comfortable sharing my whole game out just yet. It's also very complicated to separate the code. That is why I offered a skype interaction. I'm keen on screensharing on there with you. For now, I will continue to post screenshots attempting to implement the feedback that you are providing. I am sorry this is not the easiest way.

    So the code I showed you in the screenshot allowed the police to stop at the correct "GetIntoCar" object. However, they were not heading towards the police car to be deleted, they were just stopping upon overlapping the GetIntoCar object.

    So to help me further with this issue, and due to the feedback you guys have given me, I have removed line 69 which was making all police officers regardless of whether or not they are searching to "ReturnToPoliceCar", that was a bit of a dumb one on my end, so I appreciate you pointing that out. Also, I have determined that I will need to pick the instances. However, before I get into understanding this, I want to show you the code that works when there is only one police car. This is me taking a step back on this thing:

    I believe from here, I just need to pick the right instances, but I am having trouble doing this without stuffing it up. Remember, there are 2 police officers per police car. They both have to go back to the right deletepoint from travelling along the path from the right GetIntoCar object.

    So from here they are: Stopping at any GetIntoCar object they run into, finding a path to any delete point, moving to that delete point then deleting.

    I'm so close to getting this right from here. I just don't know how to pick the instances in a way that it will work with multiple cars. =[ Further assistance on this issue is much appreciated and thanks so much for your help to this point.

  • When the Police Car reaches it's destination, it parks, then construct 2 will spawn 2 police officers [/code:2jnh4rwf]
    just a thought.. 
    add 2 new instance variable for PoliceOfficer startX & startY
    PoliceOfficer on created set startX=PoliceOfficer.X;startY=PoliceOfficer.Y
    then you can use
    On "FindPathToPoliceCar"--find path to( PoliceOfficer.startX, PoliceOfficer.startY)
  • korbaach, I didn't expect anyone to provide a full Capx of an example and share it with me and the rest of anyone else that might need help with issues like this.

    This is precisely the help I needed. I have applied similar principles to my game and it works like a charm. Thank you so much for going above and beyond, dude!

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