Can someone explain, all other “voids” are working well and i can add them to void Start(), but shuffle isn’t, when i try to place it ahead it can recognize a “Shuffle void”, but it doesn’t work
int randomIndex = Random.Range(i, list.Count); change 0 to i and it’s works well, but still have problem with location in script, works only if i adds shuffle void before start
First of all those are not “voids”. They are called methods. You wouldn’t call your car “a red” or “a black” because it has the color red / black, would you? void is the return type of the method and void is a special pseudo type which indicates “nothing”.
Anyways What exactly do you mean be “working” or “recognize”? If something is not recognized it would mean that your code does not compile. Is that the case? Do you get a compiler error? If so what is it. If you don’t get a compiler error the method is recognised since you call it in line 7. You can’t call something that does not exist / is not recognised.
If you don’t get any compiler error, the next question would be, do you get any runtime error? So when you start your game, do any errors pop up in the console? If so, which ones?
If you don’t get any compiler nor runtime errors we would interpret your “not working” as a logical error. So you expect X to happen but you actually get Y (Y could be nothing at all).
I just read your second post (came in intermediately). Yes to do a proper equally likely shuffle you have to use “i” as the start value for your random value. However it does shuffle with 0 as well, just that the shuffle would be biased. Though you still haven’t said what is the actual issue? I would guess that you actually use your list in some other method and you expect the list to be shuffled there but you actually called your shuffle method afterwards. Of course you have to call it at a place where it does what you want.
Imagine we play a game with cards (in real life). The deck of cards is not shuffled in the beginning, So all cards are ordered. We wouldn’t draw our playing cards before we shuffle the deck, would we? Because shuffling the deck after we have drawn our cards would of course not change the cards we have already drawn. This is of course just an analogy. We don’t know what you do with the elements in your list. Since you have some other methods that you call in Start, like “GetButtons()” or “AddGameMemos()”, those may use the elements in the list to do something. Again shuffling the list after you used the list will most likely not change the outcome of what you have done before the shuffle.
You really should be more clear about your actual issue.
Sure a bit chaotic thoughts, thanks for help, and sure this is methods. That’s not actual a card game, so I need this shuffle at start, that’s why I’m asking. But anyway when I write this method after “Start()”, it get compiler error “method doesn’t exist”, so if I write it above “Start()”, it works well. But I got a bunch of methods below, that’s I’m wondering why it doesn’t work.
This doesn’t make any sense. It doesn’t matter where inside the class you place a method declaration. Maybe you placed it outside the class? That’s not possible. You can not define methods outside a class in C#.
In the code snippet you’ve shown you placed it right after the Start method. So this would work. Are you sure there is not another closing curly bracket in between?