Scripting dynamic numbers

Discuss anything related to Train Simulator from DoveTail that does not fit in one of the more specific categories.

Re: Scripting dynamic numbers

Postby deltic009 » Thu May 28, 2015 10:17 am

AndiS wrote:The additional help is roughly this:

Code: Select all
fullNumber = Call("GetRVNumber")
headcode = string.sub(fullNumber, 1, 5) -- from first character to just before the 5th
engineNumber = string.sub(fullNumber, 5) -- from 5th to the end
Call("Headcode_A:SetText", headcode, 0)
Call("Bodyside_Engine_Number:SetText", engineNumber, 0)


Hope the first part works. 8-)

I will adapt the bodyside bit because it will need to be digits 5-9 for the number and the final digit for the nameplate, but thanks very much. Where would I slot the two (well it will be three) 'Call' commands into the existing script? Sorry if I'm asking terribly simple questions.

Keen as I am to try this, for the sake of marital harmony I'd better not try such until all the kids are asleep this evening.
deltic009
Full Time Fireman
 
Posts: 62
Joined: Mon Apr 14, 2014 12:52 pm
Has thanked: 16 times
Been thanked: 34 times

Re: Scripting dynamic numbers

Postby AndiS » Thu May 28, 2015 1:29 pm

Getting characters 5-9 would be:
engineNumber = string.sub(fullNumber, 5, 10)

And the nameplate bit is this:
nameplate = string.sub(fullNumber, 10, 11)
or
nameplate = string.sub(fullNumber, 10)
if you are sure it is the last character.

The answer to "where to slot this" is "where your first tests work". I.e., experiment with the bits I posted above, trying to just get "AAAA" on Headcode_A. Once you got that, you put the full code in my previous post where you before just have the SetText commands.
AndiS
Top Link Driver!
 
Posts: 736
Joined: Wed Apr 09, 2014 5:48 pm
Has thanked: 268 times
Been thanked: 308 times

Re: Scripting dynamic numbers

Postby cjbarnes5294 » Thu May 28, 2015 2:38 pm

Just a point on string.sub, Andi:

Code: Select all
headcode = string.sub(fullNumber, 1, 5) -- from first character to just before the 5th


This would actually return the string from first character up to and including the 5th, not just before the 5th, as explained in the lua wiki. :)

string.sub(s, i [, j])

s:sub(i [,j])

Return a substring of the string passed. The substring starts at i. If the third argument j is not given, the substring will end at the end of the string. If the third argument is given, the substring ends at and includes j.

> = string.sub("Hello Lua user", 7) -- from character 7 until the end
Lua user
> = string.sub("Hello Lua user", 7, 9) -- from character 7 until and including 9
Lua
> = string.sub("Hello Lua user", -8) -- 8 from the end until the end
Lua user
> = string.sub("Hello Lua user", -8, 9) -- 8 from the end until 9 from the start
Lua
> = string.sub("Hello Lua user", -8, -6) -- 8 from the end until 6 from the end
Lua


Kind regards,
Chris
The Red Queen Hypothesis, applicable to train sim development?

"Here, you see, it takes all of the running you can do, to keep the same place."
cjbarnes5294
Driver
 
Posts: 398
Images: 82
Joined: Mon Mar 31, 2014 12:40 pm
Location: Gloucestershire/North Yorkshire
Has thanked: 551 times
Been thanked: 187 times

Re: Scripting dynamic numbers

Postby AndiS » Thu May 28, 2015 2:46 pm

:oops: :oops: :oops:
RTFM, stupid me!

I actually looked there, but was too hasty to actually digest the meaning of "until" in the definition. Too many languages with too many ways of specifying such a basic thing ...

So the above must read:

Getting characters 5-9 would be:
engineNumber = string.sub(fullNumber, 5, 9)

And the nameplate bit is this:
nameplate = string.sub(fullNumber, 10, 10)
or
nameplate = string.sub(fullNumber, 10)
if you are sure it is the last character.
AndiS
Top Link Driver!
 
Posts: 736
Joined: Wed Apr 09, 2014 5:48 pm
Has thanked: 268 times
Been thanked: 308 times

Re: Scripting dynamic numbers

Postby deltic009 » Thu May 28, 2015 11:23 pm

So then, I have some good news and some bad......

The good news is, when I go to place down my loco it very briefly flashes up the headcode 3210 (the primary number digits) before going blank. The reason it goes blank is because there are errors reported with the script from the Logmate. I shall post these below so somebody can help, hopefully, along with what I added to the script as well.

Errors:
Script Manager - Trace cScriptState.cpp : 386 = Lua Error: ...\RailVehicles\Diesel\Class55\MDP\Scripts\Class55HeadcodeEngineScript.lua:179: `end' expected (to close `function' at line 83) near `<eof>'
Content - Trace cScriptComponent.cpp : 201 = Error creating instance of script C:\Program Files (x86)\Steam\steamapps\common\RailWorks\Assets\Kuju\RailSimulator\RailVehicles\Diesel\Class55\MDP\Scripts\Class55HeadcodeEngineScript.lua

Now I am just guessing that the one of failure to create the instance of the script, is because it contains errors....

Anyway, now for what I have added to the script.

