GM:S 1.4 Running scripts on objects in array.

Discussion in 'Legacy GameMaker Community Tech Support' started by jacenqu, Jan 12, 2020 at 7:02 PM.

  1. jacenqu

    jacenqu Member

    Joined:
    Sunday
    Posts:
    1
    Hello! I've been trying to run a script on objects in an array.
    I have a object (o_roommaker) which fills an array with objects, then spawns them in.
    I'm trying to use a script to update each objects sprite (I tried to do it in the object itself, but if the player was walking around he could see the objects changing their sprites. And I can't do it immediately after objects are placed, since the orientation of the walls will be different as more are added.)
    It appears the script doesn't even run, because I threw debug messages into the script and they won't display.
    Anyone know a solution?

    Here's the bit of code and script I cannot get to work:
    o_roommaker(create event):
    Code:
    for(var i = 0; i < 20; i++) {
        for(var ii = 0; ii < 20; ii++) {
            if(roomGrid[i, ii] == o_wall) {
                with(roomGrid[i, ii]) {
                    update_sprite(roomGrid[i,ii]);
                }
            }
        }
    }
    Script update_sprite():
    Code:
    top = true;
    bottom = true;
    left = true;
    right = true;
    if (position_meeting(x, y - 16, o_wall)) {
     top = false;
    }
    if (position_meeting(x, y + 16, o_wall)) {
     bottom = false;
    }
    if (position_meeting(x - 16, y, o_wall)) {
     left = false;
    }
    if (position_meeting(x + 16, y, o_wall)) {
     right = false;
    }
    //none around it.
    if (!top && !bottom && !left && !right) {
     sprite_index = asset_get_index(wallpath + "top");
    } //all around it.
    if (top && bottom && left && right) {
     sprite_index = asset_get_index(wallpath + "none");
    } //none above.
    if (!top && bottom && left && right) {
     sprite_index = asset_get_index(wallpath + "bottom");
    } //none below.
    if (top && !bottom && left && right) {
     sprite_index = asset_get_index(wallpath + "top");
    } //none left.
    if (top && bottom && !left && right) {
     sprite_index = asset_get_index(wallpath + "right");
    } //none right.
    if (top && bottom && left && !right) {
     sprite_index = asset_get_index(wallpath + "left");
    }
    
    wallpath is defined in the wall object's create event as:
    Code:
     wallpath = "s_testwall_"; 
     
  2. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,792

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