Jump to content



Photo
- - - - -

Help with table options menu.


  • Please log in to reply
4 replies to this topic

#1 sliderpoint

sliderpoint

    Pinball Fan

  • Members
  • PipPipPipPip
  • 760 posts
  • Location:Spokane, WA

  • Flag: United States of America

  • Favorite Pinball: Metallica

Posted 30 August 2015 - 06:08 PM

Hey guys I'm trying to figure out how to add more dip switches to for some table options.  I basically copied the scripts for the menu option structure from Cirqus Voltaire Platium Ed.  I've used this in the past, but I only had a couple options and it works fine. It piggy backs the default F6 dip switch menu.

 

The problem is I don't understand the "registry locations" addresses for the constants.  Here are what I did to try keep it simple.

 Const optOpenAtStart	        = &H00000001
 Const optBear			= &H00000010
 Const optFester		= &H00000100
 Const optBox			= &H00001000
 Const optCousinItt		= &H00010000
 Const optBooks			= &H00100000
 Const optBetas			= &H01000000
 Const optSwLight		= &H00000002
 Const optCVLight		= &H00000004

The first 4 work fine, but the all the last ones seem to end up causing conflicts with the first ones in someway.  Also some with show as check boxes instead of radio buttons.

 

Here is the whole section:

'REGISTERY LOCATIONS ***************************************************************************************************************************************
 
 Const optOpenAtStart	= &H00000001
 Const optBear			= &H00000010
 Const optFester		= &H00000100
 Const optBox			= &H00001000
 Const optCousinItt		= &H00010000
 Const optBooks			= &H00100000
 Const optBetas			= &H01000000
 Const optSwLight		= &H00000002
 Const optCVLight		= &H00000004

'OPTIONS MENU *********************************************************************************************************************************************

 Dim TableOptions, TableOptions2, TableName
 Private vpmShowDips1, vpmDips1, vpmDips2

 Sub InitializeOptions
	TableName="TAF_VPX"	'Replace with your descriptive table name, it will be used to save settings in VPReg.stg file
	Set vpmShowDips1 = vpmShowDips								'Reassigns vpmShowDips to vpmShowDips1 to allow usage of default dips menu
	Set vpmShowDips = GetRef("TableShowDips")					'Assigns new sub to vmpShowDips
 	TableOptions = LoadValue(TableName,"Options")				'Load saved table options
' 	TableOptions2 = LoadValue(TableName,"Options2")				'Load saved table options
	Set Controller = CreateObject("VPinMAME.Controller")		'Load vpm controller temporarily so options menu can be loaded if needed
'	If TableOptions2 = "" Then TableOptions2 = 0
	If TableOptions = "" Or optReset Then						'If no existing options, reset to default through optReset, then open Options menu
		TableOptions = DefaultOptions							'clear any existing settings and set table options to default options
		TableShowOptions
	ElseIf (TableOptions And optOpenAtStart) Then				'If Enable Next Start was selected then
		TableOptions = TableOptions - optOpenAtStart			'clear setting to avoid future executions
		TableShowOptions
	Else
		TableSetOptions
	End If
'	TableSetOptions2
	Set Controller = Nothing									'Unload vpm controller so selected controller can be loaded
 End Sub
 
 Private Sub TableShowDips
	vpmShowDips1												'Show original Dips menu
	TableShowOptions											'Show new options menu
	'TableShowOptions2											'Add more options menus...
 End Sub

 Private Sub TableShowOptions					'New options menu, additional menus can be added as well, just follow similar format and add call to TableShowDips
   Dim oldOptions : oldOptions = TableOptions
	If Not IsObject(vpmDips1) Then				'If creating an additional menus, need to declare additional vpmDips variables above (ex. vpmDips2 and TableOptions2, etc.)
		Set vpmDips1 = New cvpmDips
		With vpmDips1
			.AddForm 700, 500, "TABLE OPTIONS MENU"
			.AddFrameExtra 0,0,155,"Bear Toy",3*optBear, Array("Rug", 0*optBear, "Head", 1*optBear, "None", 2*optBear)
			.AddFrameExtra 0,65,155,"Thing Box",3*optBox, Array("Black Vinyl", 0*optBox, "Default", 1*optBox)
			.AddFrameExtra 0,120,155,"Chair Options",3*optFester, Array("with Uncle Fester", 0*optFester, "No Fester", 1*optFester)
			.AddFrameExtra 0,185,155,"Swamp Lighting", 3*SwLight, Array("Enable Green Light", 0*OptSwlight, "Disabled", 1*optSwlight)
			.AddFrameExtra 175,0,155,"Coustin Itt",3*optCousinItt, Array("Enabled", 0*optCousinItt, "Disabled", 1*optCousinItt)
			.AddFrameExtra 175,65,155,"Bookshelf",3*Books, Array("Bookcase Mod", 0*OptBooks, "Default", 1*optBooks)
			.AddFrameExtra 175,120,155,"Beta Plastics", 3*Betas, Array("Show Beta Plastics", 0*OptBetas, "No Beta Plastics", 1*optBetas)
			.AddFrameExtra 175,185,155,"Chair/Vault Lighting", 3*CVLight, Array("Enabled", 0*OptCVLight, "Disabled", 1*optCVLight)
			.AddLabel 0,240,175,30,"* Restart To Apply Settings"
			.AddChkExtra 180,240,135, Array("Enable Menu Next Start", optOpenAtStart)
		End With
	End If
	TableOptions = vpmDips1.ViewDipsExtra(TableOptions)
	SaveValue TableName,"Options",TableOptions
	TableSetOptions
 End Sub

 Dim Bear, Fester, Box, CousinItt, Books, Betas, CVLight, SwLight

 

 Sub TableSetOptions		'defines required settings before table is run
	Bear = ((TableOptions And (3*optBear))\optBear)
	Fester = ((TableOptions And (3*optFester))\optFester)
	Box = ((TableOptions And (3*optBox))\optBox)
	CousinItt = ((TableOptions And (3*optCousinItt))\optCousinItt)
	Books = ((TableOptions And (3*optBooks))\optBooks)
	Betas = ((TableOptions And (3*optBetas))\optBetas)
	CVLight = ((TableOptions And (3*optCVLight))\optCVLight)
	SwLight = ((TableOptions And (3*optSwLight))\optSwLight)
	SaveValue TableName,"Options",TableOptions
 End Sub

