Jump to content


Photo

Find objects that meet the criteria.


  • Please log in to reply
2 replies to this topic

#1 wnsrn3436

wnsrn3436

    GMC Member

  • GMC Member
  • 134 posts
  • Version:GM8

Posted 01 March 2012 - 11:02 AM

It is slow.
Please use the following things: http://gmc.yoyogames...howtopic=284288

Spoiler


EDIT :

var id_s, distance, distance2;

id_s=noone
distance=argument1

with(argument0)
{
    distance2=point_distance(x, y, other.x, other.y)
    if distance>distance2 and id!=other.id /*and ...*/
    {
        id_s=id
        distance=distance2
    }
}

return id_s

The default criteria is the distance.
Script(object, distance)

Edited by wnsrn3436, 17 August 2012 - 01:41 AM.

  • 0

#2 thenoller

thenoller

    GMC Member

  • GMC Member
  • 208 posts

Posted 13 July 2012 - 11:51 AM

Cool! This taught me that "other" can refer to the executing instance even while inside a with-construction, making it a great starting point for many different scripts I've been missing. Thanks! :)

By the way, you shouldn't call "point_distance(x, y, other.x, other.y)" twice - instead store it in a temporary variable.

EDIT:

Okay, "other" does not refer to the instance running the script; not in my version of GM anyway. One can, however, use global variables for this.

Edited by thenoller, 13 July 2012 - 06:11 PM.

  • 0

#3 wnsrn3436

wnsrn3436

    GMC Member

  • GMC Member
  • 134 posts
  • Version:GM8

Posted 02 August 2012 - 11:16 AM

Cool! This taught me that "other" can refer to the executing instance even while inside a with-construction, making it a great starting point for many different scripts I've been missing. Thanks! :)

By the way, you shouldn't call "point_distance(x, y, other.x, other.y)" twice - instead store it in a temporary variable.

EDIT:

Okay, "other" does not refer to the instance running the script; not in my version of GM anyway. One can, however, use global variables for this.


Oh! Good!
I saw too late. :sweat:

​Local variables can be shared in with-statement by using prefix 'other.' In contrast,
temporal variables that defined wih 'var' can be shared in current script without any prefix.​

umm...
​If variables are not defined as 'temporary' can be brought up from an arbitrary instance that exists,
otherwise( that is, if the variable is not temporary) it can not be used within other instances by the usage of With statement.​

EDIT :

var id_s, distance, distance2;

id_s=noone
distance=argument1

with(argument0)
{
    distance2=point_distance(x, y, other.x, other.y)
    if distance>distance2 and id!=other.id /*and ...*/
    {
        id_s=id
        distance=distance2
    }
}

return id_s

Edited by wnsrn3436, 02 August 2012 - 11:37 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users