How do I have an event call functions one after the other?

0 favourites
  • 10 posts
From the Asset Store
Voice call plugin based on webrtc protocol for construct 3
  • My goal is to end up with a basic text/dialog system where the player walks up to a character/object, hits a button, and a few lines of text display. To handle this I created a "CharacterSpeech" function that, on execution:

    1. limits player input (so they can hit button to continue, but aren't running around the screen while the text displays)

    2. turns a GUI Textbox visible

    3. changes the text to the string parameter passed to the function

    4. waits (wait until signal, specifically) until a button is pressed

    5. turns textbox invisible

    6. returns player control

    To test it I had a character call the function upon interaction, to which it promptly said "Hello World!" as expected. However, I want it to say multiple things. I had thought it would have been enough to have two seperate events called upon interaction, both calling the CharacterSpeech function, saying "Hello World" and then "Hello Again," and had assumed that the second function wouldn't be called until the first function completed. This was not the case, and it seems both functions were called simultaneously (which is to say only "Hello Again" appears, having overwritten "Hello World" in the textbox).

    How do I set it up so the second "CharacterSpeech" function called in the interaction event doesn't display until after the preceding function is completed?

  • RexMundane - You want create a processor that executes thread chains of functions in a given order waiting for the previous one to finished before calling the next.

    The easiest method is as follows:

    First define variables

    • Create a stack of function names and store in an dictionary. (This will be your thread)
    • Create var functionIndex and set to -1 (Represents the next function to call)
    • Create var currentFunctionIndex and set to -1 (Represents the current function that was called)

    Now setup the processor

    • EveryTick if (functionIndex > -1) call Function from stack of that index (IE functionIndex = 0 call function name where dictionary index = 0)
    • Set currentFunctionIndex = functionIndex (to store for incremental purpose)
    • And then set functionIndex back to -1 so you stop calling functions

    Last is the control

    • When user presses a button (or some triggered event takes place) you take the currentFunctionIndex that was stored when the function was called and then set functionIndex to (currentFunctionIndex +1) so the next function will be called by the processor and so on
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm sorry, I still don't understand, I didn't succeed at Computer Science in college and am having a hard time understanding what you mean by this. Can you point me to an example resembles the problem I'm having?

    I don't know how to copy code out of C2, but what I have currently looks like this, where CurrentInteractionMode is a global var that limits player input as I mentioned.

    What do I add to it to make it work like you're saying?

  • RexMundane - No worries I created an example for you... Sorry if it seams over complicated but as a developer I'm usually pretty thorough in code layout.. It does require some understanding but I think it will make sense once you see it working and can go over the code. Hopefully this helps.




    Edit: I made it easier and took out the processor part and its simply a triggered event now.

  • Thank you but that doesn't seem to do what I'm intending for it to do. If I'm reading it correctly, what will happen is, evidently, the same text will be displayed in the same order each time the "ToggleDialogBox" function is initially called, basically reading the script out of the dictionary. So doesn't that cause a problem if, for example, I have two characters in the same layout who will say different things? Or a character that will say one thing the first time you talk to them, and a different thing on the second?

    I appreciate your time and patience on this, but I seem to still be struggling to understand. In the example as I presented it above, I think the problem solves itself if I could find a way to keep the second call of the CharacterSpeech function from affecting the DialogBox text until the first call is completed, is there not a way to do that?

  • RexMundane - For that you need to work with and understand containers and picking instances. I updated the example for you. I think from the example it will cover the basics. The Person Sprite has a container that has the Dialog Dictionary and the DialogBox has a container that contains the text box and button. When you pick the Person it also picks the dictionary and when you create or destroy the dialog box it also creates or destroys the text and button... Good luck.



  • There might be a mistake, I think that's the same capx file.

  • sorry about that.. try it again

  • Thanks. I see what you're doing there but it feels like that just creates more logistical problems down the line. Like what if I want a character where he says different things depending on when you're talking to them? If I'm reading this right you couldn't have a second dictionary contained by the character sprite and have the code work. You could theoretically, at the event that would change the character's dialogue, kill the existing character to replace with an exact duplicate who says the second dialogue I suppose, but wouldn't that start getting over-complicated?

    Plus the way I had things set up I was hoping to be able to set up other cutscene-style actions, like having a character move to a certain point, change their animation, etc, using similarly structured functions. I realize I must be coming off as a broken record on this but is there really no way to have, say, a kind of function that checks to see if one of it's kind is running, and if it is then to queue and wait for the current one to finish before running?

  • Bump.

    Been trying to fiddle with this for a week hoping to find an answer. Keep thinking it will either be some sort of IsScriptedEventHappening boolean flag or otherwise building a sort of event-queue, but no idea where to go from there. Can anyone help?

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