Hello, I am in the process of going through the Udemy course “Learn to Code by Making Games - Complete C# Unity” I am at the tail end of the Block Breaker section.
Full disclosure, one could describe my level of competence as “novice” only if one were being very generous.
This is a question unrelated to Block Breaker. I am in the midst of fiddling around using Unity to make a character generator and eventually Virtual Tabletop (VTT) assistant of sorts to aid in online RPG play. One of the key things I will need to do over and over again is roll dice and get the results.
I have the basics of a script for rolling [numberofdice]d[sizeofdie]. In the particular game I will be playing there is are also types of rolls “boons” and “banes” with boons you roll a number of d6 and take the highest one and add that to the 1d20 roll. Banes work the same but you subtract the highest die from the d20 roll.
I figured rather than rewriting essentially the same code for the boons and banes rolls I could point the boon and bane methods to the RollThem Method and use that putting the results of the rolls into an array, sorting them, then pulling the highest number only. The problems I am running into is twofold. Attempting to call the RollThem Methods for the Bane or Boon give the following error…
Error CS0029: Cannot implicitly convert type ‘void’ to ‘int’ (CS0029) (Assembly-CSharp)
The second problem is getting the array to sort. When I ran into trouble with the rolling I tried seeding the array manually just to test out that part of the code. The documentation in the Unity - Scripting API is completely unhelpful in this regard.Diltering for unity 4.6 and C# it has the following entry…
Sorts all Array elements.
Var hello = new Array (“c”, “a”, “b”); hello.Sort(); print(hello); // prints a, b, c.
Using this example results in the following error…
Error CS1501: No overload for method ‘Sort’ takes ‘0’ arguments (CS1501) (Assembly-CSharp)
If you could help be find my way back to the proper path I would be eternally grateful.
Ultimately, I may scrap this entire approach as I (hopefully) learn more and understand more but I am thus far pretty confused by OOP in general and can only infrequently understand what error messages are trying to convey. I hope this was not too rambling and someone can make sense of what my issues are and can provide enlightenment.
I did attempt to put this on github as suggested but after ~2 hour trip down that rabbit hole I gave up and I’m just including a ZIP file of the project.
Thanks in advance,
DiceRollerPoC.zip (147.5 KB)