User Tag List

Results 1 to 2 of 2

Thread: Problem with scope and AI behaviors

  1. #1
    Clicker Fusion 2.5

    Join Date
    Feb 2014
    0 Post(s)
    0 Thread(s)

    Question Problem with scope and AI behaviors

    I'm trying to figure out the best way to set up the AI behaviors for the NPC:s in my game, but I keep running into problems because the different NPC instances gets mixed up. So, for example, an enemy designed to just move back and forth on the ground like a Goomba may start spontaneously flying when a flying enemy is spawned.

    As it is now, I have set up the AI events in the following way:

    1) Once an NPC is created, it's given a unique ID value, and one of its alterable strings named "Main AI" is set to the name of a specific AI routine, for example "Ground Pacing".

    2) On every frame, a ForEach loop called "AI" is run on the NPC:s. If the NPC:s "Main AI" is different than "", a function with the name of the AI behavior is triggered (so, in this example, "Ground Pacing".)

    3) Here's where the problems with my method start, because with each event in the AI function, I have to limit the scope and specify which NPC instance should be affected, by refering to it's ID value. Each NPC instance also have a sprite and a PMO object assigned to them, so I need to limit the scope on those objects as well on every event that affects them. If I forget to limit the scope on just one single line, it will result in bugs like the unwanted flying enemy.

    4) The first time the Main AI Function is triggered, a sub-function called "AI Setup" is triggered, which sets up the initial values of the AI main behavior, and assigns a sub-behavior. Then, another sub-function is triggered, named from the main behavior and sub-behavior, separated by a "/". For example: Ground Pacing/Walking Left.

    5) In the sub-behavior function, movements and actions of the NPC are triggered, and checks are made to see if the conditions are met for changing to another sub-behavior.

    So, my problem is: how do I limit the scope for the affected objects, without having to do it again and again, in every single event of every AI behavior I program? Is it possible in any way to, say, limit the scope for the NPC object, sprite and PMO in the first event of the Main AI function ("Ground Pacing"), so that it keeps the scope in the following events and sub-functions?
    Or, does anybody ave any other suggestions on how I can set up the AI behaviors differently to avoid the problem?
    I'm dead tired of the constant bug testing and having to copy/paste the "ID of 'NPC' = Current NPC ID" event all over the AI code.

  2. #2
    Clicker Fusion 2.5 DeveloperiOS Export Module
    butterfingers's Avatar
    Join Date
    Apr 2012
    6 Post(s)
    0 Thread(s)
    Hey dude,

    If it's any consolation, I've struggled with this for a long time too.

    There are loads of great MMF examples out there for AI, but few of them are the whole scope of a game, and it gets big and messy for sure.
    I had similar issues with having to do loads of scoping on Not A Hero, and there are some workarounds and tricks, but this stuff is inherently complicated and it's really hard to give advice without some actual eyes on your code.
    Without the benefit of an MFA I'm a little confused about your method though:

    -> Once an NPC is created, it's given a unique ID value
    -> a ForEach loop called "AI" is run on the NPC:s
    -> I have to limit the scope and specify which NPC instance should be affected, by refering to it's ID value

    If you're using a ForEach loop on the NPCs then you shouldn't need the ID check - ForEach will cycle through each of the NPCs in turn automatically?

    Can I also clarify if when you're saying "Function" and "SubFunction" are these actual names of things in extensions - Like the "Function Extension", or just a term you're using for bits of code?

    Happy to help if I can

Similar Threads

  1. For Each Loops and Overlap Scope
    By rocketappliances in forum Fusion 2.5
    Replies: 4
    Last Post: 14th April 2015, 05:08 PM
  2. zoom/scope in ios (has anyone got a method?)
    By Tuna in forum iOS Export Module Version 2.0
    Replies: 8
    Last Post: 15th April 2013, 05:05 PM
  3. iSniper scope for Ebolaboy
    By stuckboy in forum File Archive
    Replies: 7
    Last Post: 6th June 2007, 09:55 AM
  4. Wobbly sniper scope?
    By EbolaBoy in forum Multimedia Fusion 2 - Technical Support
    Replies: 9
    Last Post: 5th June 2007, 06:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts