Running code to restore DOM element states and variables (ie. save and load) of a game causes some elements to stop updating when gameloop iterates

This is a very complicated issue to explain.

Nutshell version of flow:

  • Call a function to save game state
  • Refresh browser to reset all code in game
  • Call a function to load game state
  • Game is restored correctly, except 3 elements no longer update in the browser when calling the next animation frame, even though if you console.log() the elements, the actual values for the elements on that particular game loop iteration are set and correct.

Best checked by cloning repo at https://github.com/leighhobson89/ChipshopChopper as this issue involves lots of functions (all stated below) and all appears to be working until you load a game and see the issue. I have a video I can upload if someone can tell me the best place to upload it, showing how to reproduce the issue.

Steps To Reproduce Scenario (video will show this if requested and place to upload given)

  • Start Game
  • Click give $10000 (a debug button I set up)
  • Click new game
  • Click all bottom row buttons except Start Shift
  • Click Improve Fryer cap. once
  • Click all auto buyers on second row once (this will make the elements below appear on screen)
  • Click “Start Shift”
  • Click “Buy Investment Fund” (this will make the buttons change to the ones below)
  • Increment the cash and risk values and see the reflection in the table
  • Now click Menu and Save game
  • Now Refresh browser
  • Now Load game back
  • Now see everything is fine and restored, but problem 1) the buttons wont increment and the investment money is not going up anymore
  • In Dev Tools, observe the console spitting out the correct value of element with id investmentDataScreenBottomRowColumn3 but problem 2) the DOM not updating it

Elements in question in the DOM having issues with after loading have ids of:

investmentCashComponent (buttons not triggering event handler so nothing happening only after loading, and are the following 2 children of this element):
investmentCashComponent_IncrementButton
investmentCashComponent_DecrementButton

investmentRiskComponent (buttons not triggering event handler so nothing happening only after loading, and are the following 2 children of this element):
investmentRiskComponent_IncrementButton
investmentRiskComponent_DecrementButton

investmentDataScreen (data fields not updating in DOM per animation frame for the children listed below, but if you console out the whole element the data is correct in the console, again only after loading.)
investmentDataScreenBottomRowColumn1
investmentDataScreenBottomRowColumn2
investmentDataScreenBottomRowColumn3

Following functions are those that handle the saving and loading process:

ui.js

createGameWindow() - last part of this function calls functions to set up click event handlers for buttons

actions.js

saveGame() //converts object into JSON and saves to a text file
loadGame() //reads the JSON and sub functions set the variables etc back
handleFileSelect()

constantsAndGlobalVars.js

captureGameStatusForSaving() //reads all variables and DOM element values except buttons into an object
captureButtonStates() //adds all button states, classes, values to the object.
restoreGameStatus()
restoreButtonStates()
  • Console outputs to validate the elements are being set with their correct values which they are.
  • Reinitialising event handlers after loading the game
  • Checking elements all have same css classes before and after load and none are disabled.

Feel free to give feedback on a better way to ask this question rather than downvoting if thats what you are thinking, as I dont know how to express such an interwoven set of functions in a minimalised way, I have explained what things I have tried, and it just doesnt make sense to me why the buttons arent working and the data not updating ONLY in the UI but the elements do have the correct data when console.log(element) is called in the dev tools.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật