Page 1 of 2

Anyone ever successfully turned an engine on/off with LUA ?

Posted: Mon Jul 17, 2017 3:42 am
by chrisell
I've come across an interesting quirk - I'm trying to do a three-way rocker switch in a cab that normally sits at zero. Hold it up to start the diesel engine, hold it down to stop.
Rocker switch works fine, script can interpret its position but for the life of me I can't seem to get the damn engine to turn off.
It would seem that this:

Code: Select all

Call( "*:SetControlValue", "Startup", 0, 1 )
doesn't work. But if you flick that control with a keyboard shortcut, cab control or the HUD, it works just fine.

Anyone found a way to do this or is this yet another of the 10,000 things I'm going to have to script around?

Re: Anyone ever successfully turned an engine on/off with LUA ?

Posted: Mon Jul 17, 2017 8:17 am
by karma99
As with most controls I expect the F4 HUD is overriding it - so your call sets the value and then the HUD checks and says "Hey, that's my control and it's at 0!" so it set's it back.

If you replace "Startup" in the loco bp with "VirtualStartup" and add a new control called "Startup" then the HUD will only control a virtual version of the Startup button on the HUD, which you can read if you need to, and then you have full control of the real Startup control.

Re: Anyone ever successfully turned an engine on/off with LUA ?

Posted: Mon Jul 17, 2017 12:55 pm
by chrisell
karma99 wrote:As with most controls I expect the F4 HUD is overriding it - so your call sets the value and then the HUD checks and says "Hey, that's my control and it's at 0!" so it set's it back.

If you replace "Startup" in the loco bp with "VirtualStartup" and add a new control called "Startup" then the HUD will only control a virtual version of the Startup button on the HUD, which you can read if you need to, and then you have full control of the real Startup control.
I'll give that a try. I have a ton of other 'virtual' controls - never occurred to me that the startup control might be circumvented this way. Thanks for the tip. I'll post with what I find.

Re: Anyone ever successfully turned an engine on/off with LUA ?

Posted: Mon Jul 17, 2017 1:29 pm
by tnleeuw01
Most vR loco's have a start / stop button. It never occurred to me actually that this button might normally ONLY work to start the engine, not to stop it...!

So perhaps if you own one of them, you can have a look at how they did it? You can look at the BR101 from vR that's available on Steam, or the vR version of the BR232 that's included with the just-released Mighty Seddin Railyard (not the other, standalone BR232).

Cheers,

--Tim

Re: Anyone ever successfully turned an engine on/off with LUA ?

Posted: Mon Jul 17, 2017 11:19 pm
by chrisell
Well after 5 hours of trying, I think I'm going to call this one yet another thing I can't get around.
"VirtualStartup" works - it separates the HUD from my script, but the engine never turns off no matter what the value of "Startup" is set to. Even pushing the value of "VirtualStartup" directly to "Startup" doesn't work.

The only thing that works is allowing the HUD and keyboard shortcut to directly toggle the "Startup" value. Only then does the engine register as properly on or off with the RPM dropping to zero (for off) and idle (for on).

Any attempt to change "Startup" via LUA fails. The value temporarily goes to the value I want, but then immediately springs back to the other value.

I don't have any of the vR products. Even if I did, I couldn't see their source so it wouldn't be any good to me. I'll ping them a line and see if they're faking it or if they've found some way around the problem.

Re: Anyone ever successfully turned an engine on/off with LUA ?

Posted: Tue Jul 18, 2017 6:31 am
by tnleeuw01
I think that yesterday I might have somehow misunderstood what you were trying to do regarding toggling engine-state from a script - yet still, both the locos from vR and from DutchClassic will turn off the main switch when you overload the traction motors. After that, you have to turn the engine on again.

So I assume that they still do somehow turn off the engine from a LUA script that monitors if traction motors are overloaded, or overheated.

What is it that you are trying to achieve, for which you need to turn off the engines from a script? Something similar to overloading an engine by giving too much power too fast?

--Tim

Re: Anyone ever successfully turned an engine on/off with LUA ?

Posted: Tue Jul 18, 2017 7:31 am
by karma99
I suspect they fake it all - virtual controls to show the RPM and then override that based on the value of the VirtualStartup control.
There are very few controls or gauges I show directly to the user anymore, pretty much everything is a virtual control and then wired up under the surface with something to make it operate realistically.

