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).
Related
Im trying to set up when I go through a collision it checks how many current players there are then times them by 2, when I print out the math is correct however it only ever adds one to the actual count on screen, any suggestions would be greatly appreciated!
(My default player count in my game mode is 1.)
Is it correct that you spawn agents in the same location?
If so, you may want to mark NoCollisionFail input of the SpawnAIFromClass as True. Setting this value to False allows UE to abort the spawn in case if newly-spawned actor overlaps with anything solid (in your cast it may be previously spawned actor).
Hope that answers your question.
I came across the following question and spent hours trying to figure out why there is a x in the remove function (I'm talking about question '(v)')
I see no reason for having a x because removing an element from the queue happens from the front and we already have the address of the front node stored (as a member in the struct).
It would be great if someone could please help me clear out this doubt because I tried to do so on my own but couldn't.
The next part of the question is as follows which is even more confusing...
The question is worded unclearly, but the main function you posted makes it clear what the code is supposed to do:
QueueElement seems to be a typedef to int, which is the value type stored in the queue.
Remove is supposed to remove the front element of the queue, and store its value into *x.
This is the case because in main it calls Remove(&i, &numqueue) and then prints the value of i.
As as aside, this code is badly written and hopefully you won't pick up too many bad habits from it. In particular, defining a Boolean where TRUE==0 and FALSE==1 is backwards and can lead to mistakes where if (bool_value) does the opposite of what it appears. This mistake actually happens in main where they wrote while (!QueueEmpty(...)).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have been given the assignment to create a quite complicated to me, but simple to some C game. The program will run and generate 25 random numbers between 1 to 100 (no repeats). The game is between two users.
Both the players will get two guesses each time. Every correct guess will be counted as 1 correct answer and will be displayed on the screen in the board.
The player having more number of correct guesses will be a winner.
The game will continue until the board is completely revealed.
The first screen should ask the user for his name, print a welcome message, and displays an empty 5x5 board. But this 5x5 board has the values in it internally
Now the program should ask the number of players (1 or 2)
If one, ask one name and second is computer and if 2 ask two names
For playing against computer, you are asked for two guesses and every correct guess is shown on the board.
Now 2 guesses for computer would be taken and shown on the screen.
I have tried everything to my knowledge to complete this but I lack a full understanding of C. Any help would be appreciated. I did not include my code because, honestly its just a mess and does not even run.
I would like to see someone be able to make such a game, so that I can study the logic. NOT COPY THE WORK
Simple steps. Start small and grow.
Easy one is to remove all questions to the user(s). Hard code the answers in the program. You can retrofit the IO later.
Start with a way ot generating 25 random numbers and load them into an array. Place the array in a global variable. You need a another array to show when a number is sucessfully guessed.
Now write a function to display that guessed array as 5X5.
Gradually build the program up
Always make functions
generate_array
show_guessed
....
If get stuck on specific things then post a new question.
This is not a direct answer, but a very long comment with some requests for more information and effort.
The problem I have with your request is that I see zero effort. I see a request for teh C0d3z and a promise not to cheat after receiving something that makes it far too easy to cheat.
What I, and probably others here, want to see is effort and some attempt.
Do you know how to print text to the screen like you see in the requirements? Do you know how to print text at all? If so, make the print routines and state this.
Do you know how to generate random numbers? If so, say so in your question and we see effort.
Do you know how to receive input from the user?
Do you know what an array is?
Do you know how to save code in your editor and compile it?
You can see that without any sort of background or starting code, we don't know where you are in your learning.
So...
Post an attempt at solving your problem in your question. If you are truly so new to coding that you cannot do this, then you need to sit down with your professor / TA / whomever and tell them this. Reading through your teaching material (textbook or whatever) should help a whole lot as well. This assignment feels like something I would see towards the end of a beginner's C class. If this is where you are, and you really have no clue what to do, then you may need to retake the class.
I have a bit of a question regarding why my code seems to hang when I run it. The code is for a project I have in a class, but we spent one class period going over Prolog so much of what I've learned is stuff I've searched around for and have taught myself. I do apologize if my code contains horrendous stylistic errors, but again, as we never formally learned how we 'should' use Prolog, this is based mostly on my own experimentation.
The goal of the segment of code I am writing is, more or less, to form a chain that connects one actor to another through a series of movies that they have been in.
I have a function I am calling that is meant to construct connections between a starting actor, all possible linked actors ending actor, and the list of movies that connects them. This is probably a horribly inefficient method of doing this, however implementing it this way solves two parts of the assignment with one segment of code.
The code that calls the function works, and for the sake of making this simpler to read, I will omit it unless asked to share it. In short, it asserts a globalStartingActor, and passes on two empty lists (ActorList = [] and MovieList = []) to a function doActorAssertions.
In turn, we have doActorAssertions. This is the revised version of it, which should be simplified and easier to read, but lacks the massive commenting that it had previously.
doActorAssertions(ActorsName,ActorList,MovieList) :-
isNotInList(ActorsName,ActorList) ->
(
findMoviesIn(ActorsName,MoviesIn),%finds all movies ActorsName is in
howLong(MoviesIn,LenMoviesIn),%Sees how many movies there are.
(
LenMoviesIn ==0;
(
append(ActorsName,ActorList,UpdatedActorList),%this causes errors!
globalStartingActor(GSAName),%asserted starting actor
assert(connectedActors(GSAName,ActorsName,MovieList)), %says that the GSAName is connected to ActorsName by a list of movies MovieList.
write(actorAsserted),
addAndTraverse(MoviesIn,UpdatedActorList,MovieList) %Goes to propegate all movies the actor is in, then actors in those movies, then recursively calls this function again.
)
)
),
true.
As I said previously, the append tag seemed to be the source of the error! This indeed appears to be the case when I simplify the code to what it is above. I simply comment that append out, and the code body works.
Why, then, is append preventing the code from working properly? I need to have append (or similar function) in that part of the code!
Is ActorsName a list? The variable' name suggests it is, as well as the usage in append/3, but then what isNotInList(ActorsName,ActorList) means? Partial or full disjunction? This could be the cause of the endless loop, maybe you should use the difference of those sets to increment the ActorList.
You should try to avoid assert/1, and instead pass around the state in variables. See this other answer for a schema doing something very similar to what you are attempting here.
This is useless, could be a typo, but then I don't understand the ->
...
),
true.
I think should read
...
); % note the semicolon!
true.
I have this code
n_userobject inv_userobject[]
For i = 1 to dw_1.Rowcount()
inv_userobject[i] = create n_userobject
.
.
.
NEXT
dw_1.rowcount() returns only 210 rows. Its so odd that in the range of 170 up, the application stop and crashes on inv_userobject[i] = create n_userobject.
My question, is there any limit on array or userobject declaration using arrays?
I already try destroying it after the loop so as to check if that will be a possible solution, but it is still crashing.
Or how can i be able to somehow refresh the userobject?
Or is there anyone out there encounter this?
Thanks for all your help.
First, your memory problem. You're definitely not running into an array limit. If I was to take a guess, one of the instance variables in n_userobject isn't being cleaned up properly (i.e. pointing to a class that isn't being destroyed when the parent class is destroyed) or pointing to a class that similarly doesn't clean itself up. If you've got PB Enterprise, I'd do a profiling trace with a smaller loop and see what is being garbage collected (there's a utility called CDMatch that really helps this process).
Secondly, let's face it, you're just doing this to avoid writing a reset method. Even if you get this functional, it will never be as efficient as writing your own reset method and reusing the same instance over again. Yes, it's another method you'll have to maintain whenever the instance variable list changes or the defaults change, but you'll easily gain that back in performance.
Good luck,
Terry.
I'm assuming the crash you're facing is at the PBVM level, and not a regular PB exception (which you can catch in your code). If I'm wrong, please add the exception details.
A loop of 170-210 iterations really isn't a large one. However, crashes within loops are usually the result of resource exhaustion. What we usually do in long loops is call GarbageCollect() occasionally. How often should it be called depends on what your code does - using it frequently could allow the use of less memory, but it will slow down the run. Read this for more.
If this doesn't help, make sure the error does not come from some non-PB code (imported DLL or so). You can check the stack trace during the crash to see the exception's origin.
Lastly, if you're supported by Sybase (or a local representative), you can send them a crash dump. They can analyze it, and see if it's a bug in PB, and if so, let you know when it was (or will be) fixed.
What I would normally do with a DataWindow is to create an object that processes the data in a row and call it for each row.
the only suggestion i have for this is to remove the rowcount from the for (For i = 1 to dw_1.Rowcount()) this will cause the code to recount the rows every time it uses one. get the count into a variable and then use the variable. it should run a bit better and be far more easy to debug.