The code I'm talking about can be found in this codesandbox.
I'm currently working on a clone of a memory game called Indefinite Interrogation. The way it works is you're asked questions; you have to always answer the same questions with the same answers. The first time you're asked each question, your answer doesn't matter; but every time you're asked that question again, you must answer with whatever you chose the first time.
What's supposed to happen in my code is that questionList (the list of questions be asked) gets updated via the getNextQuestion() function every 10th question, and the Game component is supposed to continue displaying questions. What actually happens is my website crashes after answering the 10th question correctly, because it "Cannot read properties of undefined (reading '10')"; the questionList logic somehow returns undefined (the error occurs on line 512).
I'm not sure why, but state variables such as currentListIndex (the current index in questionList) don't seem to be getting updated by getNextQuestion(). Even after that function gets called, the old value of currentListIndex seems to still be getting used, and that breaks the game every 10 questions (each questionList is 10 elements long so the max index is 9; currentListIndex seems to become 10 at some point for unknown reasons).
questionsIndices (basically an array of indices to determine which lists of questions can be used to generate questionList) also seems to fail to get updated by that same function.
My only guess is that I'm using useEffect() incorrectly. Thank you for taking the time to read this, and I appreciate any assistance I can receive to resolve this issue.
EDIT: use the console output to see the correctAnswer to each question. Game overs will cause the game to reset itself back to score 0 (this may take a few seconds).
Hi so my wordpress site has just started acting up, I am not sure if its an update that has caused this but only on this one page I am getting this error regarding
Notice: Array to string conversion in /customers/c/1/7/veganantics.co.uk/httpd.www/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/StoreApi/Schemas/ImageAttachmentSchema.php on line 95
I can't seem to find the issue, I have tried replacing the file with a new core file and the error is still there, would really appreciate some help
This is the page: https://veganantics.co.uk/vegan-gifts/
Thank you
Ash
The theme, a plugin or some custom code is probably using the wp_calculate_image_sizes filter and returning an array instead of a string.
Do a text search on your install and look for wp_calculate_image_sizes. The function that you need to find will look similar to
add_filter('wp_calculate_image_sizes', 'something');
Explanation:
ImageAttachmentSchema.php on line 95 is calling wp_get_attachment_image_sizes which must be a string.
wp_get_attachment_image_sizes is returning wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id ) which again must be a string.
wp_calculate_image_sizes returns a filtered value, and that's the only place where such an error (array instead of a string) can happen. So, if the filter incorrectly returns an array, it bubbles up to the function that you see in the error log.
Apologies for the basic question but I'm new to regular expressions and am really struggling to find a solution to the problem I am facing.
I am trying to pull out a particular field from a json response dynamically, which can change each time I call it.
The response is:
[{"colorPartNumber":"10045112022164298","skuPartNumber":"0400218072057","productColor":{"identifier":"Dark blue","label":"Dark blue","hex":"#0000A0"},"productSize":{"identifier":"0","label":"0","name":"Designer","scaleLabel":"apparel-wmn","schema":{"name":"UK","labels":["8"]}},"soldOut":true,"onlyOneLeft":false,"limitedAvailability":false,"preorder":false,"comingSoon":false,"visible":true,"displayable":true,"buyable":false,"availableInPhysicalStore":false,"expectedShippingDate":null},{"colorPartNumber":"10045112022164298","skuPartNumber":"0400094632819","productColor":{"identifier":"Dark blue","label":"Dark blue","hex":"#0000A0"},"productSize":{"identifier":"1","label":"1","name":"Designer","scaleLabel":"apparel-wmn","schema":{"name":"UK","labels":["10"]}},"soldOut":true,"onlyOneLeft":false,"limitedAvailability":false,"preorder":false,"comingSoon":false,"visible":true,"displayable":true,"buyable":false,"availableInPhysicalStore":false,"expectedShippingDate":null},{"colorPartNumber":"10045112022164298","skuPartNumber":"0400218072040","productColor":{"identifier":"Dark blue","label":"Dark blue","hex":"#0000A0"},"productSize":{"identifier":"2","label":"2","name":"Designer","scaleLabel":"apparel-wmn","schema":{"name":"UK","labels":["12"]}},"soldOut":true,"onlyOneLeft":false,"limitedAvailability":false,"preorder":false,"comingSoon":false,"visible":true,"displayable":true,"buyable":false,"availableInPhysicalStore":false,"expectedShippingDate":null},{"colorPartNumber":"10045112022164298","skuPartNumber":"0400468014814","productColor":{"identifier":"Dark blue","label":"Dark blue","hex":"#0000A0"},"productSize":{"identifier":"3","label":"3","name":"Designer","scaleLabel":"apparel-wmn","schema":{"name":"UK","labels":["14"]}},"soldOut":false,"onlyOneLeft":true,"limitedAvailability":false,"preorder":false,"comingSoon":false,"visible":true,"displayable":true,"buyable":true,"availableInPhysicalStore":false,"expectedShippingDate":null}]
I am trying to pull out the skuPartNumber, but only when the "buyable" value is set to true.
Every thing I try I cannot seem to get just this one value :(
So in the example above the only value I want to pull out is 0400468014814.
This json is dynamic so there could be 100 values coming back, but the principle is the same.
One example of a failed attempt is skuPartNumber(.*?)"buyable":true, which only gives me the very first value (0400218072057), which is wrong.
Once again sorry for the basic question.
Try the following regular expression:
\"skuPartNumber\":\"(\d+)\"(?:[^}]*?\}){3}[^}]*?\"buyable\":true
Your answer is in the first match group.
Is there an easy way to update a field on a get of a get_or_create?
I have a class ItemCategory and I want to either create a new entry or get the already created entry and update a field (update_date).
What I do is:
item,created= ItemCategory.get_or_create(cat=cat_id,item=item_id)
if created == True:
print "created"
else:
item.update_date = datetime.now
item.somethingelse = 'aaa'
item.save()
This works for a while in my loop. But after 50-100 get/create it crashes:
peewee.InterfaceError: Error binding parameter 4 - probably unsupported type.
Maybe I should use upsert(), I tried but wasn't able to get anything working. Also it's not probably the best solution, since it makes a replace of the whole row instead of just a field.
I like peewee, it's very easy and fast to use, but I can't find many full examples and that's a pity
Newbie mistake
item.update_date = datetime.now()
I am not 100% sure this is the only answer though. I modified my code so many times that it might be also something else.
Regarding my question about create_or_update , I've done this:
try:
Item.create(...)
except IntegrityError:
Item.update(...)
peewee is really great, I wonder why no one ever asked for a create_or_update.
I'm creating an application that requires me to post a lot of data into tables as well as changing values within the table.
Whenever I write applications most of my time seems to be stopping errors such as:
'Cannot perform this method on a closed dataset'`
or
'tblName not in edit or insert mode'`
I seemingly get these every time and they aren't easy to debug and find out what's going wrong where.
I'm just looking for some guidance on how I can stop this from happening, I know it's something I am doing. For example, at the moment I am getting:
'Cannot perform this operation on a closed dataset'
somewhere within this code:
procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if not tblSystem.Active then
tblSystem.Open;
if not tblSpecs.Active then
tblSpecs.Open;
tblSpecs.Edit;
tblSpecs.Post;
tblSpecs.Close;
// Post changes to the notes on exit
tblSystem.Edit;
tblsystem.Post;
tblSystem.Close;
end;
and
procedure TfrmMain.chkAutoUpdateClick(Sender: TObject);
begin
tblSystem.Edit;
if chkAutoUpdate.Checked then
chkInstUpdates.Enabled := True
else
begin
chkInstUpdates.Enabled := False;
tblSystemAutoUpdate.AsBoolean := False;
end;
end;
I'm going to assume right away that this is bad code for pushing/pulling data from a table, any help would be appreciated. Also any debugging help would be amazing.
If I were to guess, I'd say that it's this line:
tblSystemAutoUpdate.AsBoolean := False;
You're trying to edit the value of a dataset field without its dataset actually being open.
WRT debugging help, when you get the exception message and it asks you to Break or Continue, choose Break. The stack trace view (upper-left pane in the standard layout) will show you the function call stack of the current thread, and that should be able to lead you right to it. Also, make sure you build developer builds of your code with the "Use Debug DCUs" project option enabled. That will let you trace into RTL and VCL units in the debugger.