How do I set variables according to the specifics of each instance of an object?

0 favourites
  • 6 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hello. I may be misunderstanding something fundamental about how events work, but I've been giving myself a headache searching through tutorials, and trying various adjustments without success, so I hope someone can help me here.

    Specifically, after one event creates several of an isometric tile object, transferring a bunch of variables over to them, I'm unsure how to come back to the lot of them and have them move according to some global variable or otherwise.

    It's hard to explain, but as you can see from the capx, there are two sections which don't apply to my tiles as I had intended, so the objects do not get separated, and the values are left empty for some of their variables.

    capx: drive.google.com/open

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Functions are bad for picking. For the first problem area, you'll need to move the events up to the for each for it to refer to each isotile in turn, assuming that's what you want.

    For the second problem area where it's in a function within a function, you can send the isotile UID through IsoSort as a parameter, and on IsoSort function reference IsoTile where IsoTile.UID = function.param(0). As it stands, it does not refer to any particular IsoTile.

    And just as final clarification, it runs everything in the for each loop first, so runs through those isotile creations, then moves down to event 24 and beyond without any specific isotile picked. Not sure on what the logic is doing, specifically the meaning of the perspective variable but that should hopefully give you some idea.

  • Thank you for the quick response! It was very helpful.

    I had to do some tweaks to get things running in the right order, but it seems to be working now. I just have one problem with the last part that sorts the Z-order of the tiles now.

    If I put it in the function, I believe the logic is that it can't really "sort" them because it's only seeing one at a time. After it "sorts" that one tile, only then is it handed another. But if I nest it anywhere else it doesn't want to work. The same problem is as before, where it's moving onto another event "without any specific IsoTile picked" as you said. (I just want it to pick all of them, once, each time the other stuff is activated).

    And if I just have it at the end, it works, but as you can see from the "test1" global variable in the debugger, it's working a little too hard. What would someone normally do in this case?

    capx: drive.google.com/open

  • There are several ways to do it I guess but a simple one would be to toggle a variable. In the FloorDraw function but outside of the for each loop, set a variable to 1. Then at the bottom you have your for each loop to run when variable=1. At the end of the for each loop you set the variable back to 0 so it runs once.

    Also your nested loop seems a bit wrong there, it will run both loops for each instance in turn, so you probably need to separate those out and have them run in order, not sure of its purpose though so couldn't say 100%.

  • Thanks again! That did it.

    As for both loops running for each instance, I'm not confident enough to say I didn't do it wrong, or that I didn't do it in a terribly roundabout way, but I think it's working as intended (until I break it again).

    Basically the first loop creates the tiles and transfers variables from the "map" to them -- ideally, later, this map could be some kind of text file or spreadsheet that I can import data from instead of being drawn by hand in the layout... if I were to ever figure out how to do something that complicated.

    Then, the second loop from the nested function. It's no longer dealing with the map tiles. It runs through each of the created IsoTiles, this time according to the view angle: the northernmost tiles will be at the top by default, but could be at the bottom if the view has been adjusted with the (][) bracket keys. Lastly the third loop sorts the z-order accordingly for each tile, which depends on the view angle and so has to be done last. Any time the view is rotated it redraws all these tiles again starting over at the first step, creating them from the map again. Sensible enough? Maybe? Who am I to say.

  • If it's working as intended then that's good, we'll say resolved :P

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)