Help with turn based selection/picking/timelines please

For questions about using Classic.

Post » Mon Jul 06, 2009 1:50 pm

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
B
1
G
3
Posts: 9
Reputation: 843

Post » Mon Jul 06, 2009 10:21 pm

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:

[code:25e099xi]
+ 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.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Tue Jul 07, 2009 1:24 am

Thank you, any advice on picking?
B
1
G
3
Posts: 9
Reputation: 843

Post » Tue Jul 07, 2009 6:20 am

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.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Tue Jul 07, 2009 6:34 am

I don't think System Compare puts objects in the SOL.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Tue Jul 07, 2009 9:06 am

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
B
1
G
3
Posts: 9
Reputation: 843

Post » Tue Jul 07, 2009 4:01 pm

[quote="Bandril":1zje96wc]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)[/quote:1zje96wc]

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.

[quote="Bandril":1zje96wc]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[/quote:1zje96wc]

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:

[code:1zje96wc]
+ 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]
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Tue Jul 07, 2009 5:11 pm

be careful with overlapping at offset, it's hard on the cpu.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Tue Jul 07, 2009 7:47 pm

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?
B
1
G
3
Posts: 9
Reputation: 843

Post » Tue Jul 07, 2009 9:19 pm

That's correct, it only really becomes a problem if you're checking overlap for hundreds of things in the same tick.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests