1
\$\begingroup\$

I want to do a level selection menu in GameMaker. There's one button for each level. Clicking on the button 1 take you to level 1, button 2 take you to level 2 and so on.

But if I duplicate the first button, all of the buttons will get you to level 1. Is it possible for multiple instances of the same object to have different variables?

\$\endgroup\$
1
\$\begingroup\$

If you placed all the buttons in the room editor then you can define variables in instance creation code (room editor -> RMB on an instance -> Creation Code).

If you created all the buttons via code, you can easily define different values, like this:

for (var i=0; i<10; i++)
{
    var obj = instance_create(50 + i*50, 50, obj_button);
    obj.level = i; // all the instances will has different value
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy