• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Problem with objects/instances

R

RisingKane

Guest
Hi there!

I'm trying to continue making my game, but I'm facing some objects/instances problems. I'm working on the code (script) below:

Code:
with (obj_button) {

    if (empty) {
        show_message("EMPTY");
    }
    else {
        for (i = 0; i <= array_length_1d(vec_exe) - 1; i += 1){
            show_message(vec_exe[i]);
        }
    }
}
But the tricky part is that I have 4 instances of "obj_button" on screen when the game starts, so the messages are shown 4 times, but I want them to be shown only once. Does anyone know how to fix that?

Thanks!
 

NazGhuL

NazTaiL
You can do:
Code:
var message;

with (obj_button) {

    if (empty) {
        message = "EMPTY";
    }
    else {
        for (i = 0; i <= array_length_1d(vec_exe) - 1; i += 1){
            message = vec_exe[i];
        }
    }
}

show_message(message);
 
R

RisingKane

Guest
You can do:
Code:
var message;

with (obj_button) {

    if (empty) {
        message = "EMPTY";
    }
    else {
        for (i = 0; i <= array_length_1d(vec_exe) - 1; i += 1){
            message = vec_exe[i];
        }
    }
}

show_message(message);
Thanks for your answer, NazGhuL!

I understood what you said, but the problem is that, in that code, the 'message' variable will contain only the last position of the 'vec_exe' array. I'd like it to have all the positions. I'm trying that by using another for, outside of the 'with(obj_button)' clause, I'll have some results soon. Thanks again!
 

NazGhuL

NazTaiL
You want to display all message?
Like:
Code:
var message;

with (obj_button) {

   if (empty) {
       message += "EMPTY#";
   }
   else {
       for (i = 0; i <= array_length_1d(vec_exe) - 1; i += 1){
           message += string(vec_exe[i])+"#");
       }
   }
}

show_message(message);
 
R

RisingKane

Guest
You want to display all message?
Like:
Code:
var message;

with (obj_button) {

   if (empty) {
       message += "EMPTY#";
   }
   else {
       for (i = 0; i <= array_length_1d(vec_exe) - 1; i += 1){
           message += string(vec_exe[i])+"#");
       }
   }
}

show_message(message);
Yeah dude, that worked out! The thing is that, at least I think so, as 'obj_button' had 4 instances on screen, the game displayed one message for each instance, thus, the same message was shown 4 times, in the same message box. It was something like this:

1.PNG

All I did was writing that code you made inside another object that had only one instance on screen, like this:

Code:
var message;

with (obj_another) {

   if (empty) {
       message += "EMPTY#";
   }
   else {
       for (i = 0; i <= array_length_1d(vec_exe) - 1; i += 1){
           message += string(vec_exe[i])+"#");
       }
   }
}

show_message(message);
Then, I got what I wanted:

2.PNG

Thanks again!
 
Top