Mene-Mene![]() Member Posts: 1398 From: Fort Wayne, IN, USA Registered: 10-23-2006 |
Ok, I've written a little RTS game which you have 4 classes of characters you can recruit, which are automated. Its 1d, and very simple. I've got almost everything worked out, but my characters don't move seprately. I've used the For...Each Loop to make each character, but say the AI says move this Elf + 2 Location, it moves all 3 Elves! When I recruit a new Elf, I want that elf at the starting position, but instead it resets all the elves. My problem might lie in the fact that I created a Elf which is global without the for loop so it could be global. In other words, I'm kind of not really knowing what I'm doing. (Kind of Not really? What does this kid think he is?) ------------------ |
|
SSquared![]() Member Posts: 654 From: Pacific Northwest Registered: 03-22-2005 |
In what language is this written? Knowing this will really help in explaining it. Someone who is familiar with the language may also be able to give a code example. It sounds like you will need to maintain some type of collection (array) to hold all of your characters. Rather than making the Elf global, the collection is global. Going through the loop will just require you to iterate through the collection. Each Elf should be created only when it is necessary. When it's created, simply add it to the collection. Your Elf must also have something unique to differentiate it from all the others. Somehow, you will need to know which one is selected. The unique value can just be the current position, assuming no other Elf can occupy the same spot. When someone clicks on an Elf, you loop through the Elf collection until you find the match. |
|
Jari![]() Member Posts: 1471 From: Helsinki, Finland Registered: 03-11-2005 |
Hi mene-mene! Hmm this is tricky, with so little information given but it sounds like that you are using the foreach loop not just to create the elves but also to move them? ------------------ [VoHW] (Help needed) [Blog] - Truedisciple (mp3) |
|
Mene-Mene![]() Member Posts: 1398 From: Fort Wayne, IN, USA Registered: 10-23-2006 |
Firstly this is in BB. Here's a summary: Set up types Help function MainMenu Function This says if player chooses Elf, Elf.Character = New Character. Update PAI function This I will give you the exact code, don't worry about the other things except for the Elf, once I got the understanding, I can do the rest.
I hope this helps. ------------------ |