Functions, Booleans, and Logic: Oh my!

0 favourites
  • 8 posts
From the Asset Store
100 items casual and logic games. All icons are of a high quality.
  • I am really stumped here, gang.

    I am working on a JRPG-style combat system.

    There are three types of Skills: Block, Fight, and Magic.

    What I would like to happen:

    Player selects a skill.

    Player selects a target.

    AI selects a skill.

    AI selects a target.

    (So far, so good. The program does things more-or-less correctly up to here)

    All Block Skills resolve: Skill name displays, animation plays, numbers adjust.

    (This is where things start to go wrong)

    All Fight Skills resolve, as above.

    All Magic Skills resolve, as above.

    Things I have tried:

    For these first few attempts, I set everything up as sub-events of a single function.

    -- At first, I just set a timer on events associated with resolving Fight skills. This worked, but if nobody selected any Block skills, then there were a couple seconds of dead air before the Fight stuff started happening. Not ideal.

    --I tried toggling a "blockDone" boolean once all the resolution steps for Block Skills were complete. This never worked. Couldn't even get Fight Skills to start resolving.

    -- I told my Fight skills to wait for the "blocksDone" signal. I attached the "blocksDone" signal to the end of the resolution events to Block Skills. This worked better. Fight Skills started processing immediately upon completion of Block Skills. However, if nobody selected any Block skills the Fight Skills would never start resolving, because no signal.

    My most recent attempt has involved:

    1) Calculating the number of skills of each type that have been selected.

    2) Toggling booleans when the number of skills of a given type is equal to zero, in order to skip unnecessary resolution steps.

    3) Running each type of Skill resolution as its own function.

    The results of this attempt have been more-or-less identical to my efforts to leverage Booleans when all of resolution was handled as a chain of sub-events for a single function. That is, Blocks do what they're supposed to. Fights never get off the ground.

    I believe the problem has to do with when the system asks for the status of my booleans, versus when the booleans toggle as part of event processing. However, after much howling and gnashing of teeth, I can't think of a way to restructure the events in order to achieve the objectives stated above. Plz help?

    drive.google.com/file/d/1jpfnlE5EW4MJcQ9Z8sx3hq23bihJoAgq/view

    Addendum: Is there a way to track the values of local variables in debug mode? I've just been using global variables, setting them equal to the local variables whenever the local values change, but this seems cumbersome.

    Also, sorry, I have no idea why the formatting on this post is so obnoxious.

  • I haven't looked at the project yet, but from what I can understand, you simply need to run your phases even if there are no actual actions to run. Account for that so that the blocks phase runs no matter what and does nothing except trigger the next phase if no one selected a block action.

    A little more complex, but you can also build a "stack" of actions to take in an array for a phase. Push them to an array, and delete them out of the the array when run. When the array size is 0, proceed to next phase.

  • The biggest obstacle seems to be in telling the compiler that one phase has ended, and another ought to begin. The first phase runs fine, but I can't get it to move on to the second phase in a way that handles multiple contingencies (ie both player and AI select Fight OR player selects Fight and AI selects Block).

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Your code seems to be ok up till the phase where you do the attacks. But I can't place what's amiss at that point. As you stated you have a lot of variables for the state, and it's tricky to debug where the logic error is.

    A slightly different way to go about it could be to have a single state variable to organize the different steps. I guess this is called a state machine.

    Anyways here's an example made from the free version. Although that probably made the events a bit odd looking in spots to get it to fit.

    dropbox.com/scl/fi/ugfnxtiht6kijgrqtqyq3/rpgBattle.c3p

    Could be useful for ideas possibly.

  • I would probably do something like this:

  • Your code seems to be ok up till the phase where you do the attacks. But I can't place what's amiss at that point. As you stated you have a lot of variables for the state, and it's tricky to debug where the logic error is.

    A slightly different way to go about it could be to have a single state variable to organize the different steps. I guess this is called a state machine.

    Anyways here's an example made from the free version. Although that probably made the events a bit odd looking in spots to get it to fit.

    https://www.dropbox.com/scl/fi/ugfnxtiht6kijgrqtqyq3/rpgBattle.c3p?rlkey=2igmwxg0953vcbqrv4vmf0stl&dl=0

    Could be useful for ideas possibly.

    Wow, this seems like it will be super useful! Thanks for putting it together. I will be using it to study up!

  • I would probably do something like this:

    Another aspect of the problem is that I have a hard time understanding which conditions and actions in Construct allow me to express logical structures like this. I've reviewed the documentation pretty extensively, but many of the explanations given seem to rely on prior knowledge of programming, which I don't really have.

    If you have suggestions about conditions that would allow the system to ask "is X pending", that would be a great boon to me.

  • If you have suggestions about conditions that would allow the system to ask "is X pending", that would be a great boon to me.

    It depends on the implementation. You can store all these skills in some data object, like an array or JSON. In this case you can read the array/json in a loop and check the "pending/completed" value of every record. If you decide to go this route, I strongly suggest JSON.

    Another option (which is less 'professional' but is actually easier to do in Construct) is to use a sprite with instance variables. Say, if there are 20 different skills in the game, you can put 20 instances of SkillSprite on the layout. They will only be used as data storage and can be invisible. For each SkillSprite instance you define a bunch of variables, for example SkillType=magic, IsSelected=true, IsProcessed=false, Priority=1 etc. Then in your functions you can easily filter and pick these instances. For example, this block of conditions will pick the next pending magic skill:

    SkillSprite compare value SkillType="magic"
    SkillSprite compare value isProcessed=false
    SkillSprite pick by highest priority
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)