picking objects and functions

0 favourites
  • 7 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • Only a single blue sprite2 object is allowed to be created on any black sprite. The Boolean is not being changed so sometime 2 or more blue sprite2 objects are being created on the same black sprite object.

    Why won't the function update the boolean?

    If i delete the function and just update it with the currently disabled action it works as expected.

    I'm guessing it has something to do with the fact that its in a loop, or the fact the sprite has just been created, but i thought adding wait 0 would ensure it was added to constructs internal object list? I've tried it with and without with no effect.

    I've also tried different picking methods in the function itself incase that has something to do with it but anyway i though functions cancelled any objects previously picked?

  • Replace

    with

    (0=False;1=True)

  • Thanks for trying to help, but that doesn't work. It does if i use the disabled action, and not with the function, which is what i'm after.

  • Ethan

    the problem is that the System > Create Object takes some time to actually create the object (or at least add the new instance to the list for that object - that seems to happen on the next tick).

    So, when the function is trying to Pick the Sprite2 nearest to Sprite, it doesn't know the one you just created exists yet. Therefore, it doesn't pick it, and then the Sprite.isChanged variable is not getting set to true, so the next time through the Repeat loop that Sprite is still available to have a Sprite2 created on it.

    Having a function re-loop through every Sprite while in a Repeat loop isn't an ideal way to do things. It would be better to pass the Sprite.UID into the function as a parameter, then in the fuction Pick Sprite by UID. Then you can do what ever you want to it - without having to loop through other instances. You can also pass the Sprite2 UID into a function and pick it as well. (trying to pick it using Pick Nearest doesn't work, but picking it directly by its UID does work).

  • The wait is messing it up in this case. What it's doing is pushing the function call to the end of the event sheet, and what you want is the call done in place.

    When creating a new object this defines when it can be picked:

    and

    "pick by uid" is the exception as it works for any object that was created.

    For accessing new object's immediately from a function you should pass that object's uid. Then you can pick the object by uid in the function, and reverse it to pick a sprite from the sprite2.

    For ex:

    call "hasframechanged" (sprite2.uid)

    on function "hasframechanged"

    sprite2: pick with uid function.param(0)

    sprite: pick closest to (sprite2.x, sprite2.y)

    sprite: x = sprite2.x

    sprite.y = sprite2.y

    --- sprite: set ischanged to true

    AllanR

    The newly created object is added to the object list at the next toplevel event as per the links above.

  • R0J0hound Thanks! that is good to know.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • AllanR R0J0hound thanks for your explanations.

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