@@ -164,36 +164,42 @@ function saveParticipantsAndStartSimulation() {
164164 let name = nameInput ? nameInput . value || `Master ${ index + 1 } ` : `Master ${ index + 1 } ` ;
165165 let pictureUrl = masterContainer . querySelector ( ".master-img" ) . src ;
166166
167- // ✅ Get selected servant ID and name safely
168- let servantId = "Unknown" ;
169- let servantName = "Unknown" ;
167+ // Ensure servantId and servantName are properly initialized and checked
168+ let servantId = "Unknown" ; // Default to Unknown
169+ let servantName = "Unknown" ; // Default to Unknown
170170
171171 if ( servantDropdown && servantDropdown . selectedIndex >= 0 ) {
172172 const selectedOption = servantDropdown . options [ servantDropdown . selectedIndex ] ;
173+
174+ // Safely get servantId and servantName from the selected option
173175 servantId = selectedOption . value || "Unknown" ;
174176 servantName = selectedOption . dataset . name || selectedOption . textContent || "Unknown" ;
175177 }
176178
179+ // Debugging: Log details about the servant
177180 console . log ( `Master ${ index + 1 } : ${ name } , Servant ID: ${ servantId } , Servant Name: ${ servantName } ` ) ;
178181
182+ // Create master data object with servant data
179183 let masterData = {
180184 name : name ,
181185 picture : pictureUrl ,
182186 status : "alive" ,
183187 type : "master" ,
184- servantId : servantId ,
185- servantName : servantName
188+ servantId : servantId , // Store the servant's ID
189+ servantName : servantName // Store the servant's name
186190 } ;
187191
188192 participants . push ( masterData ) ;
189193 } ) ;
190194
191195 console . log ( "Saved participants:" , participants ) ;
196+
197+ // Save participants to localStorage
192198 localStorage . setItem ( "participants" , JSON . stringify ( participants ) ) ;
193199
200+ // Redirect to the simulation page
194201 window . location . href = "simulation.html" ;
195202}
196-
197203//code to attach the above function to the button:
198204document . addEventListener ( "DOMContentLoaded" , function ( ) {
199205 const startButton = document . getElementById ( "simulation" ) ;
0 commit comments