Jump to content


Photo

determining an instance id


  • Please log in to reply
4 replies to this topic

#1 _258945

_258945

    GMC Member

  • New Member
  • 20 posts
  • Version:GM8

Posted 17 April 2012 - 01:12 AM

Gamemaker 8.1 Pro.

Its a simple thing I need to do, but I'm not sure how to write the code.
////obj1_instance_1

////needs obj2_instance_2's ID

////so it can change obj2_instance_2's variables

////rather than changing obj2_instance regardless of how many copies there are of the object.
I'm not going to throw up my guesses in code at the moment.

If anyone can help me out, I will greatly appreciate it.

Edited by _258945, 17 April 2012 - 04:11 PM.

  • 0

#2 kupo15

kupo15

    GMC Member

  • GMC Member
  • 400 posts

Posted 17 April 2012 - 02:45 AM

There is a command call instance_find(obj,n+1) which finds a specific instance. You could also set up an array that assigns ids to it so you can reference that if you wanted too. The help menu and google are very useful :)
  • 0

#3 _258945

_258945

    GMC Member

  • New Member
  • 20 posts
  • Version:GM8

Posted 17 April 2012 - 03:08 AM

There is a command call instance_find(obj,n+1) which finds a specific instance. You could also set up an array that assigns ids to it so you can reference that if you wanted too. The help menu and google are very useful :)


So, now I'll start with my guesses.
///this is all currently untested

///create event of object 1
variable_instance_id = instance_id

///event that sends the variable_instance_id to object 2
obj_2.instance_id_get = variable_instance_id

///later on in object 2 edits variables
if something_happens = true
{
      instance_id_get.obj_1.variable_something = true
      instance_id_get.obj_1.variable_somethingelse = -10
}

The other idea I had was something like this:

///event of object_Q that creates object 1
instance_id_get = instance_find(obj_1, instance_number(obj_1)+1)
instance_create(x, y, obj_1)
variable_instance_id.obj_1 = instance_id_get

///then we pick back up after the create event as detailed in first code
///but I've no clue if any of this will work, or what it will do.
///I have an idea what I think it should do... but this may not be what will happen.


.....none of THAT worked....

Edited by _258945, 17 April 2012 - 04:21 AM.

  • 0

#4 kupo15

kupo15

    GMC Member

  • GMC Member
  • 400 posts

Posted 17 April 2012 - 03:42 PM

Well if you want to get an id from an instance and put it in a var you simply use something like
variable = id; //make sure id is on the right

but if you want the 2nd instance of an object just do this

instance_find(obj2,1).VAR = whatever

No hard feelings but did you just make up those functions like instance_id_get and instance_id :P
When learning GML, the best way I learned was to use the help file or googling. If I needed to find something related to instances like ids or something, I would search for instances in the help file and it will show you all the functions that GM has under that then you just pick the one that fits what you want. :)

Edited by kupo15, 17 April 2012 - 03:43 PM.

  • 0

#5 _258945

_258945

    GMC Member

  • New Member
  • 20 posts
  • Version:GM8

Posted 17 April 2012 - 04:08 PM

instance_id_get was not a function, it was a user made variable, instance_id is a default GM8.1 variable.

however, I got some help from Noele on the issue of instance id's and it all clicked:

3 ways to get the id

instance_create
instance_nearest
and collision events

the way to assign the id is to make a variable that equals one of these events:

variable_id = instance_create(x, y, obj_created)

variable_id is now used as the object to be effected by other objects.

variable_id.direction = 0

Now, I was close on some points, and way off on others (particularly getting the actual id, I went as far as trying to assign the id which is redundant, I know since every instance already has an id). But the central part of my confusion seemed to lay in the usage of variable_id I thought it had to be attached to the particular object: variable_id.obj_created.direction = 0. but that is of course not valid.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users