Baseball game dev diary: V1.1.0.202012302330 Innings buttons on the fly

  1. All innings buttons (regular and extra) are now generated as the game progresses. So innings 2-9 for example do not show until these innings are started. These arrays of objects are quite complicated to set up (especially when replacing existing variables or arrays with new ones) but they make for much more efficient code. 
  2. Generating of innings buttons was done incorrectly resulting in innings of 2 or more over the starting game length not being removed correctly. Code seemed to be creating a whole new set of innings buttons with each inning that was added, instead of just the one inning worth. 
  3. Hits and runs now update in the line score (as too will errors when they are included). Per-inning runs also update in the line score buttons.  Per innings totals for hits, runs, errors, walks, runners left on (LOBs) stored in two-dimensional arrays (0,1 is team 0 inning 1 etc) with 0,0 and 1,0 being the totals, making use of what would have been an empty array space anyway. These arrays start as the length of the original number of innings  but grow if required.

Getting these hits and runs labels to update correctly has been the most frustrating experience to date. Two days of trial and error, and consulting numerous online articles, discussion forum posts, YouTube clips and rewriting code in an attempt to overcome something that seemed relatively straightforward in the beginning – updating the text in labels that are part of an array of control objects (ie Runs and Hits in the game log). Seriously, how hard could it be? Team 0 gets a hit, add 1 to Team 0’s hit count. The array variable updated! The actual text property’s value for the label itself updated! Yet it wasn’t displaying on the screen! That didn’t make any sense whatsoever – the actual text property itself changed its value yet the text on the screen did not change. I actually found some sources that seemed to confirm this was expected and there were things that I needed to code to get around it. I did notice however that whenever I closed the game log form using the X and reopened it, it magically started working correctly. So I was super confused. I tried the following:

  1. Creating whole new classes (eg hitLabel) with get/set methods (similar to how I created the player class, except these classes inherited the label class properties and had a new property called (for example) hits that would be changed to set the text property. Did nothing.
  2. Create an instance of the hitLabel and then once it’s set up, make LblHits(0) and then LblHits(1) equal to that instance (using a loop). Got this idea from a YouTube video. Still didn’t work.
  3. Removing the existing labels from the screen and adding new ones with the same name after each pitch (because theoretically a run could score on any pitch if there’s a baserunner, regardless of pitch outcome). I really did not want to do this because it is such a band-aid and is so inefficient but I was at my wits end and I figured it was the only way to get it to work. Well it didn’t. 

After two days of pulling my hair out and completely butchering my code (the game log form code now has more code commented out than there is code that actually runs) I somehow – I’m not sure how – got it working. I came to the realisation that I was calling the procedure SetupGameLog when the game log form loaded, but also calling that procedure beforehand when starting the game. This probably had the effect of creating the control objects on the screen twice. I remembered from previous experimentation with the innings buttons that new controls are added underneath existing controls, not on top.

This would explain why the label texts never updated on the form. Well they actually did, but I just couldn’t see it because they were underneath the first labels created. A key contributing factor was that I got so caught up in an article I had read that gave me the impression that what I was doing was actually not possible to do easily that it didn’t occur to me that the program’s logic was actually the problem.

Continuing on with the change log:

  1. Had enough of stuffing around with the line score controls when resetting games so I separated the line score onto its own form. Took around 10 mins. This solved a problem of trying to figure out how to reset the line score with each new game because I then only needed to run the controls.clear method on the linescore form.
  2. Removed the close button from the game log and line score forms as closing them resets the content of the textboxes. User must use checkbox to show/hide them.
  3. Added runs, hits, errors, walks, LOBs, pitches (no pitch count yet though) to end of inning text in game log.


Comments

Popular posts from this blog

MLB (Road to) The Show attribute progression

MLB The Show 21: create a stadium prediction & using created stadiums in online games

V1.1.4.202103032300 Basic player creator, line score tidy up and additional play results, including errors