Play Sound whenever object is moved?

I have a tennis ball I’m going to be moving a lot, and every time I move it I’d like it to play a wack sound.
How could I set this up?

Thanks!

I’m guessing this would work. On the map properties, place a keyword under “Key command to apply to all units ending movement on this map”. Like ‘MapSwitch’ or something like that.

Then place a sound trait on the ball piece that triggers on MapSwitch.

It should play the sound every time you move it.

Hello, I finally had the chance to try this and I can’t follow your instructions. Can you go into more detail?

Do you mean go to MainMap/GlobalProperties?
Or something different?

Thanks!

In the editor, double click on the main map component. This will show the map properties (not to be confused with Global Properties which is a Module, Map and Zone level component).

That did the trick, thanks!

Is there a way to get it to play 1 of 5 different sounds?
I tried sulecting 5 sounds, then adding {“Tball” + Random(5) + “.mp3”}

But it doen’t work. But if I sulect only 1 sound and put it in “sound clip” then it does work, for that one sound.

Paste up the screenshot of your attempt at Random that doesn’t work, please.

To judge from that graphic, you appear to have so-called “Smart Quotes” around your text literals. Make sure that you only use plain double-quotes, like this {"Tball" + Random(5) + ".mp3"}

If you find that copy and paste converts this example to use Smart Quotes, then I suggest that you hunt down the system setting that allows that on your machine and turn it off.

For example, on Mac, the setting is a Keyboard setting under Text Input, Text Replacements.

You can see in the bottom half of the panel, I have “Use smart quotes and dashes” disabled:


I changed the quotes, but nothing…

While I see nothing obviously wrong with your screenshots, the fact that you’re getting an “Expression evaluation error” tells me there is definitely something wrong with your expression. Try typing the expression from scratch, rather than copying it from elsewhere. I suspect there are still some non-ASCII characters somewhere in there (those plus signs look suspiciously large to me, for example, although that might just be the font being used for your chat window).

Can’t get it to work I’m afraid.

Sorry, I’m stumped. A very similar expression works fine when I test it on an Action Button. To rule out some other possible causes, can you get your exact same expression to work on an Action Button ?

I’ve come to the conclusion that this can’t be done. Only one sound can be played with what we’re doing and the way we’re doing it.

I can get it to work with multiple sounds with a button, but doing it the same way I can’t get it to work with this moving object.

I think it should work. However, you could instead use the Global Hotkey trait from the tennis ball piece to trigger the Action Button to make the sounds.

Are the five mp3 files actually inside the module? They will be inside an audio folder. ( I think.) had a similar problem, and I had to copy my mp3 into it via 7zip.

The more I think about it, the more I believe I’m right. I bet your vmod doesn’t include the mp3 files you need. Open your vmod with something like 7zip, and you should see a folder called “sound” (or “sounds”, (I don’t remember which) at the images level. If not there, create it. Then copy into it the six mp3 files you need.

I noticed when I looked at your error message that it first told you about a syntax error. I think that was a red herring because the very next line said “file not found,” and there it is.

And it makes sense if you think about it. When you specify an image file, you must explicitly state the file name, and there’s no fooling around with properties or file name construction. The editor can easily grab that image file. But with sounds it a different story. There is no way in hell the editor can know from “splat”+random(100)+”.mp3” what it should do. All it can do is throw up its hands.

1 Like

Sorry for the late reply.
How would I add 5 different sounds with the same file name?
[I found the folder and the sounds weren’t in there.]

You can’t! But if you have five distinct soundfiles named:

Tball1.mp3
Tball2.mp3
Tball3.mp3
Tball4.mp3
Tball5.mp3

…and you use the formulation @marktb1961 gave you a week ago: {"Tball" + Random(5) + ".mp3"}

That’s how it’s going to result in playing a random choice of those 5 files.

You can add those files using the Sound trait’s “Select” button. Do that for each file, then replace the last entry with the aforemantioned random expression. The files remain in the module, even when no longer referenced directly by the trait.

1 Like