leezer3 / OpenBVE

OpenBVE- A free train simulator
http://www.openbve-project.net
278 stars 52 forks source link

Problems with If statements #574

Closed RetentiveGOAT closed 3 years ago

RetentiveGOAT commented 3 years ago

Description

Whenever I try to code an if statement that pertains to something triggering when the train is placed in one of the reverser notches, the object state refuses to show up. the string of code in question is: StateFunction=If[Cars<1|ReverserNotch>0,0,1]

Reproduction

Coding an object state such as headlights in this format: [Object] Position = -0.73, 1.66, 11.06 States = glow_white.b3d StateFunction=If[Cars<1|ReverserNotch>0,0,1] but when the train is put in any of the reverser notches besides neutral, the object state refuses to show up

Train

This code can be found in the R46 subway car for openBVE as well as the new R62 subway car for openBVE. The R46 can be found here: https://bvestation.com/download/17 While the R62 can be found on this page: https://www.thebveinitiative.org/downloads

Logs

openBVE Log: 1/15/2021 2:44:53 PM

14:44:54 Using openGL 3.0 (new) renderer 14:44:54 Initialising game window of size 1200 x 1010 14:44:54 Game window initialised successfully. 14:44:54 Loading route file: D:\Documents\openbve content\UserData\LegacyContent\Railway\Route\Miscellaneous Routes\OB NYCT Sigs Demo.csv 14:44:54 INFO: Route file hash 44D963269A68ED5DD70032E5B3E51418E162B14A6179996D89DF4C22C02EDB82 14:44:54 D:\Documents\openbve content\UserData\LegacyContent\Railway : Railway folder found. 14:44:54 Route file format is: CSV 14:44:55 Route file loaded successfully. 14:44:55 Loading AI train: D:\Documents\openbve content\UserData\LegacyContent\Train\WIP trains\R46 by CoronaYards\R46 4 Car (2020) 14:44:55 Loading sound.cfg file: D:\Documents\openbve content\UserData\LegacyContent\Train\WIP trains\R46 by CoronaYards\R46 4 Car (2020)\sound.cfg 14:44:56 Loading player train: D:\Documents\openbve content\UserData\LegacyContent\Train\WIP trains\R46 by CoronaYards\R46 4 Car (2020) 14:44:56 Loading sound.cfg file: D:\Documents\openbve content\UserData\LegacyContent\Train\WIP trains\R46 by CoronaYards\R46 4 Car (2020)\sound.cfg 14:44:56 Loading train panel: D:\Documents\openbve content\UserData\LegacyContent\Train\WIP trains\R46 by CoronaYards\R46 4 Car (2020)\panel2.cfg 14:44:56 Train panel loaded sucessfully. 14:44:56 Loading train plugin: D:\Documents\openbve content\UserData\LegacyContent\Train\WIP trains\R46 by CoronaYards\R46 4 Car (2020)\os_Ats1.dll 14:44:56 Train plugin loaded successfully.

Related information

leezer3 commented 3 years ago

This appears to be working correctly to me, so I think you've misunderstood the way this works somewhere. (Object viewer doesn't, but that's a different problem entirely and unrelated)

Cars < 1 | ReverserNotch > 0

This will return true (0) in the following situations:

Looking into the R62, the reason your headlights aren't showing is that it's also checking for PluginState 99 If I remove this condition, it works.

RetentiveGOAT commented 3 years ago

I tried changing the syntax, and removing pluginstate 99 for both trains, and still no dice. I wonder what I could be doing wrong in this scenario?

leezer3 commented 3 years ago

Not sure .

Try replacing the headlight object with something else (large cube or something?) & see if you can see that.

I'll take a look at the object itself later.

RetentiveGOAT commented 3 years ago

Replaced the object, still no dice. The train works fine in older versions of OpenBVE

leezer3 commented 3 years ago

Done some more investigating, and I've figured out some things & confused others....

Your root cause is the following: https://github.com/leezer3/OpenBVE/commit/469d85dfe865230be4ddf53c567c150fa4d70872

Now the trouble is that a Vector3 multiplied by a Matrix4 is as I've now figured out after a bunch of headscratching an undefined operation, as opposed to simply incorrect which was my initial assumption :/

Some formats expect the W component to be ignored (in other words effectively multiplying the Vector3 by a 3x3 matrix), but others expect a constant W component. In practice, this led to rounding errors with small half-distance glows.....