Jump to content


Photo

Addressing an instance id stored as a variable


  • This topic is locked This topic is locked
2 replies to this topic

#1 AnalogF6Games

AnalogF6Games

    GMC Member

  • New Member
  • 1 posts
  • Version:GM8.1

Posted 03 September 2012 - 07:37 PM

EDIT: Wow, I found it finally. Instance_id is more for addressing a count for a particular instance type rather than global instance ids. You have to address the value as (instanceidhere).x = x_value. In my case, I replace "with(instance_id[obj_cockpit.wall1]) x" with "((obj_cockpit.wall1)).x"

I am running a game that is storing distance and directional data for individual instances, but I am being told that the n value is greater than 32000 and can't be used. What sense does that make when instance_id is by default going to start with 100000?

with(instance_id[obj_cockpit.wall1]) x = lengthdir_x(wall1_len,wall1_dir)
    with(instance_id[obj_cockpit.wall1]) y = lengthdir_y(wall1_len,wall1_dir)

The error I'm getting is
ERROR in
action number 1
of  Step Event
for object obj_cockpit_wall:

Error in code at line 3:
       with(instance_id[obj_cockpit.wall1]) x = lengthdir_x(wall1_len,wall1_dir)
                                    ^

at position 35: Array index >= 32000

Is it the way I'm using instance_id that's wrong? It can't be that I have to manually set instance ids and then use them, is it?

Edited by AnalogF6Games, 03 September 2012 - 07:54 PM.

  • 0

#2 HaRRiKiRi

HaRRiKiRi

    GMC Member

  • GMC Member
  • 1364 posts

Posted 04 September 2012 - 06:31 PM

You can also just do this:
with(obj_cockpit.wall1) {x = lengthdir_x(wall1_len,wall1_dir); y = lengthdir_y(wall1_len,wall1_dir);}
That is if obj_cockpit.wall1 is the id of an instance.

Edited by HaRRiKiRi, 04 September 2012 - 06:32 PM.

  • 0

#3 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1619 posts
  • Version:GM:Studio

Posted 04 September 2012 - 07:47 PM

Unless I missed my guess, obj_cockpit.wall1 is set to the id of an instance.

You can use that directly. For example:
obj_cockpit.wall1 = instance_nearest(x, y, o_wall);
obj_cockpit.wall1.x = 7;
with (obj_cockpit.wall1)
  y -= 3;

instance_id[n] is just a list of the ids of all instances that exist during the current step. The ordering of these ids may change each step. To help you understand how to use this array, note that the following are equivalent:
with (all)
  x += 1;
var n;
for (n = 0; n < instance_count; n += 1)
  if (instance_exists(instance_id[n]))
    instance_id[n].x += 1;

EDIT: Improved examples.

Edited by Gamer3D, 04 September 2012 - 07:50 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users