Programming Multiples of The Same Object to do Different Things

Pretty simple, really. I have 5 gui buttons. They have an “Off” frame and an “On” frame. Would it be best to import them all in one object, or to import each as a separate object with 2 frames? I will show what I’m trying to do in a screen shot.


So, I have 25 Buttons, 5 rows of 1 through 5. Very simply, all they do is display what the current weapon level is of each weapon. Here’s the things I don’t know. I don’t know if it would be best to have one button object with all 5 off and all 5 on frames, and make 25 instances of that, or if it would be best to have 5 button objects with 1 off and 1 on frame. I also don’t know how to control each different instance. I don’t know how to make, say, row one show the level of one weapon, while the other row shows the level of the next weapon. I don’t know how to tell Gdevelop that I want each instance of the object to do something different based on the weapon level. (Beginner with Gdev, but not total beginner in general. I’ve already implemented a functional weapon level system, for instance. Still pretty newb, so pointing me to a good tutorial that covers what I’m trying to do would be helpful.)

HI,
I usually prefer t use 1 object with more instances.
To determine the object I use a object variable (ex. ID or name).
How to select the correct object depend about your code.
You can use “for each object” and the condition to check if the ID is the correct one.

3 Likes

Thanks for the suggestion. I will toy around with it and check back if I have issues.
@jumpingj NVM, fully golden now! I found the instance variables! :slight_smile: I’m a dangerous MFer now!

2 Likes

No need for that, the condition is enough

3 Likes

Really ?wow. Please help me to understand when it is necessary to use “pick all object” and “for each object”


The “for each object” is to be used when you want to do a free action for every object, for example, if you want to make a scene array with all the X positions of each instance of an object, by default the “Push X onto a scene array” condition has no object in parameters so it will be executed only once, only adding he X position of one more or less random object (technically it is not random, but it is not really specified and therefore something your code shouldn’t rely on). In that case, you would use the “for each object” so that this free action gets called for each instance, adding everything into the array.

Since a condition checking for a variable of an object already uses an object in its parameters, it is an object action and will perform object picking for you.


The pick all objects is for resetting object picking. For example, if you want to check if object instances with ID 1 and ID 2 exist, you cannot put them all in one event, as after the first one, only the object with ID 1 remains picked, and since the next condition will only be checked on that object, it is bound to fail. Instead, you would after the first condition to check if an object has ID 1 use pick all objects to reset object picking so that the next conditions and actions will be run on all the instances again. Now all instances can be checked to see if one has ID = 2.

3 Likes

Excellent information here. I was kind of wrong about my assumptions of what “instance variables” actually do, but it doesn’t matter because as things developed so did how I plan to implement that Ui feature. Basically, that weapon screen up there is only going to display the current weapon, and one row of buttons will display the current weapon level. At week 2, I feel that I’m a little less than half way done with what I’m trying to accomplish here, and will soon be looking for the appropriate places to share screenshots of the project with the community. Every graphic is hand made, pixel by pixel, every sound effect, so far, from jfxr and I plan on writing the sound track myself.