Heiholf
Memory Referrence Issue In Recursive Algorithm
I haven't fully understood what the function should do nor how the code works but I think the problem has something to do with mutability.
All variables that aren't "simple" like ints, doubles, chars, etc. are passed by reference and keep their "state" even if you leave the scope. For example in this code:
The output is:
1
5
Because the array "remembered" the change.
20 replies
❔ Convert void to bool
That's correct in general a token is anything described above but the contest excludes:
SyntaxKind.PrivateKeyword,
SyntaxKind.PublicKeyword,
SyntaxKind.SemicolonToken,
SyntaxKind.CommaToken,
SyntaxKind.CloseBraceToken,
SyntaxKind.CloseBracketToken,
SyntaxKind.CloseParenToken
22 replies
❔ Need to delete all the Cloned Prefabs
------------------------------------------------------------------------------
To actually answer your question:
To delete all shorter fishes you at first have to get access to all fish, check if they are shorter and if they are delete them (Unity calls it Destroy).
How to access all fish:
Option 1: Keep track of the fish you've already created in a List somewhere and remove them when there are destroyed.
Option 2: If all fish share a parent you can call
GetComponentsInChildren<FishController>()
on this parent and you should get a List of FishControllers which enables you to access the fish as well. (I wouldn't recommend this option because it is more expensive to execute and in my opinion more complicated to implement).
How to check if they are shorter:
If you have a list of all fish iterate over all of them and compare their lengths and delete them accordingly.
To other people reading this:
Do not tell me that this is not the optimal way of implementing this. Yes, there are ways to speed it up like storing the fish sorted by length and looking up the fish length boundary with Binary Search. However, I don't think this is helpful advise in the moment.4 replies
❔ Need to delete all the Cloned Prefabs
Taking a look at your code many questions arise.
1) Why do you call
fishPrefab.GetComponent<FishController>()
in the beginning?
2) Why do you increase the fishAmount
eventhough you apparently don't Instantiate a fish or do something similar
3) What do you try to accomplish with this line FishController fishController = fishPrefab.GetComponent<FishController>()
you never use fishController
anywhere in this scope?
4) What is FishController
, is it a static class?
5) What should the function do in the first place the name StoreFishy()
indicates that you want to store a Fish(y) in some way but there aren't even signs that something like that happens anywhere? It seems more like you are trying to create and add additional fish to the scene.
As a tip: Do not post screenshots of your code instead put it into a code environment (start with three ` (backticks) and end with three `)4 replies
❔ Convert void to bool
This is definitely the closest way to "convert void to bools" but it sadly is too verbose because a token is a keyword, a opening/closing brace/bracket/parenthesis, dot, comma, semicolon, type name, variable name or any "atomic" element of code (some of these are excluded by the rules of the contest).
22 replies