The online racing simulator
#1 - FL!P
Forcing the custom view to reload from a script [solved - W29]
Sorry, this is a bit difficult to explain and English isn't my mother tongue, but I'll do my best.

I'm planning to release a suite of scripts that allows to save and use several different sets of custom views, and cycle through them from a single command. Basically it works by having several views folders and an executable renaming them to change the active one. This exe is called from LFS scripts via the /exec command.

If I run the suite while I'm using the cockpit view, for example, the next time I press V to switch to the custom view, the custom view will load with the new settings as expected. If I run it while I'm using the custom view, I'll have to press V and SHIFT+V (or vice-versa) to reload the custom view and see the changes. This makes perfect sense to me.

But since this isn't very user friendly, I'm trying to do this press V & press SHIFT+V from a LFS script, so the custom view would reload automatically. And this is where the problem is.

If I end my script with "/press v" the view changes as expected (for example from custom view to chase view). But if I end my script with

/press v
/shift v

... nothing happens and I still have to press V and SHIFT+V by hand to see the changes. I suppose the second simulated key press occurs too soon after the first one and LFS somehow ignores them. I tried to run press v first, then my exe, and then only shift v, and it makes no difference.

But there's more, and this is where it gets puzzling: if I display the custom view and call my suite repeatedly, then the custom view reloads the second and the subsequent times and everything seems to work perfectly. But in fact it does not work as expected: it doesn't display the custom view from the set that was just activated, but from the previous one. Again, it's only when I press V and SHIFT+V by hand that the custom view will be displayed with the settings from the current views folder. So the press v & shift v sequence seems to take effect only the next time I trigger my script. I have no idea why.

Any suggestion to work around this problem and force the custom view to reload immediately? Maybe I should post a feature request for a script command to reload the custom view?
#2 - FL!P
I think I know why this is happening: I suspect that by the time the LFS's script reaches the /press v /shift v statements, the exe isn't done running yet. The behavior I see would make perfect sense, in this case.

I can think of two ways to fix this problem (none of which is implemented yet, unfortunately):

1. When it launches an exe, LFS could wait for a reply from it (maybe optionally) and resume the execution of the script only when it has received it, or

2. LFS could provide a /pause command (taking a number of seconds or a number of ticks as parameter).

Scawen: I remember you said somewhere that you were planning to add a pause command. Any chance to get it in the next official update? That would be great.
I guess the reload wont happen automatically because LFS isnt monitoring the data/views folder for any changes. So when the files get replaced. LFS has no clue this has happened. Since you are already calling a script it would be a waste of processing to monitor folders for external changes. You do need to find a way to call the change view command AFTER the files have been moved.

BTW : There might be a better way than calling /press v /shift v

Have you tried the command: /view custom to switch to the Custom view. LFS MAY not check what the current view is and therefore RELOAD THE WHOLE view from disk.

(format: /view [fol/heli/cam/driver/custom])

But this wont solve the lag from the file copying issue. I've have also found instances where a wait or pause would have helped in scripts.

perhapse you couild force a wait by Perhapse spamming some text over multiple times.. say 50 eg:
/echo .....................................
/echo .....................................
/echo .....................................
/echo .....................................
/echo .....................................
/echo .....................................
/echo .....................................
etc...
etc...
/view custom

(thats if view custom works)

Or Maybe a great many commands in the script might slow it down during the file copy process.
/view custom
/view custom
/view custom
/view custom
.
.
50 or 100 times

--------------------
If you get stuck and really desperate, you could try to make the batch file only copy the view files only every second time it executes instead of everytime, meaning you could run the script twice safely. Once to change views files, and once more the make the current view change. But this is a horrid way to make it work.

--------------------
And heres a tip. When you do manage to get this working, call the script v.lfs so that you only need to type //v to run it. Helpfull if you must run it twice to make it work.
#4 - FL!P
Thanks for your reply and suggestions, mate!

