Is there a list of points that we need to keep in mind while using the object variable in function? Or we just cannot use it?
What you you mean ?
Pass an object to a function by configuring the parameters of the function.
Use the function.
And in the function you can retrieve the object or instance variable of the object.
I have create a function and passing button and tile as parameters. This is the example, I’m trying.
Case 1: When the cursor is on button > create object tile (using y position with object variable count) - this does not work.
But when I use this:
Case 2: When the cursor is on tile > create object tile (using y position with object variable count) - this does work.
Are there any specific rules to work around an object variable?
Update: I checked this in a debugger, the object gets created for Case 1 also but not able to increase the value of count.
When you create a tile object, the value of count variable of the tile is initialized with 0.
So when you set the position using this count variable, the result is 70 for every single instances you create because 0*50+70 = 70
After, when you Do + 1 to the variable count of tile, the value is going to be 1 for every single tile instances but it is no longer have any effect on the position because you set this value after you set the position.
I don’t understand what are you trying to achieve here that doesn’t work.
If you want each instance to be created below each other on the Y axis, use a scene variable instead of object variable.
An object variable is unique and private to each instances, you can read about this in the docs.
So unless you want each instances you create to overlap each other, it makes no sense what you doing.
Okay, I realise the mistake but I’m still not able to achieve the intended behaviour. Help would be really appreciated. Thanks in advance!
I want to make a function for this so it is reusable. Same can be achieved without function.
I want to click button says for example button 1 at the bottom and create tiles of 1’s stacked one below the other. And follow the same for rest of the button and tile. Now using a scene variable does not address the following problem:
Initial Scene Variable(nextTileYPosition) = 50
+50 to Variable(nextTileYPosition)
This will create 1’s tile one below the other.
But now when I click on 10’s button below; the value of scene Variable(nextTilePosition) should be equal to 50. And at the same time store the Variable(nextTilePosition) for the 1’s tile so that when again clicking on 1’s button results in creating tile below the previously created tile and not from the position 50.
Similarly, I want to delete the tiles at the bottom and when I click on the button, it should start creating tile just below and not after space.
You can store only 1 value at the time in a scene variable. You need to use a structure, child variables to store multiple values. You can read about it on the wiki.
The idea is.
tileYPosition.1 = 50
tileYPosition.10 = 50
(1 and 10 is a child of tileYPosition)
if tile1 button is clicked:
create tile1 at position X;Variable(tileYPosition[“1”])
Do + 50 to Variable tileYPosition.1
if tile10 button is clicked:
create tile10 at position X;Variable(tileYPosition[“10”])
Do + 50 to Variable tileYPosition.10
And then when you delete just Do - 50 to tileYPosition.1 and .10
If you don’t understand structures then you can use a scene variable individually for each tile.
Thanks, I’ll try to implement through structures. Using different scene variable would mean to create the same action action and again.