Help with turn based selection/picking/timelines please

This forum is currently in read-only mode.
From the Asset Store
Selection frame like in RTS games, works both on mobile and desktop devices.
  • Hello all, I would like to congratulate the developers on building a very slick engine and a strong community.

    I need some help figuring out turn based movement/unit selection (picking) and time lines.

    What I expect to see happen here is members of the yellow family get selected by the basis of a comparison of a private id variable and a global temporary variable �

    intended Flow�

    Cap starts out with player turn enabled

    Player clicks the layout which sets a sprite at the mouse x/y � this sprite becomes the movement target for the yellow family of sprites.

    What should happen next is that a sprite should be highlighted in blue, then about 1 second latter the target sprite should be highlighted in red, then 1 second latter the sprite should move 128 pixels towards the target sprite, pause for 1 second move another 128 pixels then deactivate causing the blue and red overlays to move off screen and the next yellow family sprite to activate with same behavior and then the third.

    After all the yellow family sprites have moved, the AI turn is over and the user should be able to click the layout setting the target sprite to new location and if it were to the right side of the layout the yellow family sprites would all go through their move routine sequentially, players turn etc etc.

    Should be simple but somehow it is evading me. I do not have a strong understanding of timelines or functions (ideally I would like to wrap as much functionality as possible into functions).

    Any help or guidance appreciated and thank you.

    Cap can be found here:

    http://www.filedropper.com/timelinetest

  • I generally handle AI stuff with pv's called "mode" and "myTimer." For your turn-based stuff you could add a pv called "turn."

    Like so:

    + Object.Value('myTimer') greater than 0
        -> Subtract (1 * timedelta) from Object.Value('myTimer')
    
    + Object.Value('turn') = global('currentTurn')
    + Trigger Once
        -> Set Object.Value('mode') to "seek"
        -> Set Object.Value('myTimer') to 5
    
    + Object.Value('turn') = global('currentTurn')
        + Object.Value('mode') = "seek"
            -> Search for target
            + Target found
                -> Set Object.Value('mode') to "chase"
        + Mode = "chase"
            -> Move towards target
            + Distance to target less than whatever
                -> Set mode to "fight"
        + Mode = "fight"
            + Every X Milliseconds
                -> Shoot bullets
            + Target destroyed
                -> Set mode to "seek"
    
    + Turn = global('currentTurn')
    + myTimer less than 0
        -> Set mode to "rest"
        -> Add 1 to global('currentTurn')
    [/code:25e099xi]
    
    Etc.  Obviously this is a simplified example but the basic method works.
  • Thank you, any advice on picking?

  • You can also use the timer behavior for AI.

    About picking: you can use System-Compare, that one allows you to compare anything. The objects that satisfy the comparison will be picked.

  • I don't think System Compare puts objects in the SOL.

  • Thank you everyone (especially Deadeye); working with your advice I now have a working prototype � any suggestions on refactoring this into functions? I am a little thrown off by how functions work and could use some examples (wiki did not really clarify things for me)

    This is a grid based game (128x128)- I cannot use any of the prepackaged movement behaviors as they do lend themselves top down well turn based movement (as I understand it) � the grid movement behavior did not seem useful to me � please correct me if am missing something vital.

    I have seen �detectors� mentioned here on the forums several times, could someone explain how they work briefly? My understanding is that they are objects added to a container � for use as path finding aids (checks for overlapping terrain etc) they are what I want to be using correct?

    Posting a link to the new cap file for suggestions/comments � thanks again

    http://www.filedropper.com/aitest

  • Thank you everyone (especially Deadeye); working with your advice I now have a working prototype � any suggestions on refactoring this into functions? I am a little thrown off by how functions work and could use some examples (wiki did not really clarify things for me)

    Functions are best used if you are performing the same set of actions over and over again (as in multiple times per tick), or if you're constantly typing out the same bit of complicated math or something. They're also handy if you want to perform an action after a specific amount of time ("Call function after delay," which is what I generally use them for. I find that they're most handy in this manner).

    It might help if you said exactly what you needed functions for. Just saying "I want to use functions" is kind of ambiguous. Everyone's event making style is different, so I really don't use functions all that often because I don't need to.

    I have seen �detectors� mentioned here on the forums several times, could someone explain how they work briefly? My understanding is that they are objects added to a container � for use as path finding aids (checks for overlapping terrain etc) they are what I want to be using correct

    Generally speaking, detectors are pretty much obsolete, because you can use "Overlapping at offset," which means you can detect collisions and whatnot outside the normal bounds of the sprite area. When you check for overlap at an offset, it basically shifts the entire sprite temporarily by however many pixels you indicate, checks for collision, then puts the sprite right back where it was.

    I say "generally" speaking because there are still times when you may need specially shaped or specifically placed detectors, depending on what it is you want to detect and how you want to detect it. For instance, if you want a platforming enemy to jump over small objects, but not large objects, then the easiest way to do that would be to place a thin "head detector" at the top of the sprite that sticks out beyond the left and right edges, then do something like so:

    + Always
        -> DetectorHead: Set position to (Enemy.X, Enemy.Top)
    
    + Enemy is overlapping Ground at offset (2, 0)
    + OR
    + Enemy is overlapping Ground at offset (-2, 0)
        + NOT DetectorHead is overlapping Ground
            -> Jump
    [/code:1zje96wc]
  • be careful with overlapping at offset, it's hard on the cpu.

  • regarding functions - I am just used to tucking everything in functions/methods, habit I guess.

    As far offset testing, the CPU burden shouldn't be a problem in a turn based setting - as only one unit will be pathing/collision checking at a time correct?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That's correct, it only really becomes a problem if you're checking overlap for hundreds of things in the same tick.

  • you can use System-Compare, that one allows you to compare anything. The objects that satisfy the comparison will be picked.

    Just to clarify (in case people find this thread via search in future etc): system compare deliberately does not do any picking at all. However, you can simulate the effect of picking by putting a 'for each' above it. Other comparison conditions, eg. in the sprite object, pick normally.

    be careful with overlapping at offset, it's hard on the cpu.

    No more so than ordinary overlaps, which don't usually bottleneck performance.

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