Your very own C functions in LUA
Moderator: Moderators
-
SteelixB
- Very Active Forum Member
- Posts: 1058
- Joined: Mon Dec 10, 2001 12:00 am
- Location: Newcastle
- Contact:
Re: Your very own C functions in LUA
Besides what's already documented on the wiki, there are a few new functions that are not yet documented (although I'm sure I've seen them listed somewhere). I only do engine script scripting so what's available to engines is all I know, purely from working it out, and a lot I haven't tested.
Call("SendConsistMessage", msgId, msgStr, direction)
msgId: Unique ID for the message (e.g. class 390 currently uses 3902 as a message ID, where I increment the last number for new versions)
msgStr: String to send along the consist.
direction: Direction to send the message. 0 for backwards, 1 for forwards (I think).
function OnConsistMessage(msgId, msgStr, direction)
end
parameters as above, but this is the function that receives a message in an engine script.
Call("GetSpeed")
get the speed of engine in m/s
Call("GetAcceleration")
get acceleration of engine in m/s/s
Call("GetIsDeadEngine")
returns 1 if the engine is dead (can be set as a property like vehicle number in scenario)
Call("GetIsEngineWithKey")
not tested, but I assume this is 1 if you are driving that vehicle in a consist.
Call("GetTractiveEffort")
not tested, probably does what it says
Call("GetCurvature")
returns the curvature of the track - note that this is not relative to the vehicle, so you should only consider the absolute value this returns rather than the sign
Call("GetGradient")
not tested, probably similar to curvature
Call("GetConsistLength")
I think this gets the full consist length in metres (not the number of coaches)
Call("GetConsistTotalMass")
not tested, probably gets the consist total mass...
Call("GetTotalMass")
not tested, probably gets the mass of the vehicle that calls the function
Call("GetIsPlayer")
returns 1 if the player is driving the consist.
Call("SysCall")
no idea.
Call("setNearPosition", x, y, z)
I think this is a function, never tested it though. Not very useful in my opinion if it works.
Get, GetInitValue, Set and GetFromArray probably don't do anything. I investigated Get once, and it seemed to want "EngineIO" or "EngineSim" as a second parameter, not sure.
Call("SendConsistMessage", msgId, msgStr, direction)
msgId: Unique ID for the message (e.g. class 390 currently uses 3902 as a message ID, where I increment the last number for new versions)
msgStr: String to send along the consist.
direction: Direction to send the message. 0 for backwards, 1 for forwards (I think).
function OnConsistMessage(msgId, msgStr, direction)
end
parameters as above, but this is the function that receives a message in an engine script.
Call("GetSpeed")
get the speed of engine in m/s
Call("GetAcceleration")
get acceleration of engine in m/s/s
Call("GetIsDeadEngine")
returns 1 if the engine is dead (can be set as a property like vehicle number in scenario)
Call("GetIsEngineWithKey")
not tested, but I assume this is 1 if you are driving that vehicle in a consist.
Call("GetTractiveEffort")
not tested, probably does what it says
Call("GetCurvature")
returns the curvature of the track - note that this is not relative to the vehicle, so you should only consider the absolute value this returns rather than the sign
Call("GetGradient")
not tested, probably similar to curvature
Call("GetConsistLength")
I think this gets the full consist length in metres (not the number of coaches)
Call("GetConsistTotalMass")
not tested, probably gets the consist total mass...
Call("GetTotalMass")
not tested, probably gets the mass of the vehicle that calls the function
Call("GetIsPlayer")
returns 1 if the player is driving the consist.
Call("SysCall")
no idea.
Call("setNearPosition", x, y, z)
I think this is a function, never tested it though. Not very useful in my opinion if it works.
Get, GetInitValue, Set and GetFromArray probably don't do anything. I investigated Get once, and it seemed to want "EngineIO" or "EngineSim" as a second parameter, not sure.
New username: RSBen
Re: Your very own C functions in LUA
Excellent detective work there! I had no idea it would be possible to check if player was driving the consist. This has been most useful thread to me. Keep up the good work. Has anyone checked the new signal functions that where brought up with german update?
- AndiS
- Very Active Forum Member
- Posts: 6207
- Joined: Fri Sep 23, 2005 4:43 pm
- Location: Jester's cell in ivory tower
- Contact:
Re: Your very own C functions in LUA
Cool list! Thanks!
On use of setNearPosition I found in signals is to move around child objects the cheap way. I.e., no animation, just this system call and the origin of the object concerned is in another place. Not too useful in most cases, because most of the time, you want to switch something off and on, but consider this academic case: There is a certain signal which can bear a plate "distant will follow" if a distant follows (as opposed to this signal acting as combined main & distant signal). Now, this can be found out be communication between signals and then, this plate could be shown automatically (without bugging the route builder). But if the plate is there, the signal post must be 20 cm farther from the track than without it. This is where the setNearPosition comes in handy ...
The return value of the SendSignalMessage in signals tells you whether the message arrived at another signal. (0 vs. -1 or similar, I don't remember at the moment.) Maybe the SendConsistMessage in trains does the same, then you could use it to detect if your the last/first vehicle (sending the message back/forward will fail then).
GetCurvature could be used to beef up the guestimate of the distance to some object. But it could be a bit too complex a formula for computing it all the time.
P.S.: New signal functions were explored in May in the signalling forums. Since then, nothing cropped up, as far as I noticed.
http://forums.uktrainsim.com/viewtopic. ... 9&t=105895
On use of setNearPosition I found in signals is to move around child objects the cheap way. I.e., no animation, just this system call and the origin of the object concerned is in another place. Not too useful in most cases, because most of the time, you want to switch something off and on, but consider this academic case: There is a certain signal which can bear a plate "distant will follow" if a distant follows (as opposed to this signal acting as combined main & distant signal). Now, this can be found out be communication between signals and then, this plate could be shown automatically (without bugging the route builder). But if the plate is there, the signal post must be 20 cm farther from the track than without it. This is where the setNearPosition comes in handy ...
The return value of the SendSignalMessage in signals tells you whether the message arrived at another signal. (0 vs. -1 or similar, I don't remember at the moment.) Maybe the SendConsistMessage in trains does the same, then you could use it to detect if your the last/first vehicle (sending the message back/forward will fail then).
GetCurvature could be used to beef up the guestimate of the distance to some object. But it could be a bit too complex a formula for computing it all the time.
P.S.: New signal functions were explored in May in the signalling forums. Since then, nothing cropped up, as far as I noticed.
http://forums.uktrainsim.com/viewtopic. ... 9&t=105895
- Kitform
- Been on the forums for a while
- Posts: 209
- Joined: Thu Feb 04, 2010 4:59 pm
- Location: Skelton, Cleveland. UK
- Contact:
Re: Your very own C functions in LUA
Thanks for the list. Hopefully one day we can get a complete list of all available calls.
- karma99
- Very Active Forum Member
- Posts: 2329
- Joined: Wed Oct 17, 2007 8:21 pm
- Location: Portsmouth, UK
Re: Your very own C functions in LUA
Sorry to pull this thread back up but we don't get many about scripting functions in RW.
Is anyone aware of functions or control names we can use to get the fire mass and the water level for steam locos.
I know we can get the water gauge (boiler) value, and I know we CAN'T get the tender water level but as the water is part of the loco for tank engines is the value accesable?
Appreciate any input from the scripting gurus, thanks.
Is anyone aware of functions or control names we can use to get the fire mass and the water level for steam locos.
I know we can get the water gauge (boiler) value, and I know we CAN'T get the tender water level but as the water is part of the loco for tank engines is the value accesable?
Appreciate any input from the scripting gurus, thanks.
- AndiS
- Very Active Forum Member
- Posts: 6207
- Joined: Fri Sep 23, 2005 4:43 pm
- Location: Jester's cell in ivory tower
- Contact:
Re: Your very own C functions in LUA
I think it takes a Ben to dig in the bowls of RW for the water in the tank. The water in the boiler has controller WaterGauge. Without such a controller defined in the game core, you can just s...shelf your desires. Of course, no one (but Ben) knows whether there is a load of controllers dormant in the game code which just did not make it to the Wiki because typing is a hard job. All the values in the HUD must be "somewhere out there" but if the code lacks the lines to define them as read-only controller, there is nothing a scripter can do about them.
Re: Your very own C functions in LUA
Can someone explain meg how the set/getNearPostion function works?
I want to make resonating cab, and loco body, and these are the only functions that looks usable for this (exept the animation method like the pendolino tilting).
Other: i know that in railworks there is a minutesfrommidnight control value, and i'm curious if there a controller from where i can get the ingame season, or date.
I want to make resonating cab, and loco body, and these are the only functions that looks usable for this (exept the animation method like the pendolino tilting).
Other: i know that in railworks there is a minutesfrommidnight control value, and i'm curious if there a controller from where i can get the ingame season, or date.
My top wishes: Realistic engine physics - Superelevation - Multi-core support - Remove Physix engine, and use better one
-
SteelixB
- Very Active Forum Member
- Posts: 1058
- Joined: Mon Dec 10, 2001 12:00 am
- Location: Newcastle
- Contact:
Re: Your very own C functions in LUA
getNearPosition returns x, y and z values for the position of an entity.
example:
I don't believe it is possible to use setNearPosition to move a cab, and you can probably only use setNearPosition on child entities of an engine blueprint (as setNearPosition would affect the location on the track). However, having the loco body as a child of the engine blueprint would sacrifice all the external animations linked to control values. You would have to animate everything yourself in script.
example:
Code: Select all
--returns the coordinates of entity owning script (in the case of an engine blueprint, the coordinates of the engine):
x, y, z = Call("getNearPosition")
--returns the coordinates of a child entity called "child" (these are defined in the "container component" in the blueprint):
x, y, z = Call("child:getNearPosition")
--set the position:
Call("setNearPosition", x, y, z)
--or
Call("child:setNearPosition", x, y, z)
New username: RSBen
-
SteelixB
- Very Active Forum Member
- Posts: 1058
- Joined: Mon Dec 10, 2001 12:00 am
- Location: Newcastle
- Contact:
Re: Your very own C functions in LUA
Are you sure about this?sanyix wrote:i know that in railworks there is a minutesfrommidnight control value, and i'm curious if there a controller from where i can get the ingame season, or date.
The closest I see for this is "Minutes_Since_Midnight". I also see "Weather_Type" and "Current_Season". None of these do anything as control values though.
New username: RSBen
- Reppo
- Established Forum Member
- Posts: 308
- Joined: Sun Oct 14, 2007 5:38 pm
- Location: Santiago de Chile
Re: Your very own C functions in LUA
Hello,sanyix wrote:Can someone explain meg how the set/getNearPostion function works?
I want to make resonating cab, and loco body, and these are the only functions that looks usable for this (exept the animation method like the pendolino tilting).
If you want I can send to you a beta of my EMU so you can view the script and take some idea about how I have achieved the cab motion.
Just send to me a private message with your mail adress and I will replay it with the link to download the model.
Regards.

The man who doesn't follow his vocation betrays himself and condemns himself to unhappiness.
