GM:S 1.4 Turning Multiple Objects *SOLVED*

Discussion in 'Programming' started by Odolwa, Oct 5, 2018.

  1. Odolwa

    Odolwa Member

    Joined:
    Jul 11, 2016
    Posts:
    57
    I have an object with separate hitbox objects matching its movement. I want to make a shorthand for the code when manipulating the 'image_angle' of all of these at once. At present I have it as follows:
    Code:
    image_angle += 1 //The main object
    obj_a.image_angle += 1 //The hitbox objects a, b & c
    obj_b.image_angle += 1
    obj_c.image_angle += 1
    
    If I wanted to reduce all of that to a single line variable do I use an array? I've tried writing the following, but I get an error so I must be doing it wrong:
    Code:
    var array[3] = obj_a.id, obj_b.id, obj_c.id
    
    Can anyone help? Thanks.
     
  2. Paskaler

    Paskaler Member

    Joined:
    Jul 4, 2016
    Posts:
    315
    You should use this code to initialize the array

    Code:
    var array;
    array[0] = obj_a;
    array[1] = obj_b;
    // ... and so on
    
     
    Odolwa likes this.
  3. Odolwa

    Odolwa Member

    Joined:
    Jul 11, 2016
    Posts:
    57
    Ok, so I created the array as you described and then tried manipulating the 'image_angle' as follows:
    Code:
    array.image_angle = image_angle //Image angles of all hitbox objects in the array will match the image angle of the main object they are attached to
    However, an error is thrown which says this is an illegal use of arrays. How should I write the code then, to get the desired effect?
     
  4. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,549
    Code:
    for (var i = array_length_1d(array)-1; i >= 0; i--) {
      (array[i]).image_angle += 1;
    }
     
    Odolwa likes this.
  5. Odolwa

    Odolwa Member

    Joined:
    Jul 11, 2016
    Posts:
    57
    Great! Thank you.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice