Jump to content



Photo
- - - - -

Allowing local settings to override defaults in vbs scripts?

VPX vbs

  • Please log in to reply
10 replies to this topic

#1 jarr3

jarr3

    Enthusiast

  • Platinum Supporter
  • 198 posts
  • Location:Frankfurt, Germany

  • Flag: Sweden

  • Favorite Pinball: Medieval Madness

Posted 14 February 2025 - 07:01 AM

Currently it is "meant" that you change your local "vpmkeys.vbs" file to change certain defaults. (among others)

A serious problem with this is that it gets more and more complicated to do updates of the components, and that you easily can overwrite your local changes to these files on each update.

 

I am thinking on how to allow storing settings to certain variables in a local vbs file, which is only loaded when it exists. Could it be possible?

 

what if this Sub is updated like this

Private Sub LoadCore
	On Error Resume Next
	If VPBuildVersion < 0 Or Err Then
		Dim fso : Set fso = CreateObject("Scripting.FileSystemObject") : Err.Clear
		ExecuteGlobal fso.OpenTextFile("core.vbs", 1).ReadAll    : If Err Then MsgBox "Can't open ""core.vbs""" : Exit Sub
		ExecuteGlobal fso.OpenTextFile("VPMKeys.vbs", 1).ReadAll : If Err Then MsgBox "Can't open ""vpmkeys.vbs""" : Exit Sub
                ExecuteGlobal fso.OpenTextFile("LocalSettings.vbs", 1).ReadAll : If Err Then MsgBox "Can't open ""LocalSettings.vbs""" : Exit Sub
	Else
		ExecuteGlobal GetTextFile("core.vbs")    : If Err Then MsgBox "Can't open ""core.vbs"""    : Exit Sub
		ExecuteGlobal GetTextFile("VPMKeys.vbs") : If Err Then MsgBox "Can't open ""vpmkeys.vbs""" : Exit Sub
                ExecuteGlobal GetTextFile("LocalSettings.vbs") : If Err Then MsgBox "Can't open ""LocalSettings.vbs""" : Exit Sub
	End If
End Sub

can I then have LocalSettings.vbs

' Changing the defaults from VPMKeys.vbs

toggleKeyCoinDoor	 = False
inverseKeyCoinDoor = True

I have tried this concept locally, but without success; my vbs experience is still far to bad  :bye2:

 

Anyone who knows how this could be solved?

 

 

 


Edited by jarr3, 14 February 2025 - 06:39 PM.


#2 scutters

scutters

    Pinball Fan

  • Members
  • PipPipPipPip
  • 539 posts

  • Flag: England

  • Favorite Pinball: Addams Family

Posted 14 February 2025 - 02:07 PM

My guess is that effectively you're declaring the same constant names twice, once in vpmkeys and then again in localsettings, so it errors reading the duplicate in localsettings.vbs

 

If that is the case then one way around it might be to be to copy everything from vpmkeys into localsettings and then only access one of the files (i.e. localsettings if it exists, and if not then vpmkeys).

 

Something like?


		ExecuteGlobal GetTextFile("core.vbs")    : If Err Then MsgBox "Can't open ""core.vbs"""    : Exit Sub
		ExecuteGlobal GetTextFile("VPMKeys.vbs") : If Err Then MsgBox "Can't open ""vpmkeys.vbs""" : Exit Sub
                ExecuteGlobal GetTextFile("LocalSettings.vbs")
		If Err Then 
			Err.Clear
			ExecuteGlobal GetTextFile("VPMKeys.vbs")
			If Err Then 
				MsgBox "Can't open ""vpmkeys.vbs""" 
				Exit Sub
			End If
		End If

(a file named MyVPMKeys.vbs or something like that might make more sense rather than LocalSettings.vbs if you do go that way)


Edited by scutters, 14 February 2025 - 02:10 PM.


#3 jarr3

jarr3

    Enthusiast

  • Platinum Supporter
  • 198 posts
  • Location:Frankfurt, Germany

  • Flag: Sweden

  • Favorite Pinball: Medieval Madness

Posted 14 February 2025 - 03:58 PM

yes, anything logical for everyone. I want it to come into the core scripts otherwise you have more and more things you do not want to overwrite while upgrading.

 

Now I see I tried to change the value of a constant...

 

stay tuned ;)


Edited by jarr3, 14 February 2025 - 05:43 PM.


#4 scutters

scutters

    Pinball Fan

  • Members
  • PipPipPipPip
  • 539 posts

  • Flag: England

  • Favorite Pinball: Addams Family

Posted 14 February 2025 - 05:56 PM

The downside of only using LocalSettings.vbs or VPMKeys.vbs would be that if VPMKeys.vbs got updated then those changes (new entries etc) wouldn't be reflected in LocalSettings without user input to copy them across. But a change to VPMKeys is maybe unlikely?

 

If you wanted to go with your original method and just have overrides for a few set values then instead of constants you'd need to use variables (undoing https://github.com/v...304ae679cedb22b) - that way would be more resilient to any future updates to VPMKeys as only changes to the variable names used would need reflecting in the LocalSettings file.

 

Choices, choices!!!!  ;)



#5 jarr3

jarr3

    Enthusiast

  • Platinum Supporter
  • 198 posts
  • Location:Frankfurt, Germany

  • Flag: Sweden

  • Favorite Pinball: Medieval Madness

Posted 14 February 2025 - 06:29 PM

found a solution:

# WPC.vbs for example

Private Sub LoadCore
	On Error Resume Next
	If VPBuildVersion < 0 Or Err Then
		Dim fso : Set fso = CreateObject("Scripting.FileSystemObject") : Err.Clear
		ExecuteGlobal fso.OpenTextFile("core.vbs", 1).ReadAll    : If Err Then MsgBox "Can't open ""core.vbs""" : Exit Sub
		ExecuteGlobal fso.OpenTextFile("VPMKeys.vbs", 1).ReadAll : If Err Then MsgBox "Can't open ""vpmkeys.vbs""" : Exit Sub
		ExecuteGlobal fso.OpenTextFile("VPMKeysSettings.vbs", 1).ReadAll
	Else
		ExecuteGlobal GetTextFile("core.vbs")    : If Err Then MsgBox "Can't open ""core.vbs"""    : Exit Sub
		ExecuteGlobal GetTextFile("VPMKeys.vbs") : If Err Then MsgBox "Can't open ""vpmkeys.vbs""" : Exit Sub
		ExecuteGlobal GetTextFile("VPMKeysSettings.vbs")
	End If
End Sub

And then the local settings file VPMKeysSettings.vbs:

toggleKeyCoinDoor = False
inverseKeyCoinDoor = True
' keyStagedFlipperR = MyOtherKey

VPMKeys.vbs has to be changed from Const to normal variable:

Dim toggleKeyCoinDoor: toggleKeyCoinDoor	 = True ' If true then a key press/switch change will flip the state from on/off, if false then one will have the real coindoor behaviour (for cabinet setups with real coindoors)
Dim inverseKeyCoinDoor: inverseKeyCoinDoor = False ' If false then the coindoor switch behaves like a original coindoor (key pressed = closed, key not 

this way it is possible to change this values without having to change the delivered file. And it is also possible to set the keyStagedFlipperL/R variables the same way...

 

What do you think?



#6 scutters

scutters

    Pinball Fan

  • Members
  • PipPipPipPip
  • 539 posts

  • Flag: England

  • Favorite Pinball: Addams Family

Posted 14 February 2025 - 10:02 PM

That will work!

 

But... if you wanted local values for other constants they'd need changing in VPMKeys also.

 

There may be another way (untested!)...   

  • Leave the constants declared as they are in VPMKeys, and in the VPMKeysSettings (the user override file name) also declare them as constants. 
  • In VPMkeys add On Error Resume Next before all the constant declarations and a On Error Goto 0 after them.   
  • Then change the calling script to load VPMKeysSettings before VPMKeys - if a constant is already declared in VPMKeysSettings then an error occurs on the duplicate in VPMKeys when that is called, but it just resumes next and skips to the next one.

In theory anyway, might be a bit cleaner?

 

Edit - late thought but you might need an err.clear next to the on error goto 0 as well


Edited by scutters, 15 February 2025 - 09:34 AM.


#7 jarr3

jarr3

    Enthusiast

  • Platinum Supporter
  • 198 posts
  • Location:Frankfurt, Germany

  • Flag: Sweden

  • Favorite Pinball: Medieval Madness

Posted 19 February 2025 - 06:39 PM

That will work!

 

But... if you wanted local values for other constants they'd need changing in VPMKeys also.

 

There may be another way (untested!)...   

  • Leave the constants declared as they are in VPMKeys, and in the VPMKeysSettings (the user override file name) also declare them as constants. 
  • In VPMkeys add On Error Resume Next before all the constant declarations and a On Error Goto 0 after them.   
  • Then change the calling script to load VPMKeysSettings before VPMKeys - if a constant is already declared in VPMKeysSettings then an error occurs on the duplicate in VPMKeys when that is called, but it just resumes next and skips to the next one.

In theory anyway, might be a bit cleaner?

 

