[Solved]Code problem, creating gui elements

I am creating scrollbar, horizontal and vertical, to simulate gui element in GDevelop.

Scrollbars share sprite objects, vertical and horizontal line, press button, … using a ID variable to differentiate groups of objects(scrollbars)

The problem is that the code does not differentiate between different groups of objects with the same ID number.

Project link: http://speedy.sh/TjtdG/GUIScrollBar.zip

Hi,

To use object’s variables, you need to use the conditions/actions in “All objects > Variables” (you’re currently using the “scene variable” conditions and actions for the objects, obviously it will not work as intended).

By the way, “Pick all XXX” is useless in your code.

If you use object variables, creating variables from the object’s editor, you must create a different object for each scrollbar, because when you create an object in the scene the object does not inherit the variables created from object’s editor. Did not why this happens ?. The new object in the scene hasn’t created variables. It has 0 variables created.

So, I create the variables from objects in the scene, to share a single object.

That is, if I use object variables, I must create an object for each scrollbar, for example ScrollBar1, scrollbar2, scrollbar3, etc …

Instead, creating the variables from objects in the scene only use one object (sprite).

‘Pick all’ is not right, then, What should I use to select the object with the specified id ?.

It is indeed inherit, they are just no shown in the instance variables. :wink:

Just the id condition you already wrote (Pick all XXX just takes all the instances of XXX into account, which is what GDevelop is already doing, then your “id” condition restrict that set of instances, etc).

If they are just no shown in the instance variables, How can i modify id variable or other object’s variables in the scene?

I used a condition in Pick all, right?

Just add it, it will override the existing one (if needed).

Yes, but it’s useless : just put the other condition alone, no need for “Pick all” before.

I have made changes related to object’s variables.

And, finally, i see that the condition:

if Variable Boton.Variable(id) = Variable(id) —> Do … to the position of Boton, select all Boton sprites, and modify the position of all sprites of type Boton.

How I can program change the position of the button with the specific id?

Can you show your new events ?

I’m not sure you fixed this :

I would use
++ For Each Boton
+++++ if boton.id = variable(id) …

Not really optimized, but you won’t have hundreds of boton in the same scene anyway.

Yes, that is. Thanks.

Yesterday was a little late and I could not continue to respond.

If I use Variables → Value of a variable, doing reference to object’s variable, don’t work correctly.

However, using All objects → Variables → Value of an object’s variable, it’s all right.

This is the new code:

I would rather do a For each on SliderVertical instead of For each Boton and For each Info as you want to proceed each sliders. Then, let the conditions the same they are : GDevelop will “browse” through all “Sliders” in an independant manner and select the correct Boton and Info objects for each Sliders.

Just need to replace Variable(id) with SliderVertical.Variable(id) (it’s an expression and you want to get id’s variable of an instance of SliderVertical)

Yes, id scene variable is not necessary. I can use id object’s variable directly.

I use “z-order” to pikup specific object.
“IF object.z-order=xx THEN …”
It’s works for me, but I do not know whether it is right.