default audio by variable

0 favourites
  • 9 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • In one of my games I have a text box where the player can type in a word, like a type of animal. That word is set to a variable and then I play an audio clip based on the variable. So, for example if they type the word "cat" in the box, the audio file "cat" will play. Same with "dog", "chicken" or whatever. My question is, how do I play a default sound if the word they type into the box isn't an audio file that I have in the project. For example, if they were to add the word "house" or "asdf" or just leave the box blank, I can play something like incorrect.wav

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • In general, it'll be something like if "cat" play cat, "dog" play dog, ELSE play "incorrect" where the else just covers every other possible entry.

  • Well, I thought about that but there are too many sound files to do it that way. Unless I can make some kind of file with all the words in it and then compare the variable to that list. Then if the word isn't on the list then the default would play. I'm just not sure how to go about doing something like that, or if it's even the best course of action.

  • How are you currently doing it, or are you also looking for ideas on a way to do the main comparisons?

  • On button clicked System set GV_Animal to TextBox.Text

    (when triggered) Audio Play GV_Animal not looping from sounds at volume 0db (tag "word").

    Audio On "word" ended -> (calls a function here)

    It works so long as the word is an audio file but if it's not then not then no audio plays so the function never runs. I tried adding an else but I either set it up incorrectly or it just didn't work properly.

    I'm open to any ideas.

  • Hmm from the way you've set it up you could potentially do this :

    On button clicked, set another GV to true i.e. GV_Playing

    Then while GV_Playing is true, if tag "word" is not playing (inverted isplaying) then play "incorrect", set GV_Playing to false and call the function. If "word" is playing then it will call the function on "word" ended anyway, and set GV_Playing to false.

  • That's a good idea. I'm going to try that. I had another idea using a second variable but I think your way might work better. I'll let you know how it turns out. Thank you.

  • It works! Thank you.

  • No problem

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