Difference between argument0 and argument[0]

C

ChaosX2

Guest
Hello!

Sorry if this is a noob question. I was going through a tutorial on finite state machines and as I was going through the code to understand it, I noticed argument[0] (and argument[1]) being used a lot and I don't understand the difference. The code did incorporate a ds_map for organizing so I'm assuming it has something to do with storing the keys and values.

I'm used to using a script and understanding arguments as "myScript(argument0, argument1);" Does argument[0] incorporate both argument0 and argument1 or what? Any help is much appreciated in understanding this.
 

johnwo

Member
There is no difference between argument0 and argument[0].

They're simply there for convenience, for example if you have a script with n arguments, you can iterate through them easily.

Cheers!
 

FrostyCat

Member
Of course there is a huge difference. If you refer to arguments using the non-array form, the script would take a fixed number of arguments. If you refer to arguments using the array form, the script would take an arbitrary number of arguments, in which case you should count them with argument_count.
 

Jezla

Member
The difference is that argument0 is a variable and argument[0] is an entry in an array. They function the same, but using the array, as @johnwo says, allows you to iterate through them, as well as use the argument_count variable if you want to vary the number of arguments used for a particular script. Note that you cannot mix the two, you must use either the variable or the array, not both at the same time.

Edit: Ninja'd
 

johnwo

Member
If you refer to arguments using the non-array form, the script would take a fixed number of arguments.
Strictly speaking, there is no difference between:
Code:
var a = argument0;
and
Code:
var a = argument[0];
It is true that you can make a script that takes an arbitrary number of arguments, that's why I added:
for example if you have a script with n arguments
n is an arbitrary number of arguments.

Cheers!
 

Mercerenies

Member
No, @FrostyCat is definitely right. There is a semantic difference between them. Read his post again. In GM8.1 and before, there wasn't a difference (and I believe you could even mix the notations), but with GM:S using the non-array form enforces compile-time constraints on the arity that using the array form disables. Basically, use the non-array form unless you need to iterate over the argument list or take a variable number of arguments.
 
Top