Any help is appreciated.

 

Thanks

-Mike



#2 Shoopity

Shoopity

    Pinball Fan

  • Members
  • PipPipPipPip
  • 691 posts
  • Location:Colorado

  • Flag: United States of America

  • Favorite Pinball: Medieval Madness

Contributor

Posted 31 August 2015 - 07:09 PM

I can only help with what I've done with AMH, which doesn't really follow how all these DIP switch things were done in the past.  I'm positive the way they've been done is much more efficient as they were done by much better coders than myself, but it seems to be a little convoluted to me.  First off, have you seen this post by Destruk?  That's what I used when trying to figure out a menu.

 

Secondly, a quick notice, in the TableShowOptions sub, for swamp lighting you have 3*SwLight instead of 3*OptSwLight. Same goes for Books, Betas, and CVLights.  Check if that's what those are supposed to be before reading any further, otherwise you might bore yourself to tears.  I'll add this, when I changed them to all be Opt..., they all showed up as Radio buttons (except the Enable Menu which is naturally a check box).

 

*****STOP READING UNLESS YOU WANT SOME BORING DETAILS ABOUT MY LIMITED UNDERSTANDING OF THE VPREG.STG FILE*****

I don't know how much you understand of how VP stores the information; I definitely don't fully understand it, especially when ROMS get involved.  But, in your code you posted, you're using all "Extra" controls, so all information, it appears, is getting stored in vpreg.stg.  And they get stored as a single number.  Since I don't know what you do and don't know, please don't get offended if I share information you already know, I'm just trying to be thorough; plus, explaining things frequently helps me find the route of the problem, even when it's information I already know, just going through it step-by-step usually makes the issue stand out.  So here goes:

 

All those dip Switch settings are getting set in the aforementioned vpreg.stg file as a single number.  You can use this file to actually view all the data that's stored in that file (and even manipulate it).  So in the code you posted, it looks like you have a table name in that file call "TAF_VPX" with a Value for this table called "Options".  This Value, called Options, contains a single number as its Data.  All that dip switch information reads from and manipulates that single number.  It does that by doing bit comparison.  Now, both Destruk's tutorial and most people use Hex numbers.  I know this is supposed to be easier, but I couldn't quite get my head wrapped around it; add to that that I already understand bit comparison and I didn't want to take the time to learn how the HEX numbers were being used, I just stayed using binary.  Here's how I understand this.

 

Let's take for example your Bear Toy Option.  Depending on what the user selects, this option will change that Options number that gets store.  So to start, to make things easy, let's say the user selects the first option for everything.  That means that Options number will be, in binary:

00000000000000000000000000000000

or just 0 in Decimal (or even 0 in Hex).  That's 32 bits which I think is what it really is (because when I was doing AMH, if I did a number greater than 32 bits it would give an overflow error).  If you looked at the number in the VPSaveEdit, you'd see 0.

 

