Systematic numbering of containers

For questions about using Classic.

Post » Mon Apr 14, 2008 8:02 am

I've been mulling this over for a day or two. The idea is to give each enemy container a unique ID number. This allows me to selectively activate individual containers for predetermined actions and movements.

For instance, for my game I have each level broken down into "encounters." Instead of everything being time critical, encounters allow me to set up challenges for the player and seamlessly string them together no matter how quickly the player completes his task. If, say, encounter 24 spawns two enemy containers I need to have full control over each to give them individual movement waypoints and firing instructions.

The way I'm considering doing this is using a global variable to create unique IDs, and assign them to each container on creation, then ++ the value.

[Begin Encounter]
+ Encounter == ##
- Spawn Enemy at (location)
- Set Enemy.ID to 'UniqueID'
- Add one to 'UniqueID'
(above will be more precise than simple add 1)
- Spawn Enemy at (location)
- Set Enemy.ID to 'UniqueID'
- Add one to 'UniqueID'

+ Value Enemy.ID == specific number A
- Set location of Waypoint to X.Y
- Set angle of movement toward Waypoint
- Set Enemy.speed to 30


...rinse and repeat for other instances.
So, does anybody have a better way of doing this that I might be overlooking? Is there a function of containers like this that is yet undocumented?

Thanks again, guys, gals.
B
3
S
2
G
4
Posts: 310
Reputation: 2,120

Post » Mon Apr 14, 2008 10:16 am

Containers select all in one go - so you only need an ID for one object in the container... and every object has a UID already built in :)

What do you use IDs for btw? I've never really needed to use them, considering we have 'For Each' and all...
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Mon Apr 14, 2008 10:30 am

Well, for each and all are fine when the intention is to work them in batch. I will still use containers for that purpose, in fact. However (and I haven't played with any tests yet), I also need to be able to create and manage individual containers on the fly. To do this, they need to have some form of separation, as shown in the pseudo code above. Let's say I create two new Enemy containers, but I want them to place their movement waypoint objects on separate sides of the screen, proceeding to meet up with them later. That's the intended effect.

Create new container, number it, perform actions on it individually if I want, all the while letting the containers do what they do best as far as batch commands go. Laser hits enemy container #4, destroy it. Special instructions to that container will simply be ignored, allowing the remaining instances to go about their tasks.
B
3
S
2
G
4
Posts: 310
Reputation: 2,120

Post » Mon Apr 14, 2008 10:48 am

A visual example:



B
3
S
2
G
4
Posts: 310
Reputation: 2,120

Post » Mon Apr 14, 2008 4:47 pm

You could use private variables to number them like so:

http://www.mediafire.com/?fy0uxzykvzy

The example uses RTS for simplicity's sake, but you don't need to.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Mon Apr 14, 2008 7:59 pm

Once again you come through for me, Deadeye. More cookie for you.

Shouldn't be very difficult at all to modify this to remove the random functions and create the specific encounters I have in mind. This whole thing has taught me a lot about containers, and I'm really enjoying the concept.

New dev journal and example caps coming soon. I'll be sure to recognize your contributions.
B
3
S
2
G
4
Posts: 310
Reputation: 2,120

Post » Mon Apr 14, 2008 11:50 pm

No prob.

When you get your encounter script system set up, please share. I'm curious to know how that would work. (Are you gonna load it from a text file or something?)
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Tue Apr 15, 2008 12:03 am

I've been considering that. It would certainly be cool to allow users to create custom levels without having to use Construct. The only thing that might hinder that is the way the thing currently handles copy-pasting events as text. There's no easy way to getting things first INTO a text file without copying every individual event individually solo and all by its lonesome individual self. Unless my inability to copy multiple events as text at once is yet another bug.
B
3
S
2
G
4
Posts: 310
Reputation: 2,120

Post » Tue Apr 15, 2008 12:32 am

Hmm. I've been mulling over how to use a script (not a Python script, more like a movie script) to control AI in NPC's. I'll have to give it some testing.

If you did get the load-script-from-file thing working, not only could you define the actions of the enemies and such, you could instruct your NPC comrades on which ships to take out. Heck, you could even put what they say into the script. Just be sure to have Slippy say "Ahhhg! I've got one on my tail!" like every ten seconds.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Tue Apr 15, 2008 1:39 am

You're precisely right. I'm glad you made me think about it again at this stage in development. I might has well design my objects and names with the intention of outside expandability, if only for the organizational improvements. I'll report back in two or three days.
B
3
S
2
G
4
Posts: 310
Reputation: 2,120

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests