Functions called multiple times in the same tick

0 favourites
From the Asset Store
75 power-up sound effects; bonus and notification sounds, fanfares, harp glissandi, stabs, clock ticks, etc.
  • Hi everyone,

    I'm encountering problems with functions. When a function referring to different instances of the same object, or different objects of the same family is called multiple times in the same tick, weird results may happen.

    I've made a very simple capx to show what I meant:

    https://www.dropbox.com/s/w396g5ws6flf5 ... .capx?dl=0

    In this capx, 2 objects of the same size and of the same family are partly superposed, and a function putting them to red color is called when you hover over an object of that family.

    The result is the following:

    When hovering both objects at the same time, only one object is put to red.

    When hovering an object, then the other one, the second object is put to red only when you're not hovering the first object anymore.

    Is there a way to make this function work as intended, i.e. having both object turn to red when they are hovered together?

    By the way that is what happens if you're not using functions but just putting "set animatin to red" as the action of the first event, but I would like to use functions if possible.

    Thanks ! <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • Rable

    You forgot to put the "For Each">> "famsprites" after the >>cursor is over the famsprites

    as is picking more than one object

    Example:

    cursor is over the famsprites

    -For Each>> "famsprites>>>>Call Function

    It should work now

  • Thanks a lot, it works now!

  • Thanks a lot, it works now!

    No problem

    Just remember when you have more than one object picked and you need to apply to them actions individually you will need the (for each) always, other ways it will apply the Action just to the first instance of that object = 0

  • tarek2

    Very interesting! Thanks again! Do I need to use "for each" also with timers?

    For example I have plenty of objects that call a function when "on timer" triggers, but potentially the same timer could expire on multiple instances of the same object at the same time.

  • Manual:

    On timer

    Triggers either regularly, or once off, after a timer that was started with the same tag has reached its duration. NOTE: this trigger can fire with multiple instances picked, if their timers all reach their time in the same tick. This can sometimes work unexpectedly if the actions expect there to be just one instance picked. The workaround is to add a For each condition after this trigger to ensure the actions run once per instance.

  • Thanks blackhornet , didn't check the manual for that, sorry.

    However,there is something I don't understand with the said workaround by adding the "for each" condition after the trigger.

    I mean... On timer is *already* triggered once per instance (as stated the line just above), right?

    So adding a for each condition will do nothing, unless you specify more conditions below. Correct?

    Sorry I'm sick at the moment so maybe I have a hard time understanding simple concepts... ^^'

  • this trigger can fire with multiple instances picked

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Haah that one haha you know how many long nights left me without sleep weeks, I thought it was a bug at the end and I reported here

    https://www.scirra.com/forum/viewtopic.php?f=152&t=198891&p=1154742#p1154742

    I thought the same that the Timers are independents and wouldn't imagine that was an exception for this which make them a bit contradictory and I read the Manual part about "Timers" many Times but as I thought that Timers were independent that's why my brain didn't recognise the "Exception" until Ashley pointed me to that part of the manual, since then it messed up my brain you don't know when or when not to put the for each it looks like if you have more than one object that they gonna use the same Timer at once the best thing is to put the For Each always just to be safe, but hey as it has an easy work around so is not a big deal.

  • Ok, got it. So basically add "for each" everywhere.

  • blackhornet tarek2

    Re. the timer multiple fire issue, is it possible to circumvent this by using "fire"&self.UID as a tag?

  • No. Why do you care? A foreach deals with each individually.

  • I have a bug in one of my projects; multiple instances are running simultaneous timers and I've been using a tag containing the instance UID to differentiate between them. Sometimes an instance hangs when the timer expires.

    If making the tags unique by including the UID isn't enough to distinguish between timers for instances of the same object finishing on the same tick then that might explain the issue I'm experiencing, hence my interest.

  • blackhornet tarek2

    Re. the timer multiple fire issue, is it possible to circumvent this by using "fire"&self.UID as a tag?

    Hi mekonbekon

    As blackhornet said, I don't think it will make any difference if I understood right, the problem is if many Timers trigger at the same Time you can expect sometimes that they will not work as is intended if they have the same "Tag" names, at list this is what I understood I may be wrong though

  • I have a bug in one of my projects; multiple instances are running simultaneous timers and I've been using a tag containing the instance UID to differentiate between them. Sometimes an instance hangs when the timer expires.

    If making the tags unique by including the UID isn't enough to distinguish between timers for instances of the same object finishing on the same tick then that might explain the issue I'm experiencing, hence my interest.

    mekonbekon

    I test it with your idea by using ("fire"&self.UID as a tag) with the example that I posted on the bug report but it didn't work, nice idea by the way and this leads to the next question is the ("fire"&self.UID as a tag) working as it looks? shouldn't give for each Object different tags because the UIDs are all different yet on my test didn't work, so my guess is

    "fire"&self.UID as a tag = exactly the same name no UID numbers added

    or

    "fire"&self.UID as a tag = or something weird because doesn't work jeje as in theory if it added each UIDs of the objects it should work because they have a different unique UIDs and on the manual part it stated if the "Tag" is the exactly the same

    [quote:ih3sh0zv]Manual

    started with the same tag has reached its duration. NOTE: this trigger can fire with multiple instances picked, if their timers all reach their time in the same tick

    Notice the part where it says "Same Tag"

    I think the question now is what is the real "Tag" it gives when you add "fire"&self.UID as a tag, that could tell you if the problem is with the Timers, example the exception is for both (Same Tag or Different Tags)

    or the problem is in something else on the events

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