If the player selects a Head for the Bear Toy, then that first option gets a value of &H00000010, or 16 in Decimal, or 00010000 in Binary; if the player selects None for the Bear Toy, then the value is &H00000030, or 48 in Decimal, or 00110000 in binary.  You might be wondering "But all the options have values like that," but, this is where the Mask comes in to play.  For that option, you defined the mask as 48, meaning it stores that number (either 0, 16, or 32) in that place; or mathematically speaking it multiplies the Option value by the mask amount.  Then when you load the data, you use that same Mask to retrieve the option setting.  This is where I start to lose how things were done in the past (and possibly why you're starting to have problems?).

 

First let me get into how binary comparison works, at least in VBScript (either in case you don't know, or anyone reading doesn't know).  If you AND two integers together, VBScript will AND their binary parts and spit back an integer.  For example, if you do the following:

Debug.Print (42 AND 57)

You would see 40 because AND-ing two binary numbers compares each digit and if they're both 1, it returns one:

101010 = 42

111001 = 57

So starting at the left, 1 AND 1 = 1, 0 AND 1 = 0, 1 AND 1 = 1, 0 AND 0 = 0, 1 AND 0 = 0, 0 AND 1 = 0, so:

101000 = 40

 

I personally would use each option as different bits.  So, since the Bear Toy has three options, then it can have a value of 0, 1, or 2; all the other options are either 0 or 1 (which actually makes it easier, but you could have them be as many values as you want).  Then you would set your masks, or your Registry locations to the following:

 Const optOpenAtStart		= 1	'Look at the first bit to determine the OpenAtStart option'
 Const optBear			= 6	'Look at bits 2~3 to determine the Bear Option'
 Const optFester		= 8	'Look at bit 4 to determine the Fester Option'
 Const optBox			= 16	'Bit 5'
 Const optCousinItt		= 32	'Bit 6'
 Const optBooks			= 64	'Bit 7'
 Const optBetas			= 128	'Bit 8'
 Const optSwLight		= 256	'Bit 9'
 Const optCVLight		= 512	'Bit 10'

Then change the first line of your options to:

.AddFrameExtra 0,0,155,"Bear Toy",optBear, Array("Rug", 0*2, "Head", 1*2, "None", 2*2)    'multiply by 2 because you multiply by the lowest bit value; if this were bits 5-7 then you would multiply by 16'

All the other Frames you don't have to change since they're only single bit options, 0 or 1, and the mask is only a single bit mask.

 

Then when you run your TableSetOptions routine, remove the "3*" so you'd have:

Bear = (TableOptions And optBear)

I know that's not how Destruk does it in his tutorial, I know that's not how it was done in the past.  But I also know that's what makes sense to me, and I know that's what works.

 

As far as your



#3 sliderpoint

sliderpoint

    Pinball Fan

  • Members
  • PipPipPipPip
  • 760 posts
  • Location:Spokane, WA

  • Flag: United States of America

  • Favorite Pinball: Metallica

Posted 01 September 2015 - 06:47 AM

 

 

As far as your

 

Hey Shoopity

 

Thanks for taking the time to detail this out for me!  I did not find the original link nor the tool to look at the saved values.   I'll dig in and see if I make changes to the menus as needed.  Although, I can't help but feel like you were right about to tell me how to do all the rest of it...   :tapping:

 

-Mike



#4 sliderpoint

sliderpoint

    Pinball Fan

  • Members
  • PipPipPipPip
  • 760 posts
  • Location:Spokane, WA

  • Flag: United States of America

  • Favorite Pinball: Metallica

Posted 01 September 2015 - 07:05 AM

EDIT:

 

I did set all the constants with the values you recommended and setup the array values to match.   All is working great and I have an idea of what I'm looking at now.

 

Thanks again!!



#5 Shoopity

Shoopity

    Pinball Fan

  • Members
  • PipPipPipPip
  • 691 posts
  • Location:Colorado

  • Flag: United States of America

  • Favorite Pinball: Medieval Madness

Contributor

Posted 01 September 2015 - 03:47 PM

I started to comment on the "some will show as check boxes instead of radio buttons," but before I typed it, I decided to see for myself.  When, after making sure all the "masks" were set to "opt...", everything came up as radio buttons, I stopped typing.

 

Like I said, I know using Hex values works and is probably easier to work with since you don't have to worry about converting between binary and decimal, but because my brain was trying to convert from hex to binary, it was confusing me.  And I don't like doing things I don't understand, even if it works.  So I just shared with you what I knew would work.

 

Those links are here:

The VPSaveEdit program (that let's you view all the data that's inside the vpreg.stg):

http://www.vpforums....attach_id=11315

 

Here's the link to Destruk's post on the subject:

http://www.vpforums....showtopic=16902

 

The way this forum formats links, it can be difficult to tell if text is a link (sometimes it doesn't put an underline on the clickable text and the blue text on the grey background can be difficult to distinguish that it's a clickable link).


Edited by Shoopity, 01 September 2015 - 03:47 PM.