In most other languages, such as C or C++, when you pass arguments you pass them in order.
For example:
int my_function(string name, int size, char type)
{
...
}
int main()
{
my_function("item1", 10, 'c')
}
This is how the compiler actually organizes the code in real machine code.
In Python, they make things a bit higher level for programmers, so you can do something like this
def my_function(name="default", size=1, type='c'):
...
my_function(size=4, name="item1", type=d)
Notice how you can call the function with arguments in a different order than the function was defined.
The only way to know what value you meant to pass for each parameter is by using the correct order. For python, you can get around this by using the assignment operator to the parameters in the call (such as size=2).
Once you do a call in a different order than the way the function was defined, you have to explicitly state which parameter you are assigning for all the following arguments. This makes sense since you have now called the function out of order and it needs to know which parameters you are referring to.
For instance, you can do this:
def my_function(name, size, type, id):
...
my_function("item1", size=4, type=d, id=3)
but you cannot do this:
my_function("item1", size=4, d, 3)
Since it now doesn't know if you mean to set d
for the id
or d
for the type
and vice versa.
Your question was how to know what order the function would like the arugments in. The best way to find this is to read the documentation for the function you are using.
If you go here https://www.pygame.org/docs/ref/sprite.html#pygame.sprite.groupcollide
You can find pygame.sprite.groupcollide and it gives you the function arguments in the order it expects. You could also manually assign then with the = operator after each parameter.
#documentation found online
pygame.sprite.groupcollide()
Find all sprites that collide between two groups.
groupcollide(group1, group2, dokill1, dokill2, collided = None)
For example in your code you can call:
pygame.sprite.groupcollide(group1=bullets, group2=aliens, dokill1=True, dokill2=True, collided = None)