Why is this pick-by-instance-var failing?

0 favourites
  • 11 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • See below. The function below is called from another function after 3 Monster sprites are created and some instance variables (their inst-vars come from Family) are set. There is 100% definitely a Monster with key=10. I can see it clearly in debug, but it never gets picked. What am I doing wrong?

    Tagged:

  • So question, maybe this is answer: Does Action: Function.Call block and wait until function called finishes all events and actions and returns before continuing to next Action after call?

  • Ok I think I see how this works. I have to use "System > Wait for Signal" and "System > Signal" to simulate JavaScript "Callbacks". Just did a quick test and I think this is what I want.

  • Ok "Signals" are broken. This won't work.

    You can't nest Signals. If in a toplevel pick event, you try Function.Call, on line right after set "Wait for Signal" (WFS). Then in the called function, do another Function.call, next line set WFS, the second WFS never triggers. I have a logging line (writes to textbox) right after and you never see it. And yes there are Signal "..." at the tops of the functions so that's not the issue. And the Signal strings are in global Constants so no, its not an incorrect Signal/WFS string issue.

  • When objects are created they are picked in that event alone.

    Objects do not exist outside the creation event until the next tick.

    Another reason to not use functions so often.

  • locohost

    the problem is that Construct 2 and 3 doesn't finish creating an object until immediately after the event where it is created.

    So, you have to wait until the next top level event before you can "pick" the object (because by then construct has added the object into its internal list of objects - making it pickable).

    there is nothing wrong with using functions as long as you understand that it is extending the event where the function is called from.

    that means if you have an event that calls a function that creates an object, and that function calls another function, or you call a second function from the original event, construct executes all those actions as part of that first event, and doesn't finish creating any new objects until the event is completely finished.

    The objects are automatically picked when you create them - the only way you can access the object from within a function call (within the same top level event as where it was craeted) is to pick the object by its UID. So you can pass the UID of the object to a function and use the UID to pick the object and work with it that way.

    The only other option I know of is to add a "Wait 0 seconds" before adding additional actions/function calls. What that does is wait until the end of the current tick to execute those actions - which counts as a new top level event, and at that point the objects can be picked.

    so, forget the wait for signal, try adding a "wait 0 seconds" before you call the second function.

  • Another reason to not use functions so often.

    Ok this was going to be next question: Should I even use functions at all? I've been coding for my main hobby and professionally for literally 37 years. This makes me think of everything in C3 as "code" and that's really probably wrong.

  • There's lots of reasons to use it. In fact I use it when I do need to break picking.

    You just have remember all the quirks.

    I think the main reason to use it is because of its ability to pass params, and reduce events.

    The main thing I don't like is events are very linear, and calls can be placed anywhere.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • locohost - I literally ran into the same thing with my recent post too

    here> construct.net/en/forum/construct-3/how-do-i-8/how-long-does-a-pick-sprite-la-142303

    I too have been programming for many, many, many years and tend to function'ise as much as possible to reuse code and prevent repetition. That was also my downfall :)

    So, want to let you know you weren't alone on this one.

  • Well, I guess you have to get used to how Construct 2,3 do things.

    I've always been doing this by Comparing instance variables ( if I understand correctly what you are doing ).

    If Monster var = 10 Monster>play animation/do whatever, then when hits frame X, jump,fire a shot or whatever is supposed to happen, and it has always worked even inside a function

    I don't think I have ever used picking for anything and don't feel like I am missing out on anything.

    Then again I still use Construct 2 even though I have subscription to 3 running.

  • locohost - I literally ran into the same thing with my recent post too

    here> construct.net/en/forum/construct-3/how-do-i-8/how-long-does-a-pick-sprite-la-142303

    I too have been programming for many, many, many years and tend to function'ise as much as possible to reuse code and prevent repetition. That was also my downfall :)

    So, want to let you know you weren't alone on this one.

    Thank you graham-s

    That does make me feel better :-) Do you use the "wait 0 seconds" just before calling sub-function trick? That seems to be working for me. Thank you AllanR for that one. I'd love to compare notes on using functions in C3. I really can't build an app without lots of functions. With all the suggestions and helpful replies here, I did get a lot working yesterday.

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