Closed Ingvix closed 8 years ago
Hi @Ingvix! I'm glad to see that someone else is interested in this project - I haven't used my Jolla phone in about two years, so this project has stagnated as a result.
I haven't tried this code, but clearing the board should look something like this:
for(var row = 0; row < 9; row++) {
for(var col = 0; col < 9; col++) {
if(S.isInitialCell(row, col)) {
continue;
}
var data = getBlockForCoords(row, col);
var block = data[0];
var blockRow = data[1];
var blockCol = data[2];
block.set(blockRow, blockCol, null, false);
}
}
I'll have limited Internet access for the next few days, but please let me know if you have any more questions and I'll address them as soon as I can.
I was able to create something quite similar before, without the if part though. I tried to create it too but I didn't realize I was suppose to type "continue" instead of "return" for it to work. But I already noticed back then that it does indeed remove the numbers but the game still acts like the numbers are there. It's the same case with your code. Also the code didn't work just like that. I had to add var s = S.getSudoku(modelId);
and replaced the capital S with small s.
Now if the numbers I clear with this function have conflicts they will still appear afterwards. So they just become invisible and not disappear.
Ah, I forgot an important step: you'll need to call s.set
with the s
sudoku object you got via S.getSudoku
Ah, now it's working, thanks. So s.set is used to set the background data in place. Previously I also tried to use it alone and wondered why it didn't make changes to the board but I guess that explains it.
Now though, I wonder how does updateSelection also effect on the visual side even though it only calls s.set. Anyway, the issue is cleared now.
Whoopsie. It's not all cleared yet. I just noticed that the cleared numbers reappear on the board after closing and restarting the app.
@Ingvix The application persists the board in a database, so you'll have to figure out how to clear it there as well.
Can you give me any hint on this? I've been trying stuff looking at functions that create connection with the database but I don't even understand why won't it save the empty board but does save normally erased values.
@Ingvix You should just need to call save
on the board object after you clear everything out.
But it already does that when the app is closed, doesn't it? I tried that before too and it didn't seem to work. Here's the current function with the save function if you see something wrong with it:
function clearBoard() {
var s = S.getSudoku(modelId);
for(var row = 0; row < 9; row++) {
for(var col = 0; col < 9; col++) {
if(s.isInitialCell(row, col)) {
continue;
}
var data = getBlockForCoords(row, col);
var block = data[0];
var blockRow = data[1];
var blockCol = data[2];
block.set(blockRow, blockCol, null, false);
s.set(blockRow, blockCol, null);
}
}
clearConflicts();
save();
}
You're right that it saves upon close, so just clearing the board should work.
I see that you're calling s.set(blockRow, blockCol, null)
; I think that this should be s.set(row, col, null)
instead, since blockRow
and blockCol
are the row and column within the block.
Ah, such an obvious mistake. Now it works like a charm. Thanks for pointing it out. Now this case it finished.
I see that you aren't too actively developing this app anymore. I've started to improve it myself as I find it very nice app that shouldn't be forgotten just yet. I'm beginner with coding in general so it has been a great help with understanding QML and I've already made the UI support different screen sizes and aspect ratios and different screen orientations.
Now I'm trying to create a function that would remove all the user inserted values from the board so the player could start the same game from the start. I've tried few things but without success. Javascript just doesn't open up to me that well yet. I was wondering if you could help me with this a bit and maybe provide the function to reset the board so I could learn from it and try to develop the app even further. I have a feeling it might not be such a complicated code to create but I just haven't found the right form for it.