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

Animation loop problem

2 posters

Go down

Animation loop problem Empty Animation loop problem

Post by Rakago Sun Apr 09, 2023 8:03 pm

Hello,

I want an animation that cycles through a list of objects but does not loop.

This is the code I'm using: StateFunction = mod[quotient[time,1],10]
This is the result:

The problem is, like I said before, it loops. I tried to use min instead of mod with the code but the animation does not cycle through the objects at all.

Any help is appreciated Very Happy
Rakago
Rakago

Posts : 67
Join date : 2019-10-30
Age : 17
Location : Spain

https://openbveiberia.blogspot.com/

Back to top Go down

Animation loop problem Empty Re: Animation loop problem

Post by leezer3 Mon Apr 10, 2023 8:31 pm

Can you clarify what you're trying to do (and how you're planning to trigger it)?

You probably want an if clause that runs the animation when the current state is below 10, but as far as I can see at the minute, your current code will trigger at the start of the sim.

leezer3

Posts : 1978
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Animation loop problem Empty Re: Animation loop problem

Post by Rakago Mon Apr 10, 2023 8:52 pm

I'm trying to make a dirt animation that makes the train get dirtier when the time passes. When you load the train it should be clean, but after some time the dirt will start to appear.

There are 10 dirt states. I want the animation to stop at the 10th state, ie the dirtiest state.
Rakago
Rakago

Posts : 67
Join date : 2019-10-30
Age : 17
Location : Spain

https://openbveiberia.blogspot.com/

Back to top Go down

Animation loop problem Empty Re: Animation loop problem

Post by leezer3 Thu Apr 13, 2023 7:16 pm

Hmm...
To make what you've got work, I think you want the following:

Code:
if[currentState > 9, mod[quotient[time,1],10], currentState]

Minor addition however:
Code:
if[speedometer < 10, currentState, if[currentState > 9, mod[quotient[time,1],10], currentState]]

I'm not sure this will ever work especially well though.

leezer3

Posts : 1978
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Rakago likes this post

Back to top Go down

Animation loop problem Empty Re: Animation loop problem

Post by Rakago Fri Apr 14, 2023 8:27 am

Tested both codes, tried several settings but the train always starts dirty and not clean, and the animation does not cycle thourgh the dirt states... Neutral
Rakago
Rakago

Posts : 67
Join date : 2019-10-30
Age : 17
Location : Spain

https://openbveiberia.blogspot.com/

Back to top Go down

Animation loop problem Empty Re: Animation loop problem

Post by Rakago Sun Apr 23, 2023 8:12 pm

Hello!

I very slightly tweaked your code, and it works perfectly, only in Object Viewer!



Code:
StateFunction = if[currentState < 9, mod[quotient[time,1],10], currentState]


In-game it just loads the last object (dirtiest state), it does not cycle through the rest at all.

Why does this happen? Sad
Rakago
Rakago

Posts : 67
Join date : 2019-10-30
Age : 17
Location : Spain

https://openbveiberia.blogspot.com/

Back to top Go down

Animation loop problem Empty Re: Animation loop problem

Post by leezer3 Mon Apr 24, 2023 10:34 am

Fiddle, too much stuff floating around plus a typo :/
I didn't really bother to read your maths mind, which is terminally broken.

The issue in the main game will be with the time, but please read the whole explanation and go away and read up a little on some basic math.

First, you've got to remember that in OpenBVE terms, time is expressed in terms of an absolute number of seconds from midnight.

Object Viewer has no concept of time, and it's time counter starts from zero.

On the other hand, let's assume that your routefile has a first station time at an arbritary 9am.
Our in-game time counter at this point will therefore be 32400


If you look at your current code, the interesting part at 9am is therefore as follows:
mod[quotient[32400,1],10]


Decompose this a little further:
quotient[32400,1] ==> This will always evaluate to 32400 (32400 / 1 = 32400!)

Therefore, our code now looks like this:
mod[32400,10]


Decomposing this gives us the following calculation:
32400 - 10 * Floor(32400/10) ==> This evaluates to 104943600

Why then does it display the final state?
This is a 'feature' of the way the game works. Everything is loaded at midnight, and the game is then run in fast-forward mode to the start. Thus, it'll run through all the states before the first frame is loaded, and sticks at the final state.

TLDR:
Math is complex.
I would suspect that the odometer is probably a better source of the trigger number than time, which might work reasonably with your current code.

leezer3

Posts : 1978
Join date : 2011-08-23

http://www.bvecornwall.co.uk

Back to top Go down

Animation loop problem Empty Re: Animation loop problem

Post by Rakago Mon Apr 24, 2023 2:19 pm

Thanks for the reply, I really suck at maths lol Embarassed  What would be the correct code to make this work in-game?
Rakago
Rakago

Posts : 67
Join date : 2019-10-30
Age : 17
Location : Spain

https://openbveiberia.blogspot.com/

Back to top Go down

Animation loop problem Empty Re: Animation loop problem

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