default audio by variable

Get help using Construct 2

Post » Mon Jan 23, 2017 3:32 pm

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
B
60
S
20
G
56
Posts: 1,077
Reputation: 35,941

Post » Mon Jan 23, 2017 6:45 pm

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.
B
45
S
15
G
73
Posts: 2,006
Reputation: 43,394

Post » Mon Jan 23, 2017 6:52 pm

@plinkie 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.
B
60
S
20
G
56
Posts: 1,077
Reputation: 35,941

Post » Mon Jan 23, 2017 6:53 pm

How are you currently doing it, or are you also looking for ideas on a way to do the main comparisons?
B
45
S
15
G
73
Posts: 2,006
Reputation: 43,394

Post » Mon Jan 23, 2017 7:03 pm

@plinkie

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.
B
60
S
20
G
56
Posts: 1,077
Reputation: 35,941

Post » Mon Jan 23, 2017 7:27 pm

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.
B
45
S
15
G
73
Posts: 2,006
Reputation: 43,394

Post » Mon Jan 23, 2017 7:34 pm

@plinkie 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.
B
60
S
20
G
56
Posts: 1,077
Reputation: 35,941

Post » Mon Jan 23, 2017 7:43 pm

@plinkie It works! Thank you.
B
60
S
20
G
56
Posts: 1,077
Reputation: 35,941

Post » Mon Jan 23, 2017 7:50 pm

No problem :)
B
45
S
15
G
73
Posts: 2,006
Reputation: 43,394


Return to How do I....?

Who is online

Users browsing this forum: Alvaro2 and 15 guests