The function doesn't see the objects

0 favourites
  • 6 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • Hi! I don't understand the behavior of my function.

    This is a map:

    The player (purple) automatically stops in the middle of the green field.

    Then, the probe (black) will automatically start exploring the area in 4 directions. Its task is to record in which direction the player can make another move.

    Here's the code:

    I want the probe to start after the player stops. The probe will write to the array objects from the 4 studied directions. On the map above you can see the moment when the probe moved from the player in the first direction.

    Currently, this code works like that:

    the probe will write to the array only the first object, the green one from which it starts.

    And normally, when I turn off the function and I turn on the code above, it will work properly:

    it writes to the array all the objects encountered by the probe. But unfortunately it does it all the time while moving on the map with the player.

    So I need a function that will run the probe only at a specific point and time of the map.

    Do I have to send something to the function?

    I suspect that this is another missing element in my Construct learning. Oh, I would really like some advanced course, maybe you know one?

  • I see your problem and yes the function will run just once. You do this with a global variable toggle. When the player stops or whatever the trigger is, set the global variable from 0 to 1. Instead of the function call have a condition variable=1. When the pathing has finished, set global variable back to 0.

  • Thanks a lot Plinkie!

    Now it works almost good :-)

    The UIDs of objects are stored in the array,

    but the probe turns 90 degrees when starts.

    It has something to do with the first action, where I rotate the probe 90 degrees.

    But it is only called once after using the SPACE key.

  • Maybe a working code snippet will help?

    I left only this strange behavior.

    For some reason the probe later turns again,

    although the rotation is only once at the beginning.

    Can someone give me a hint?

    drive.google.com/open

  • The bullet behavior is likely the issue.

    You modify the angle of the object, but the angle of motion of the bullet behavior is still the same.

    Consider making your moving angle an instance variable of "Sonda".

    When you want it to move, you can set it to

    moveAngle = (moveAngle + 90)%360

    The modulo will make it go back to an angle of "0".

    When you set your bullet to actually move (have its moving speed > 0) then you can set its angle of motion to be equal to moveAngle.

    You should then see it turning as intended.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks Kyatric!

    Small steps forward :)

    I need accurate insight in the directions of the player and probe.

    Since the bullet behavior is causing the problem, I decided to add a function that will allow me to have an excellent orientation in the directions.

    In the picture I have selected the condition checking the value of the global variable called "player_direction".

    And it does not work!

    If I add the second parameter to the function and pass the string "west" then it will work.

    But I need a direct checking of the global variable.

    How can I do in function?

    edit:

    I can't add the picture, so I send it to Google Drive:

    drive.google.com/open

    edit2:

    It works!

    I was combining further and made the big discovery!

    The value of my global variable was written in quotes and it should not be.

    I thought that by defining a global variable as a string I should write its default value in quotes.

    And that was a misunderstanding, uffff :-)

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