|
Ok so after several days of wracking my brain, I will admit to myself that I need help. My app seems to have some strange behaviour I can't quite figure out. The code seems to work well until I call the 'restart' function using the button, to generate a new rootWord. The restart function clears the usedWords array, and clears most user scores (except 'high score'), then calls the 'startGame' function. All looks well until you play the game. If you have entered say 3 or 4 words into the game (which populate the usedWords array), and then restart the game with a button press to generate the new rootWord, it seems that any new words submitted thereafter do not show in the list view...until you have entered a suffciient quantity of words which exceeds the previous array size. This is weird, as I have (I think) cleared the contents of the usedWords array, and new words are appended at 0. Further weirdness is that I can submit the same valid word repeatedly in the restarted games only, which seems to go through the 'guard' statements and correctly get added to the userScore, but they do NOT appear in my list view until, again, the word is submitted more times than the previous array's last size. Finally, I notice that repeatedly submittng the same word over and over (in a restarted game only) will increment the score correctly, but does not reject the repeated word which has already been submitted, until it starts to appear in my list on screen. It's like the words somehow aren't getting to the usedWords array, until I have submitted several words, but ONLY when playing a restarted game! I feel like I'm going mad. I'm sure I am just being an idiot, but I cant figure out where this has gone wrong. Like I say, the game functions perfectly until I call restart to generate a new rootWord...so strange. Any help would be appreciated, but I'm also keen to understand how I can go through a debugging process to track my data and see what is 'inside' the array.
|
|
Hi, The problem is in the
it should be
|
|
Wow!!! Amazing thank you so much Hector! I was so focused on the functioning of the array, thinking i must be deleting the contents incorrectly or otherwise not handling the array properly I didn't spot that (obviously). You have no idea how grateful I am, thank you for saving my sanity! edit: now I've seen it I can't believe I missed it... |
SPONSORED Let’s face it, SwiftUI previews are limited, slow, and painful. Judo takes a different approach to building visually—think Interface Builder for SwiftUI. Build your interface in a completely visual canvas, then drag and drop into your Xcode project and wire up button clicks to custom code. Download the Mac App and start your free trial today!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.