Page 2 of 3
Re: The DVT discussion thread
Posted: Sat Jun 04, 2011 10:10 pm
by Irishrailguy
Kariban wrote:
Put BeginUpdate at the bottom of Initialise. Update runs when you're driving the vehicle I think, but not when the AI is unless you tell it to. Initialise is only run once when the script starts, so it sets your panto to 0 and then never touches it.
The 91 isn't set up yet, so I'd just like to test the concept of 'disabling' the pantograph. If I wanted to get it to run without ending, could I put it in a while loop? Does everything have to start with a function, because if I'd have to contain it in Initialise() I'd end up in the same situation.
:EDIT:
I've tried this 'while' loop, there's an Initialise() inside the block of code and PantographControl is already preset to 0, yet I can still use the pantograph. I thought that since Initialise() is inside the loop it will continue to run through it even though Initialise() only does it once. But this doesn't seem to work
Code: Select all
while Call("*:GetControlValue", "PantographControl", 0) == 0 do
function Initialise()
if (Call("*:GetControlValue", "PantographControl", 0) ==0) then
Call("*:SetControlValue", "PantographControl", 0, 0);
end
end
end
Re: The DVT discussion thread
Posted: Sat Jun 04, 2011 10:44 pm
by Kariban
You can't use loops that probably won't end in a hurry in realtime applications, you'll jam it solid - Update() is running in a loop. What you are trying to do is trap anything that is likely to make it do something you don't want it to do, and stop it before it does anything ( which is why I put that snippet in with OnControlValueChange ). Note that I didn't ever set isConnectedToA91 to true.
Let's do a little logic for virtual controls in slightly LUA-esque pseudo-code
Controllers defined in the blueprint
Panto = down ( this is the actual pantograph control )
VPant = down ( this is the interface that controls the pantograph, ie the P key and the panto button, any cab button and the consist message interface )
Variables
91connected = false
Code: Select all
Logic flow:
if VPant is up then ( an attempt to put the pantograph up )
if 91connected is true then
set Panto to up
end
end
You can turn that into LUA & put it in Update(), or you can take the logic and make it event-driven in OnControlValueChange. The game pantograph - and associated turning-on-of-power - won't move until your condition is fulfilled. I much prefer this approach to forcing an override on the game engine.
Re: The DVT discussion thread
Posted: Sun Jun 05, 2011 7:50 pm
by Irishrailguy
Thanks, I get what your'e going for there, so I tried it and what I came up with was this:
Code: Select all
function OnControlValueChange ( name, index, value )
if Call( "*:ControlExists", name, index ) then
Call( "*:SetControlValue", name, index, value );
end
end
function Initialise()
Call("*:SetControlValue", "TrainBrakeControl", 0, 0.75);
Call("*:SetControlValue", "SimpleChangeDirection", 0, 1);
Call("*:SetControlValue", "Reverser", 0, 0);
Call("*:SetControlValue", "PantographControl", 0, 0);
end
function Update(inteval)
end
if "PantographControl" == 0 and Call("*:OnControlValueChange","PantographControl", 0, 1) then
if (Call("*:OnConsistMessage", 0091, class, 1) == true) then
Call("*:SetControlValue", "Pantograph|Control", 0, 1);
end
end
function BeginUpdate()
end
This doesn't work either, I don't know why it won't, it seems to make sense to me, I've even tried it with an else statement after saying
Call("*:SetControlValue", "Pantograph|Control", 0, 0). I thought that if there is both options stated surely I must get a result? I've probably done something wrong
Re: The DVT discussion thread
Posted: Mon Jun 06, 2011 1:26 am
by Kariban
Yes, your code isn't inside a function for starters. OnConsistMessage is a pre-existing name for a script event handler ( like OnControlValueChange ) so you don't call it like that. I would go study some existing engine scripts for a bit to give you an idea of how it all works - one of DaveB's creations, or try my HST brake mod because it's quite simple.
Re: The DVT discussion thread
Posted: Mon Jun 06, 2011 10:59 am
by Irishrailguy
Thanks Kariban, I changed around the function type and with this:
Code: Select all
function OnControlValueChange ( name, index, value )
if (Call("*:OnControlValueChange", "PantographControl", 0) == 1) then
Call("*:SetControlValue", "PantographControl", 0, 0);
end
end
and it actually works! I know it doesn't take a message ID into account but I can now work on that. I noticed that the only function that loops itself in most engine scripts is OnControlValueChange, since it's the one every script has to update it's controls:
Code: Select all
function OnControlValueChange ( name, index, value )
if Call( "*:ControlExists", name, index ) then
Call( "*:SetControlValue", name, index, value );
end
end
So I'll get back to the thread once I get the rest of the controls sorted

