home home

downloads files

forum forum

docs docs

wiki wiki

faq faq

Cube & Cube 2 FORUM


Delayed sound play

by SheeEttin on 11/28/2007 05:27, 21 messages, last message: 12/07/2007 05:59, 3617 views, last view: 05/02/2024 14:18

So I'm trying to set something up that is, at least to me, rather complicated.
I have a sound which I am trying to play in the background every so often. This is what I put in my map CFG:

while [$fov] [ sleep (+ 90 (rnd 60)) [ echo "sound (registersound sheeettin/growl.ogg)"] ]

...which should always return true, because the FOV will always be greater than zero. Now, it should then execute the sleep and related script... but it stops loading the map (and memory usage goes wicked high).
Why is this? Is it continually executing the while condition, instead of just once? Is it registering an infinite number of the sound? (The docs say it should just return the value of the previously-registered sound...)

Or, is there a better way to accomplish this goal?

Go to first 20 messagesGo to previous 20 messages    Board Index   

#2: ..

by apflstrudl2 on 11/28/2007 13:08

make a loop script with a sleep comman in it and you\\\\\\\'ll see that it won\\\\\\\'t wait until the sleep comand is over.
you could try somthing like this:

soundloopon = 1
soundloop = [ if ($fov) [
sleep (+ 90 (rnd 60))[ echo \\\\\\\"sound (registersound sheeettin/growl.ogg)\\\\\\\"]
if (= soundloopon 1) [soundloop]
]

i think that will do what you want

echo \\\\\\\"sound (registersound sheeettin/growl.ogg)\\\\\\\"]

doesn\\\\\\\'t register a sound, that\\\\\\\'s just an echo of: \\\\\\\"sound (registersound sheeettin/growl.ogg)\\\\\\\"

reply to this message

#3: Re: ..

by SheeEttin on 11/28/2007 23:31, refers to #2

Well, that brought me to

soundloop = [
sleep (+ 90 (rnd 60)) [ echo "sound (registersound sheeettin/growl.ogg)" ]
soundloop
]

...which works until you call soundloop, I assume because it calls itself recursively.
This is one of those places where a GOTO would actually be useful...

reply to this message

#4: Re: ..

by MovingTarget on 11/28/2007 23:39, refers to #3

>This is one of those places where a GOTO would actually be useful...

You didn't just say that, did you???

/me covers my ears and screams

reply to this message

#5: Re: ..

by SheeEttin on 11/29/2007 00:39, refers to #4

There are cases such as these...
A loop's out because it'll ignore a sleep (or so apflstrudl2 says), while doesn't work because of the reasons above, and a recursive call just stops.

So, um, anyone got any ideas? MeatROme, are you reading this? :(

reply to this message

#6: Re: ..

by demosthenes on 11/29/2007 07:58, refers to #5

Doesn't it work better backwards?

soundloop = [<play sound>; sleep ((+ 90 (rnd 60)) soundloop]

reply to this message

#7: ..

by apflstrudl on 11/29/2007 16:07

soundloop = [<play sound>; sleep (+ 90 (rnd 60)) [soundloop]]
that'll work, but i would make i command to stop that. Otherwise you've to restart to stop this.

I don't know which one works better. The one demosthenes wrote playes the sound from beginning, the otherone just after some time.

reply to this message

#8: Re: ..

by SanHolo on 11/29/2007 20:01, refers to #7

Hmmm, that code will require more and more memory since the calls don't ever finish. Isn't there something like setTimeout() in Cubescript? That'd allow the function to exit (and get rid of the sleep command).

reply to this message

#9: Re: ..

by SheeEttin on 11/29/2007 23:04, refers to #7

Those helped a lot. It works now!
Here's roughly what it looks like:

soundloop = [sleep (* 100 (+ 90 (rnd 60))); [ sound (registersound sheeettin/growl.ogg); soundloop ]]
soundloop

But there still exists the problem of it continuing if the map is changed. I tried creating an alias for map (to set a variable which the script checks to see if map was called), but creating aliases in place of built-ins isn't allowed...

Hey! How about checking if the fog changes colors? (I've set my own fog color.) That should work.

reply to this message

#10: ..

by apflstrudl on 11/30/2007 15:31

you could also set a variable which you have to set with the console. That's what i wrote some posts before, or you could write this variable in the map cfg and before you run soundloop again you'll check if it's 0 or 1 (or something else)

reply to this message

#11: Re: ..

by SheeEttin on 11/30/2007 22:11, refers to #10

Problem with that is that the variable would persist if the map was changed; I can't have everyone change all their CFGs to set the variable back to 0.

Incidentally, the fog color-change solution works fine.

reply to this message

#12: Re: ..

by MovingTarget on 11/30/2007 22:20, refers to #11

That is an ingenious solution there :-)

reply to this message

#13: Re: ..

by SheeEttin on 11/30/2007 22:25, refers to #12

Simple, really.
I just thought "Well, what changes when a map loads? The fog color, for one... Let's do that!" and it worked!
You just need to think about things in the right way and solutions will present themseleves.

reply to this message

#14: Re: ..

by Hirato Kirata on 12/01/2007 02:30, refers to #9

The simplest I could think of was this to check for fog colour changes


alias bak-fogcolour 0

fogcheckloop = [if (= $fogcolour $bak-fogcolour) [sleep 100 [fogcheckloop]] [sound (soundfile); alias bak-fogcolour ($fogcolour); sleep 100 [fogcheckloop]]]

fogcheckloop

reply to this message

#15: Re: ..

by SheeEttin on 12/01/2007 03:01, refers to #14

Hmm... That seems a little complicated. I went with this:

soundloop = [
sleep (* 1000 (+ 90 (rnd 60))) [
sound (registersound sheeettin/growl.ogg 200)
if (= fogcolour 12591120) [] [soundloop]
]
]
if (= fogcolour 12591120) [] [soundloop]

Plays the sound when I want it, and doesn't continue looping if the fog color changes.

That'll be what's in the map (more or less), unless I decide to put the fog check earlier (to eliminate a sound queue -> map change -> sound play situation). Maybe put it before the sleep and make the sleep, etc. execute if it evaluates true... Yeah, let's do that.

reply to this message

#16: Re: ..

by Hirato Kirata on 12/01/2007 03:15, refers to #15

alias bak-fogcolour 0

fogcheckloop = [if (= $fogcolour $bak-fogcolour) [sleep 100 [fogcheckloop]] [sound (soundfile); alias bak-fogcolour ($fogcolour); sleep 100 [fogcheckloop]]]

The above will see if fogcolour is the same as bak-fogcolour, which is an alias. if it is, sweet, it'l just loop it. if it's not it'll play a sound and make bak-fogcolour the same value as fogcolour. so basically it'll play the sound whenever a command is issued to modify the colour of fog and then wait for another.

soundloop = [
sleep (* 1000 (+ 90 (rnd 60))) [
sound (registersound sheeettin/growl.ogg 200)
if (= fogcolour 12591120) [] [soundloop]
]
]
if (= fogcolour 12591120) [] [soundloop]

By the looks of yours (and my knowledge of cubescript) It'll loop over and over as long as the fogcolour isn't yours. And if the colour is yours, it'll just deactivate till the next time it's run (and again deactivated).
I may be wrong as empty spaces are often ignored so it may just loop over and over as long as the colour is yours

~Hirato Kirata

reply to this message

#17: Ahemm ...

by MeatROme on 12/01/2007 13:05

Just saw the whole backlog in one go,
what /are/ you doing? ;-)

registersound is for using once - to register the sound - then remember that index for later usage.

and if you want a sound to be looped my approach would be to use it as a mapsound (these have their own index list) and place appropriate sound entities around - those get looped anyway ;-)

Didn't really get deeper into what you wrote about fogcolor, but in the end, if you've registered it once and gotten back SND_IX then you can play it with [sound $SND_IX] :-)

reply to this message

#18: Re: Ahemm ...

by SheeEttin on 12/01/2007 22:01, refers to #17

According to the docs, doing a /registersound on a previously-registered sound returns the index of the sound, so what I've got should register the sound if it's not registered, and return the sound index if it is.
This means that it won't play the sound on the first loop, but that's okay... A longer delay at first is good.

On mapsounds: I'd rather have it play in the background, alongside the music. It's meant to be heard wherever you go, no matter what you're doing. Once I pick out some music that goes well with the sound and the map, it'll all fall into place.

Everything will make a bit more sense once you see the whole map, by the way.

reply to this message

#19: Re: Ahemm ...

by MeatROme on 12/01/2007 23:42, refers to #18

A mapsound with large enough radius, or multiple ones and a "1" instance counter added to the mapsound loading - so u only ever hear the one instance - can't guarantee their all in phase though.
place it near map center
newent sound 1234 1024 1204
if 1234 is your mapsound index (no default ones, so your first one will actually be 0). and 1024 would be radius and size - so if your map isn't larger you'd hear it everywhere at full volume (full = what the cfg specifies).

loading the same sound twice doesn't work,
you'll need to at least pass different parameters, e.g. load the second with a volume of 254 ... but why the hell would you want two almost identical sounds?

reply to this message

#20: Re: Ahemm ...

by SheeEttin on 12/01/2007 23:54, refers to #19

I don't want to load it twice.
Trying to load it twice just returns the index of the already-loaded one (which is what happens there).

reply to this message

#21: I hate things like this!

by Sprintersoft on 12/07/2007 05:59

Why is it suddenly so hard to render a delayed sound loop? I could have coded a simple game in the time you people have been debating this! (And I am a terrible codemonkey!)

P.S. These "are you human" questions are getting harder and harder...

Visit my website at:
sprintersoft.wikidot.com

reply to this message

Go to first 20 messagesGo to previous 20 messages    Board Index   


Unvalidated accounts can only reply to the 'Permanent Threads' section!


content by Aardappel & eihrul © 2001-2024
website by SleepwalkR © 2001-2024
53868409 visitors requested 71643580 pages
page created in 0.021 seconds using 10 queries
hosted by Boost Digital