Quote from JasonJ :I guess the reload wont happen automatically because LFS isnt monitoring the data/views folder for any changes. So when the files get replaced. LFS has no clue this has happened.

Yes, as I said you have to switch views for the changes to be visible. Obviously LFS reads the cvw files each time you switch to the custom view. Hence my attempt to run /press v /shift v.

Quote :You do need to find a way to call the change view command AFTER the files have been moved.

Exactly.

Quote :BTW : There might be a better way than calling /press v /shift v

Have you tried the command: /view custom to switch to the Custom view.

I'll try it. I searched for something like that, but somehow I missed it in the commands file.

Quote :
But this wont solve the lag from the file copying issue. I've have also found instances where a wait or pause would have helped in scripts.

perhapse you couild force a wait by Perhapse spamming some text over multiple times.. say 50 eg:

Yes, I've considered that possibility, but if it works, that would be my last resort.

Thanks again.
A quick test in the debugger shows me that /view custom does load the cvw file again.

So... does that mean the problem is solved?

Oh... I guess not, because you are running from a script and your program will not have finished before LFS has already reloaded the view, so you still need some kind of pause or wait.

EDIT : It looks like I can easily make LFS wait until the called program is finished. So how about a new command, just like /exec, but /wait which runs a program and hangs until that program is finished (aka synchronous spawn).
#6 - FL!P
Thanks a lot for checking this, Scawen!

You're right, it doesn't solve the problem with the exe not being done running yet when the view is reloaded. So yes, it'd be great to have a pause or wait command.
OK, it's done, a new command /wait - it's the same as /exec but... waits

Note : LFS just hangs completely untill the called exe is finished. So this is only for really quick external programs.

If that's a bad name for any reason let me know. I don't think I'll want that name for anything else as I've probably use /pause to make a script pause (in future).
#8 - FL!P
Quote from Scawen :OK, it's done, a new command /wait - it's the same as /exec but... waits

Wow, brilliant, thanks a lot! Can't /wait to try it!

It would be better to only hang the script, obviously, but I guess that will have to wait for the implementation of the /pause command. So in the meantime, I'm sure this will do the job well enough. Thanks again!
#10 - FL!P
Thank you, Scawen! It works great!
Someone buy this man a drink........... WOW
#12 - FL!P
FlipCams 1.0b1
I'm releasing the first beta version of FlipCams, a new addon for LFS that allows to save and use five different custom views per car, and cycle through them by pressing CTRL+F11 and CTRL+F12.

W29 is required, so I won't advertise FlipCams yet in the Unofficial Addons subforum. But you can get it from my team's site.

Please let me know if you run into any issue with it. I hope you'll enjoy it!

Thanks again to Scawen for having implemented the /wait command that fast when I needed it!
Tried it out and it works great.
Top job FL!P and nice work from Scawen putting in the /wait feature so you could make this

I'll be using this alot I think.

Thanks and keep up the good work

[EDIT] Btw, Maybe you should create a thread in unofficial addons to promote your mod a bit more
#14 - Jakg
In his original post he said he will - but only once W29 goes official, as it wont work without it and Scawen has not realeased W29 properly yet anyway
#15 - FL!P
Quote from alco64 :Tried it out and it works great.

Good news, thank you!

May I ask you if you have AutoHotkey installed on your machine? It's supposed to work without it, but I'd like it confirmed.

Update: I'd also like to know which version of the OS you're running, if you don't mind. Thank you.
Quote from FL!P :Good news, thank you!

May I ask you if you have AutoHotkey installed on your machine? It's supposed to work without it, but I'd like it confirmed.

Update: I'd also like to know which version of the OS you're running, if you don't mind. Thank you.

Hey,
I don't have autohotkey installed.
And i'm using Windows XP Pro SP2.
Hope this helps you
#17 - FL!P
Definitely, thanks!
#18 - FL!P
FlipCams 1.0b2
FlipCams 1.0b2 is out and now comes with an installer that takes care of everything.

You can get it from the top message of this thread on R4R's forum.

FGED GREDG RDFGDR GSFDG