Re: The DVT discussion thread
Posted: Mon Jun 06, 2011 11:05 am
by Kariban
Er, OnControlValueChange
isn't a call, it's a pre-defined function. What happens is that the game calls it when there is a change in a control value ( as the name says ), you don't usually call it yourself. Sticking it in Call() does nothing at all. What you actually want is
Code: Select all
function OnControlValueChange ( name, index, value )
if name == "PantographControl" and value == 1 then
Call("*:SetControlValue", "PantographControl", 0, 0);
end
end
simple as that. However I'm really not sure how effective that will be.
Re: The DVT discussion thread
Posted: Mon Jun 06, 2011 11:15 am
by Irishrailguy
Ok, yes I've tested this and I realised that none of my controls work

I've forgotten that it can only be used once(or can it not?), looks like I'm back to square one

Oh well I'll give what you suggested a try, I knew it seemed too easy
:EDIT:
It seems that if I use OnConrolValueChange twice in a script the update control function at the start doesn't work anymore (No controls move) Is there any way to fix this?
Re: The DVT discussion thread
Posted: Mon Jun 06, 2011 11:22 am
by Kariban
Add Call( "*:SetControlValue", name, index, value ) to the bottom of the function ( before the last end ).
Re: The DVT discussion thread
Posted: Mon Jun 06, 2011 11:26 am
by Irishrailguy
Sorry for that last edit, it takes me ages to type stuff up, I'll give it a shot thanks
:EDIT:
This is what I've got now:
Code: Select all
function OnControlValueChange ( name, index, value )
if name == "PantographControl" and value == 1 then
Call("*:SetControlValue", "PantographControl", 0, 0);
end
Call( "*:SetControlValue", name, index, value)
end
Is this right? It fixes the first problem but the pantograph works again

Re: The DVT discussion thread
Posted: Mon Jun 06, 2011 1:03 pm
by Kariban
Hmm, yes, it would. Not sure if LUA will let you set the value of parameters, so try this instead.
Code: Select all
function OnControlValueChange ( name, index, value )
if name == "PantographControl" and value == 1 then
Call("*:SetControlValue", "PantographControl", 0, 0)
return
end
Call( "*:SetControlValue", name, index, value)
end
Re: The DVT discussion thread
Posted: Mon Jun 06, 2011 2:02 pm
by Irishrailguy
Ok, that made a difference, for some reason if I activate the pantograph the f4 display says its turned on for about a second and then turns off, yet for some reason I can still move the dvt

But if I do this:
Code: Select all
function OnControlValueChange ( name, index, value )
if name == "TrainBrakeControl" and value < 0.75 then
Call("*:SetControlValue", "TrainBrakeControl", 0, .75)
return
end
Call( "*:SetControlValue", name, index, value)
end
the brake is locked below 0.75, so this works nicely for any lever, but there seems to be an issue with using this on push buttons,
Thanks for the code, I'm making progress now!

Re: The DVT discussion thread
Posted: Mon Jun 06, 2011 2:09 pm
by Kariban
Er, if you do that you'll never ever be able to take the brake off

it will reset the brakes EVERY time, rather than when you start. The set-the-brakes bit needs to go in Initialise()
Re: The DVT discussion thread
Posted: Mon Jun 06, 2011 10:05 pm
by Irishrailguy
Ok, I've now come to the point where I want to lock the brakes unless I get a consist message , in this case from a class 67, with a id of 1711, I can't seem to put the lock brakes code in another if statement and get it to work, here's the code I'm using, whatever problem is with it must be excused since I've hit a mindblock from working at it all day
Code: Select all
function OnControlValueChange ( name, index, value)
if name == "TrainBrakeControl" and value < 0.85 then
if (Call("*:OnConsistMessage", 1711, argument, direction) == true) then
function Initialise()
Call("*:SetControlValue", "TrainBrakeControl", 0, 0.85)
end
elseif (Call("*:OnConsistMessage", 1711, argument, direction) == false) then
Call("*:SetControlValue", "TrainBrakeControl", 0, 0.85)
return
end
end
Call("*:SetControlValue", name, index, value)
end
Re: The DVT discussion thread
Posted: Tue Jun 07, 2011 1:33 am
by Kariban
OnConsistMessage is another built-in function just like OnControlValueChange; the insides will look much the same. It is not something to use with Call. Once again, best look at some examples first ( and by that I mean go and dig up one of DaveB's scripts, or my HST one ).
Re: The DVT discussion thread
Posted: Tue Jun 07, 2011 1:16 pm
by Irishrailguy
Ok thanks for the tips, I'll have a look around.