BVE WorldWide
Would you like to react to this message? Create an account in a few clicks or log in to continue.

.animated sound (StateChangeSound)

4 posters

Go down

.animated sound (StateChangeSound)  Empty .animated sound (StateChangeSound)

Post by LXQt Wed Apr 21, 2021 12:25 pm

I am trying to make a platform announcement (Train arrival), where it would be played if the train is 425m behind the object. (The object is placed in the end of the station)
My following code is:
Code:
[Object]
States = 1.csv, 2.csv
Position = -8.2, 0.2, 0
StateFunction =  If[trackDistance[0]<425, 1, 0]
[StateChangeSound]
FileNames = , ARR.wav
Position = 0, 0, 0
Volume=0.8
Radius = 200

What I am expecting to happen: If the train is 425m behind the object, change the state to 1.
When the state got changed to 1, play the Arrival sound. Since the train is less than 425m, it should always return 1 from now on. And it should only play the sound once as the state only got changed once.

What happens instead: The sound will repeatedly play every few seconds when trackDistance is smaller than 425m.

Is this intentional? If yes, what is the correct way of doing it? Thanks Very Happy


Last edited by LXQt on Sun Apr 25, 2021 5:20 pm; edited 1 time in total (Reason for editing : Further explanation)
LXQt
LXQt

Posts : 114
Join date : 2019-02-18
Location : Hong Kong

https://lx862.com

Back to top Go down

.animated sound (StateChangeSound)  Empty Re: .animated sound (StateChangeSound)

Post by LXQt Sun Apr 25, 2021 5:19 pm

Still can't make it to only play once Sad

A workaround is to check If[trackDistance[0]>400 & trackDistance[0]<425, 1, 0] (Check if the train is between 400 and 425m from the object)
Then apply an 8 second RefreshRate, so there must be at least an 8 second interval before it loops again. (Which the train has PROBABLY passed at this point)

The problem is
1. It will loop again if the player decided to have the train go slower.
2. Sometimes I end up missing the announcement due to timing (Going 25m requires less than 8 seconds at around 45-60km/h, the object could passed the 400m mark before it refreshes and change the state)
LXQt
LXQt

Posts : 114
Join date : 2019-02-18
Location : Hong Kong

https://lx862.com

Back to top Go down

.animated sound (StateChangeSound)  Empty Re: .animated sound (StateChangeSound)

Post by Delsin Sun Apr 25, 2021 5:22 pm

Probably it's a good idea to add a flag (boolean true/false) to the sound sections that determines if it's played once or looped
Delsin
Delsin

Posts : 313
Join date : 2016-08-20

LXQt likes this post

Back to top Go down

.animated sound (StateChangeSound)  Empty Re: .animated sound (StateChangeSound)

Post by LXQt Sun Apr 25, 2021 6:04 pm

That would be nice, but I am still not sure is this a bug or not...

The documentation (and the name "StateChangeSound" itself) suggest that it will only get played once when a state got changed.
So if nothing got changed after the train distance is closer than 425m, what could possibly triggers the StateChangeSound?
(It also does not wait for the sound to finish playing before playing another one, at an 1-2 second interval)

Older versions just straight up not work at all with the StateChangeSound

It may also be worth noting that on the example above, it is assumed that 1.csv and 2.csv is empty. I don't actually need to change states
Which means I can just use 2 null.csv and achieve the same effect.
LXQt
LXQt

Posts : 114
Join date : 2019-02-18
Location : Hong Kong

https://lx862.com

Back to top Go down

.animated sound (StateChangeSound)  Empty Re: .animated sound (StateChangeSound)

Post by NakanoS Tue May 04, 2021 6:59 pm

You miss this.
Code:
PlayonShow=1
PlayonHide=0

I forget which case it should be shown up. In case something still wrong, swap the value.
I have so much object with this exact feature and all worked with this key
NakanoS
NakanoS

Posts : 28
Join date : 2017-11-09
Age : 28
Location : Bandung, Indonesia

http://javvasharyo.weebly.com

Back to top Go down

.animated sound (StateChangeSound)  Empty Re: .animated sound (StateChangeSound)

Post by LXQt Tue May 04, 2021 8:48 pm

This is for a single state. The same thing happens even if I switch to single state with PlayOnShow/PlayOnHide.

It seems that the if statement will change the state everytime the original value changes. So even the same value can triggers multiple sound.

(Let just say trackDistance updates every one second, if the condition is true, it will set the same state every one second)
It also seems StateChangeSound detects when the state got set (instead of only changed).
LXQt
LXQt

Posts : 114
Join date : 2019-02-18
Location : Hong Kong

https://lx862.com

Back to top Go down

.animated sound (StateChangeSound)  Empty Re: .animated sound (StateChangeSound)

Post by Peti817172M Sun Dec 31, 2023 8:33 pm

I tried it, but only works, if I put the object in the scenery. But if I put it in a train, it won't show, and no sound.

Peti817172M

Posts : 4
Join date : 2023-12-26

Back to top Go down

.animated sound (StateChangeSound)  Empty Re: .animated sound (StateChangeSound)

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum