Heiholf
Heiholf
CC#
Created by Tal on 7/24/2023 in #help
Memory Referrence Issue In Recursive Algorithm
Have you tried an iterative approach yet, this may resolve the problem all together.
20 replies
CC#
Created by Tal on 7/24/2023 in #help
Memory Referrence Issue In Recursive Algorithm
This would prevent the array changes from "leaking" into the next recursion but I'm not sure if you may want that to some extent because I do not understand the function completely.
20 replies
CC#
Created by Tal on 7/24/2023 in #help
Memory Referrence Issue In Recursive Algorithm
Directly after if (arr == null || arrToAssemble == null) return null;
20 replies
CC#
Created by Tal on 7/24/2023 in #help
Memory Referrence Issue In Recursive Algorithm
The safest (maybe not best/optimal) way to fix this is to clone indexerArr in the beginning as clone or something like that and only mutate that Clone
20 replies
CC#
Created by Tal on 7/24/2023 in #help
Memory Referrence Issue In Recursive Algorithm
The cloning there does not help because you already mutate the array in the for loop with indexerArr[currRank]++
20 replies
CC#
Created by Tal on 7/24/2023 in #help
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:
public static void Main()
{
int[] ints = {1, 2 ,3};

printAndEdit(ints);
printAndEdit(ints);
}

public static void printAndEdit(int[] list)
{
Console.WriteLine(list[0]);
list[0] = 5;
}
public static void Main()
{
int[] ints = {1, 2 ,3};

printAndEdit(ints);
printAndEdit(ints);
}

public static void printAndEdit(int[] list)
{
Console.WriteLine(list[0]);
list[0] = 5;
}
The output is: 1 5 Because the array "remembered" the change.
20 replies
CC#
Created by Heiholf on 7/22/2023 in #help
❔ 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
CC#
Created by Qpy on 7/23/2023 in #help
❔ 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
CC#
Created by Qpy on 7/23/2023 in #help
❔ 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
CC#
Created by Heiholf on 7/22/2023 in #help
❔ 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
CC#
Created by Heiholf on 7/22/2023 in #help
❔ Convert void to bool
Tha's a very clever idea, according to the token counter it is equivalent to the first method but there might be room for optimization
22 replies
CC#
Created by Heiholf on 7/22/2023 in #help
❔ Convert void to bool
It would probably count, maybe even as 2 or 3 tokens but I can say for certain because I dont know of a way to accomplish the functionality
22 replies
CC#
Created by Heiholf on 7/22/2023 in #help
❔ Convert void to bool
I haven't counted directly but the second version would lead to a syntax change somewhere else which would overall reduce tokens
22 replies
CC#
Created by Heiholf on 7/22/2023 in #help
❔ Convert void to bool
I think you are correct. But sadly a function or a lambda create more tokens as the first option.
22 replies
CC#
Created by Heiholf on 7/22/2023 in #help
❔ Convert void to bool
No, they are given methods
22 replies