Code: Select all
fullNumber = Call("GetRVNumber")
headcode = string.sub(fullNumber, 1, 4) -- from first character to just before the 4th
engineNumber = string.sub(fullNumber, 4, 9) -- from 4th to the 9th
nameplate = string.sub(fullNumber, 10) -- 10th digit only


At the very top

Code: Select all
function Update ( time )

--Headcode and dynamic numbering/naming script.

      Call("Headcode_A:SetText", headcode, 0)
      Call("Headcode_B:SetText", headcode, 0)
      Call("Nameplate_L:SetText", nameplate, 0)
      Call("Nameplate_R:SetText", nameplate, 0)
      Call("Bodyside_Engine_Number:SetText", engineNumber, 0)
   
   
-- Check for player train.


I have added the section between function Update (time) and --Check for player train.

Thanks in advance

*NOTE - at this point I want to ask a question that may be a case of function working over good convention. If I want both headcode objects to display the same headcode at both ends, would having them share the same child object name which is referenced in the script work, or would this break things? I ask because obviously this would be the same question for the nameplates and the bodyside numbers as some have up to 4 bodyside numbers.
deltic009
Full Time Fireman
 
Posts: 62
Joined: Mon Apr 14, 2014 12:52 pm
Has thanked: 16 times
Been thanked: 34 times

Re: Scripting dynamic numbers

Postby deltic009 » Fri May 29, 2015 12:11 am

Additonal info, I tried putting just the top section into the script and this broke it in terms of starting the errors.

Thanks.

I deleted the top section and then put in this section and each individual headcode dsiplayed as asked in the static format, rather than dynamic.

Code: Select all
--Headcode and dynamic numbering/naming script.

      Call("Headcode_A:SetText", "AAAA", 0)
      Call("Headcode_B:SetText", "BBBB", 0)
deltic009
Full Time Fireman
 
Posts: 62
Joined: Mon Apr 14, 2014 12:52 pm
Has thanked: 16 times
Been thanked: 34 times

Re: Scripting dynamic numbers

Postby cjbarnes5294 » Fri May 29, 2015 12:30 am

Hi Matt,

As LogMate is having a moan about, you need to close the function with an "end":

Code: Select all
function Update ( time )

--Headcode and dynamic numbering/naming script.

      Call("Headcode_A:SetText", headcode, 0)
      Call("Headcode_B:SetText", headcode, 0)
      Call("Nameplate_L:SetText", nameplate, 0)
      Call("Nameplate_R:SetText", nameplate, 0)
      Call("Bodyside_Engine_Number:SetText", engineNumber, 0)

end


Chris
The Red Queen Hypothesis, applicable to train sim development?

"Here, you see, it takes all of the running you can do, to keep the same place."
cjbarnes5294
Driver
 
Posts: 398
Images: 82
Joined: Mon Mar 31, 2014 12:40 pm
Location: Gloucestershire/North Yorkshire
Has thanked: 551 times
Been thanked: 187 times

Re: Scripting dynamic numbers

Postby deltic009 » Fri May 29, 2015 12:49 am

Thanks Chris, it turns out I actualy had everything as it should be, but because I left all those bits at the end of the lines such as -- from first character to just before the 4th that is what was breaking it!!!!

Onwards
deltic009
Full Time Fireman
 
Posts: 62
Joined: Mon Apr 14, 2014 12:52 pm
Has thanked: 16 times
Been thanked: 34 times

Re: Scripting dynamic numbers

Postby AndiS » Fri May 29, 2015 8:32 am

Well everything from "--" to the end of the line is ignored, so that is not what you missed. But you cleared missed one "end".

Code: Select all
`end' expected (to close `function' at line 83) near `<eof>'

means that it is still looking for some "end" at the end of the file (abbreviated <eof>). It is expected to close the function starting at line 83. So just go to line 83 and from there down as far as you think the function runs and add a line containing the word end after that. It will most likely be just before the next line starting with the word function.

In doubt shown the whole script. Only then it is possible to point out missing stuff.

Having two identical child names is not a good idea. You achieve the same headcode in the script by using the same variable to set both:
Call("Headcode_A:SetText", headcode, 0)
Call("Headcode_B:SetText", headcode, 0)

So the text that is in variable headcode is shown on both independent children Headcode_A and Headcode_B.
AndiS
Top Link Driver!
 
Posts: 736
Joined: Wed Apr 09, 2014 5:48 pm
Has thanked: 268 times
Been thanked: 308 times

Re: Scripting dynamic numbers

Postby deltic009 » Tue Jun 02, 2015 1:10 am

Just wanted to quickly drop in and say thanks for all of the help. This is where I now find myself, so it is another skill I have picked up from the wonderful community once again.
2015-05-30_00001.jpg

2015-05-29_00004.jpg


I really should be getting on with the numbering and nameplates for the Headcode versions, but I have been trying to make something semi-related in Blender and encountering some minor issues. Slowly but surely, all will be revelaed with this last bit later on........

Current.jpg
deltic009
Full Time Fireman
 
Posts: 62
Joined: Mon Apr 14, 2014 12:52 pm
Has thanked: 16 times
Been thanked: 34 times

PreviousNext

Return to Train Simulator Mess Room

Who is online

Users browsing this forum: No registered users and 3 guests