We've got a whole new brake set up coming for the Large Prairies that's been quite the puzzle and overrides absolutely everything.

Re: Anyone ever successfully turned an engine on/off with LUA ?

Posted: Tue Jul 18, 2017 8:14 am
by tnleeuw01
Can you fake the engine RPM shown in the HUD rather than a gauge?

I guess you can set it to 0 even if the engine technically is "running" according to it's state in RW...

(Oh and most of these engines that I have experience with are electrics so you'll see Amps instead of RPM, but the principle remains the same I guess).

Cheers,

--Tim

Re: Anyone ever successfully turned an engine on/off with LUA ?

Posted: Tue Jul 18, 2017 10:03 am
by karma99
Yeah we did it with the GT3 Gas Turbine using "VirtualRPM". You can always have your own dials saying anything you want them to however to "hack" the HUD just put the word Virtual in front of most controls and you can separate the internal value from the UI, although it's not always a sure thing and some of them don't work.
Never try overriding the actual control as you'll just end up with a fight between the value you set and the value the internal code sets and it will just bounce around horribly somewhere in between.

Re: Anyone ever successfully turned an engine on/off with LUA ?

Posted: Tue Jul 18, 2017 12:49 pm
by chrisell
I'm already doing VirtualRPM for the revs because the geared engine doesn't work in TS so in order to get 4 distinct gears (by sound anyway), I have to do a ton of math under the hood that looks at my own calculated tractive effort, throttle position and the RPM the game wants, in order to get the smoke the way I want and to get the RPM and sound to behave as if it's a 4-speed transmission.

What I want, though, is an "all off" - everything turned off - ie. a dead engine. I can't seem to fake it though because under the hood, the game keeps the RPM at idle no matter what I do and as long as that's the case, the game still thinks the engine is on. Meaning even if I override every gauge and value with "Virtual" ones, I can sit in a cab with no audio and a dead control panel but as soon as I push the throttle, the train moves off because the game still thinks the engine is running.

I'm already faking everything else with my own control names and "Virtual" controls but this stupid three-way engine start/stop rocker switch is a giant pain in the ..

Re: Anyone ever successfully turned an engine on/off with LUA ?

Posted: Tue Jul 18, 2017 1:02 pm
by karma99
What about Virtual Throttle?.. just don't pass the value to "Regulator" when the engine is dead.

Re: Anyone ever successfully turned an engine on/off with LUA ?

Posted: Tue Jul 18, 2017 2:05 pm
by chrisell
karma99 wrote:What about Virtual Throttle?.. just don't pass the value to "Regulator" when the engine is dead.
I guess.

Every time I get into adding new stuff to my engines, I just remember how much hassle it was last time around :( It's like a constant punishment :)

Re: Anyone ever successfully turned an engine on/off with LUA ?

Posted: Tue Jul 18, 2017 2:28 pm
by tnleeuw01
Wondering how much of punishment TSW will be for content-creators...

--Tim

Re: Anyone ever successfully turned an engine on/off with LUA ?

Posted: Tue Jul 18, 2017 2:50 pm
by karma99
tnleeuw01 wrote:Wondering how much of punishment TSW will be for content-creators...

--Tim
I would expect far less to be honest as it will have been built from the ground up by people who know what is required to make it flexible - especially the project lead :wink:
TS is a bunch of hacks and updates (some of them great, some not very friendly) on top of a product that I suspect was never intended to get past the stage of it's initial release as Rail Simulator. And fair play to DTG for getting us this far. Does anyone remember when steam trains had a constant ball of smoke above the chimney when they stopped and they didn't even chuff?! As I sit here and write a whole new realistic GWR brake system that all seems like a very long time ago now :D

Re: Anyone ever successfully turned an engine on/off with LUA ?

Posted: Tue Jul 18, 2017 5:52 pm
by chrisell
tnleeuw01 wrote:Wondering how much of punishment TSW will be for content-creators...

--Tim
Well having seen their simugraph demonstrations, I'd say that's probably the reason there IS no 3rd party support right now. The modelling side of it won't be too bad - use things like Substance Painter to get better textures and materials etc. But what's going to be a huge pain is having all the geometry present at once - inside, and outside. One saving grace (in my opinion) of TS is that the cabview, passenger view and outside view are all different geometries (well they are if you want any sort of performance).
Having to have all those piled into a single model is going to make maintenance and updates pretty nightmarish. That's before we even get to simugraph.