Methods of "Queuing" for a function.

  • I have a function that displays achievements. There is an array with Achievement ID, Title and Flag. When the right conditions are met, a parameter is passed to the function for the achievement ID, then the function displays the Title for the achievement in a popup and flags the achievement as "done" in the array. The popup is about 3 seconds long.

    There may be conditions where 2 or 3 achievements are triggered (for different IDs) in the same second. In this case, I do not want all 3 popups to fire simultaneously, but one after the other (with popups being about 3 seconds each).

    I tried the following but it seemed to fire the same achievement twice:

    Example:

    <if conditions are met for achievement ID1>
    Call Function "Achievement" (1)
    	
    On Function "Achievement"
    	If AchDisplay=False then
    		Set AchDisplay=True
    		<Do popup and array stuff>
    		Wait 3 Seconds
     		Set AchDisplay=False
     	Else
    		Wait 3 seconds
    		Call Function "Achievement" (Function.Param(0))
    

    Not that a circular reference is the best idea anyway.. but recalling the function again with the same param did not fly. Grateful for any ideas. Plan B is to display simultaneous Achievements in varying areas of the screen, but it looks crusty. Thanks, -Steve

    Edit: I see now that I'm experiencing this:

    Note about using 'Wait' in functions

    Note that in a function call, if you use 'Wait' then the function has finished by the time the next action after the 'Wait' runs. This means the function parameters are no longer available. You could work around this by copying function parameters to a local variable.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Using "Wait" like this is a bad idea. Timer is a much better option, but you still need to keep pending achievement IDs somewhere.

    .

    You can try a different approach - create an array or dictionary named PendingAchievements.

    When a new achievement is unlocked, add it to this array.

    Every 1 second or so check this array, if it's not empty and AchDisplay=false, display first achievement from the array and remove it.

  • dop2000 was a little faster but my example should not be in vain ;)

    (open C3 editor.construct.net ): 1drv.ms/u/s!Ap_-qxoGKbDcg10G1gtAsIxRyTeo

  • Thanks dop2000 for the pointers and kriand for taking the time for an example! It's working well now.

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