Edit - late thought but you might need an err.clear next to the on error goto 0 as well

 

 

I followed your proposal and pushed a test to my fork on github (in case you want to try)   https://github.com/J...uns/13419825589

 

Seem to work fine!  It ignores the if the file is missing but shows a error message pointing to the file and the vbs Err.Number in the message.



#8 scutters

scutters

    Pinball Fan

  • Members
  • PipPipPipPip
  • 539 posts

  • Flag: England

  • Favorite Pinball: Addams Family

Posted 19 February 2025 - 10:09 PM

 

That will work!

 

But... if you wanted local values for other constants they'd need changing in VPMKeys also.

 

There may be another way (untested!)...   

  • Leave the constants declared as they are in VPMKeys, and in the VPMKeysSettings (the user override file name) also declare them as constants. 
  • In VPMkeys add On Error Resume Next before all the constant declarations and a On Error Goto 0 after them.   
  • Then change the calling script to load VPMKeysSettings before VPMKeys - if a constant is already declared in VPMKeysSettings then an error occurs on the duplicate in VPMKeys when that is called, but it just resumes next and skips to the next one.

In theory anyway, might be a bit cleaner?

 

Edit - late thought but you might need an err.clear next to the on error goto 0 as well

 

 

I followed your proposal and pushed a test to my fork on github (in case you want to try)   https://github.com/J...uns/13419825589

 

Seem to work fine!  It ignores the if the file is missing but shows a error message pointing to the file and the vbs Err.Number in the message.

 

 

Nice touch with the Err.Number 53 handlingfor the vpmkeyscustom file not being found!  :tup:



#9 Mike DA Spike

Mike DA Spike

    Pinball Fan

  • Platinum Supporter
  • 1,280 posts
  • Location:Hoofddorp

  • Flag: Netherlands

  • Favorite Pinball: Too many to mention

Posted 20 February 2025 - 06:42 AM

Good catch guys!
I also need to adjust two values for my coindoor, and a VPX update necessitates modifying the vpmkeys.vbs file as well.
I hope you'll submit a PR for this, and that it will be incorporated into VPX.
:drinks:

331ddabcc742f0ba74791e946eb0f791.gif Try PinballX Database manager as a replacement of PinballX's game list manager
With special thanks to Scutters 


#10 jarr3

jarr3

    Enthusiast

  • Platinum Supporter
  • 198 posts
  • Location:Frankfurt, Germany

  • Flag: Sweden

  • Favorite Pinball: Medieval Madness

Posted 20 February 2025 - 06:57 AM

Good catch guys!
I also need to adjust two values for my coindoor, and a VPX update necessitates modifying the vpmkeys.vbs file as well.
I hope you'll submit a PR for this, and that it will be incorporated into VPX.
:drinks:

It is on it's way, it would help if you could test if it works and comment in the issue https://github.com/v...all/issues/2162

 

This is my VPMKeysCustom.vbs:

Option Explicit

Dim keyStagedFlipperL : keyStagedFlipperL = StagedLeftFlipperKey
Dim keyStagedFlipperR : keyStagedFlipperR = StagedRightFlipperKey
Const toggleKeyCoinDoor	 = False
Const inverseKeyCoinDoor = True


But I have opened a second issue https://github.com/v...all/issues/2167 which IMHO should make any changes to the flipper keys obsolete.

 

Here is an updated build:  

But as said, hopefully redundant if the second issue makes it.


Edited by jarr3, 20 February 2025 - 07:05 AM.


#11 jarr3

jarr3

    Enthusiast

  • Platinum Supporter
  • 198 posts
  • Location:Frankfurt, Germany

  • Flag: Sweden

  • Favorite Pinball: Medieval Madness

Posted 21 February 2025 - 06:55 AM

I have made a POC for my second issue here:  https://github.com/J...uns/13451431363

 

Here I have change VPMKeys to look like this:

Dim keyStagedFlipperL : keyStagedFlipperL = StagedLeftFlipperKey
Dim keyStagedFlipperR : keyStagedFlipperR = StagedRightFlipperKey

And I have changed the default of StagedLeftFlipperKey and StagedRightFlipperKey to match LeftFlipperKey RightFlipperKey

 

IMHO it would mean if you do not have any Staged flippers you leave it to the default value and all ok.

If you own staged flippers, you change the default to the keys you have programmed it to and all ok...

 

No more changing VPMKeys? And I beleive it will become easier for table writers? No more options if staged flippers or not???

 

Now I just have to test it on a couple of tables...  :db: 


Edited by jarr3, 21 February 2025 - 06:56 AM.






Also tagged with one or more of these keywords: VPX, vbs