SimHub EasyScript

Apps SimHub EasyScript 2.0.0

Login or Register an account to download this content
TheLichten submitted a new resource:

SimHub EasyScript - Use SimHub's Ncalc/JScript Engine to create Events, Properties and do Logging

Create Custom Events, Properties and do Logging, configured through the UI, using SimHub's built in NCalc/JScript engine.

SimHub is required for this plugin to work: Download

Current Features
  • Events
    • Write a NCalc/JScript expresion as condition
    • Set the Update Rate for how often the condition should be checked
    • Set if the event should trigger when the condition goes from false to true (Rising), true to...

Read more about this resource...
 
Is the output of a property available to be called in another Javascript calculation? Do you have any code examples of how you might use the script? Thanks
I should add, I find myself repeating code in slightly different functions which is not efficient, or easy to maintain. an example is average lap time for which I have a nice script. I need to use it again tho for remaining time based on Fuel left.
 
Last edited:
Is the output of a property available to be called in another Javascript calculation? Do you have any code examples of how you might use the script? Thanks
I should add, I find myself repeating code in slightly different functions which is not efficient, or easy to maintain. an example is average lap time for which I have a nice script. I need to use it again tho for remaining time based on Fuel left.
Yes, you can like with every other property, and you find it like you would when implementing it into a dashboard.

It may not matter for your average laptime, but there is the consideration of order of execution, because if whatever uses the value runs before what sets the value you will use out of date data (or even have a null on the first run).
The order is the order in which they were created (aka the order in the list inside of EasyScript), with all Events running before Propertys, with Logging only running when SimHub triggers it with an event (logging runs async, so even when called by an EasyScript event, it should execute before propertys update, but could after).
And then comes in Async aka Parallel Execution and Update Skip, which can mess with the order. This also throws up the question how the jscript engine handles the values of propertys changing mid execution of a script, obviously everything in a variable will stay the same, but if you call $prop again, could you get a different value.
The only guarantee is that Script should run prior to DashStudio, aka your dashboard, but with Parallel Execution that is not a guarantee either.
Now, our scripts execute at 60 times a second, even with some update skip this is at 4 to 20 times, if it reads an old value (or even a null) it ain't a big deal, the next update for a newer value is there before we notice. Heck, I have been debugging how simhub handles when you cross Start Finish, and for a couple of update cycles your trackpos value reads you as being at the beginning of the lap, while the lap counter has not iterated up, as it is waiting for the game to report the laptime, while this is happening your leaderboard position in a race will jump to a lap down, making you scored in the wrong position, which you may or may not have noticed.

tl;dr: When you reference another property from EasyScript, or frankly SimHub, your data maybe out of date, but that is probably fine with how fast we update.
 
Thanks for your reply.
I'm still at a loss, maybe you can explain like I'm 5...
I see a use case for me to plot the power of AMS2 cars.
for that I'd like to use the logging feature.
I have an Easy script event "test"
Property "testing"
logging "test1"
In dash studio, the only one of those I can see is property "testing"
My event is a simple counter, I'm logging rpm and torque.
when I run a replay I'm expecting the event to trigger as it's rising, and for that event to trigger a log, I do not get any output.
Is there something I'm missing in the flow of how Easyscript works?
Thanks RR
 
Last edited:
In dash studio, the only one of those I can see is property "testing"
DashStudio only shows and uses Properties, same for Available Properties.
This is because properties contain values, that you can then display verbatum, or within a formula to determine if something should be shown or where.

Events are triggers, that can be matched to Actions.
DashStudio has Actions, such as NextScreen, which makes the dashboard go to the next dashboard page, while SimHubs DataCor ships with NewLap, Flag_Yellow, etc.
EasyScripts Events are Events (duh), but Logging is an Action.

To map Events to Actions go to "Controls and events" (Keyboard icon) and go into the Events tab. There create a new binding for Source test and Target test1. You can also use this screen to try if your logging function works and logs to the correct place by pressing "Trigger Action Now".




Now, come to think of it, with your application of logging car performance data through the logging action we might have a problem with file access.
Short version: When the Event triggers SimHub forwards the function call to the logging action, which goes and launches itself async. The async function then runs the script, and takes the output and calls System.IO.File.AppendAllText(file, text); to write the data into the file. How precisely it works is unknown, it will however likely open (or try to open) a handle on the file, then write the data into the file and then close the handle.
Now, the issue is with async is that we don't know if the previous operation has finished, and you can't open a filehandle when one is already open, which would throw an exception.

We can check by going in SimHub to logging (if you don't see it make sure to select "Show logging tab" within SimHub Setting, General tab, General Section).
If you see the error "EasyScript: Exception thrown when trying to log to file", then your trigger rate should be decreased, and I maybe should look into doing something about this.

I am probably overthinking this, again
 
Brilliant plugin but it looks like it is not compatible with latest Simhub versions any longer. When I press "Edit Connection" button nothing happens. I Simhub's logs I find this error message:

[2023-09-18 10:17:19,945] ERROR - Unhandled dispatcher errorSystem.MissingMethodException: Method not found: 'Void SimHub.Plugins.UI.SHDialogContentBase.ShowDialog(System.Windows.DependencyObject, System.Action)'.
at Easy_Script.UI.View.ListEditor.BtnEdit_Click(Object sender, RoutedEventArgs e)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
...
 
Brilliant plugin but it looks like it is not compatible with latest Simhub versions any longer. When I press "Edit Connection" button nothing happens. I Simhub's logs I find this error message:

[2023-09-18 10:17:19,945] ERROR - Unhandled dispatcher errorSystem.MissingMethodException: Method not found: 'Void SimHub.Plugins.UI.SHDialogContentBase.ShowDialog(System.Windows.DependencyObject, System.Action)'.
at Easy_Script.UI.View.ListEditor.BtnEdit_Click(Object sender, RoutedEventArgs e)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
...
I have been aware of this issue for a week, I added yesterday at the top of the download page an addendum that it does not work current (you must have missed that).

I am sorry, I should have done testing on the pre release versions, then I would have easily caught that w0tever changed the Editing Dialog that I use too. But I just have not found the time, I should have this and the update to SimHubOBS done in the next few days.
 
Back
Top