Sign in to follow this  

Completing objectives in order.

This topic is 3870 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am having a problem with my objectives completing in order. Each level has different objectives but they all end with an exit objective. However my problem is I can run to the exit (which activates the exit trigger) then go and do objective "A" and as soon as I complete "A" the round ends. I am suppose to have to go back to the exit to complete the round. I am looking for something to put in to force the correct order. I am programming in C++ and I have tried to add an objectiveComplete bool command and set it to true at the end of objective "A" and then use an IF statement in the exit code so it won't run the code until the objective is complete however it did not work. Any thoughts on what I can do? Thanks in advance.

Share this post


Link to post
Share on other sites
Your logic sounds more-or-less correct, so it's most likely your implementation that is broken.

I would first make sure I have a means to ask the level if a given objective (represented by an objective identifier, which can be a string, a number, whatever) has been completed, e.g., IsComplete(ObjectiveA), or something. Then have each objective simply store a list of objective identifiers that are prerequisites. For example, in a simple two-objective scenario, the "exit" objective may depend on the "save the queen" objective.

Now, when you are about to mark an objective as complete or not (for example, when the user enters the area that would complete the exit objective and thus finish the level) you first call IsComplete() for all objectives in the list of prerequisites. If any prerequisite objectives are not complete, then this objective cannot be completed. You can notify the player if you want, or just silently fail to mark the objective as complete.

If that's basically what you're doing (it sounds like it might be), then the problem is your implementation and you'd need to show some code or step through it in a debugger.

Share this post


Link to post
Share on other sites
In general you can solve this kind of problem using a Finite State Machine.

With only two objectives you don't really need to formalise it as a state machine (although your code will be equivalent to having a state machine). However, if you had several objectives, some of which can be skipped depending on whether others were completed, a state machine is a good approach.

Unfortunately a quick Google search doesn't show up too much in the way of a clear, non-theoretical introduction to state machines. About the best one I can find is here:

http://ai-depot.com/FiniteStateMachines/FSM.html

This page is probably most relevant to you:

http://ai-depot.com/FiniteStateMachines/FSM-Practical.html

I recommend reading up on finite state machines, as they are a useful tool for anyone who wants to write software.

Share this post


Link to post
Share on other sites
Thanks for the info guys. Do to my NDA I can not post code which makes it hard for me to get help outside my team. (in case you are wondering y I did not contact my team is that they have bigger issues to take care of as we are about to hit the deadline and I figured guys here can help me with the smaller issues.)

Turns out there already is a objectiveComplete command they just called it something else and it had a bug in it that caused a complete as soon as you triggered the zone with or without completing the other objectives.

BTW in the end I did code it right as I thought it just was still buggy from the other error.

Thanks again.

Share this post


Link to post
Share on other sites
I still need help. I am trying to fix the other code that has the error. I thought I had an understanding of list sizes but maybe i don't.

I have dependencies.empty() and dependencies.end ()

If dependencies.empty () is true then the objective completes.
when dependencies iterates to the end then the objective is also complete.

what I want to know is when dependencies.end () reaches 0 could the program also think that it equals dependencies.empty ().

I think that it may only because if I comment out the complete function on the dependencies.empty () then the map doesn't complete even when the dependencies reaches the end.

The other thought I had was maybe that as the map loads it declares dependencies empty before the dependencies load therefore declaring the exit objective complete due to the dependencies.empty ().

Share this post


Link to post
Share on other sites
Are you familiar with the use of your debugger? This is exactly the sort of issue where you should be able to set a breakpoint on the relevant code, step through the code as it is run, and see what is going wrong.

If for some reason a debugger is not available, you could also put some tracing code in an look at what happened afterwards (aka "debugging through printf").

If you are not familiar with your debugger, now is a perfect time to learn. You won't get far as a C++ programmer without decent debugging skills.

Good luck,
Geoff

Share this post


Link to post
Share on other sites

This topic is 3870 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this