Discuss and collaborate on GML scripts

You are not logged in.

#1 2021-05-22 08:17:39

Registered: 2021-05-22
Posts: 1


at first,iam very new to programming. whistle

line 25            if (i != noone) ds_list_add(dsid,i);

doesnt it has to be              if (i != noone) ds_list_add(other.dsid,i);

getting errors in the to checking object the variable dsid  does not exist.

Last edited by rons0n (2021-05-22 08:37:19)


#2 2021-05-25 13:37:21

Registered: 2007-08-18
Posts: 1,233

Re: collision_circle_list

First, I guess you are using a legacy version of GameMaker. This script has an equivalent built-in function now that has some additional features as well. … e_list.htm

If you are using GMS2, you should not be using this script.

The variable dsid is a local variable declared at the start of the script on line 14.

Expandvar x1,y1,radius,obj,prec,notme,dsid,i;

If you have modified this script to work in GMS2.3 by turning it into a function with a proper function signature at the top and you have removed lines 14 to 20 to make it work, that could explain the problem. The parameter variables in the function signature collision_circle_list(x1,y1,radius,obj,prec,notme) are automatically declared and set when the script function is called. But two of the local variables on line 14 still need to be declared: dsid and i

While the script is executing, local variables should always be visible and have precedence over any instance variable that might have the same name. Using other in the way you suggest would force the script to use an instance variable belonging to the calling instance, the instance outside of the with construct. Likewise, using self there would force the script to use the instance that is currently in scope, the instance being iterated upon inside the with construct.

If dsid had NOT been declared as a local variable in the script, this would cause the error you saw and your suggestion could fix it. It would also create a new variable in the calling instance, or if that variable was already being used in the instance, it would change its value which could cause a bug somewhere else. That's why local variables are used. It prevents a script from accidentally messing up any instance variables that might have the same name or wasting memory and time caused by creating new variables that are not needed outside of the script/function.

You can read about self and other here: … ywords.htm

And you can read about with here: … 2Fwith.htm

And you can read about var and local variables here: … iables.htm

Abusing forum power since 1986.


Board footer

Powered by FluxBB