Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

PowerQuest

A Nifty 2D Adventure Toolkit for Unity · By Powerhoof

Having trouble putting Combat System into Coroutine

A topic by cleveblakemore created 33 days ago Views: 83 Replies: 10
Viewing posts 1 to 3
(2 edits)

I am trying just to get all four commands for turn-based combat.

I want to call out to a co-routine and have it call a special dialogue tree for my main character and three companions.

Some extensions below but not relevant to my basic problem. I simplified it to show what I want to do.

Call each special dialogue until they are closed, then call the next one. When all orders filled, exit the co-routine.

Any help much appreciated. This is super simple code after having vast elaborate schemes with ten times this much code and this still doesn't work to simply display them one at a time.

It shows each "Display" debug text but only the last menu for "Goliath" ...

I need to know how to open a dialogue tree, wait for it to be closed, then execute the next one.

Code below ...

---------------------------------------------------------------------------------------------------

C.Jonah.TurnOrder = Character.TurnOrderMode.None;

C.Goliath.TurnOrder = Character.TurnOrderMode.None;

C.Eddy.TurnOrder = Character.TurnOrderMode.None;

C.NurseJan.TurnOrder = Character.TurnOrderMode.None;

   if(C.Jonah.IsDead() == false && C.Jonah.TurnOrder == Character.TurnOrderMode.None)

   {

    Display: Showing Jonah Combat Orders ...

    D.JonahCombatMenu.Start();

   // E.WaitUntil(()=>C.Jonah.TurnOrder != Character.TurnOrderMode.Pending);

   }

   if(C.Goliath.IsDead() == false && C.Goliath.JoinedParty == true && C.Goliath.TurnOrder == Character.TurnOrderMode.None)

   {

    Display: Showing Goliath Combat Orders ...

    D.GoliathCombatMenu.Start();

    //E.WaitUntil(()=>C.Goliath.TurnOrder != Character.TurnOrderMode.Pending);

   }

   if(C.Eddy.IsDead() == false && C.Eddy.JoinedParty == true && C.Eddy.TurnOrder == Character.TurnOrderMode.None)

   {

    D.EddyCombatMenu.Start();

    //yield return E.WaitUntil(()=>C.Eddy.TurnOrder != Character.TurnOrderMode.Pending);

   }

  if(C.NurseJan.IsDead() == false && C.NurseJan.JoinedParty == true && C.NurseJan.TurnOrder == Character.TurnOrderMode.None)

  {

   D.NurseJanCombatMenu.Start();

   //yield return E.WaitUntil(()=>C.NurseJan.TurnOrder != Character.TurnOrderMode.Pending);

  }

End

It's a bit unintuitive, but showing a Dialog Trees  isn't Blocking, (so that the player can still have control, and can save the game if they want, etc) 

So you might have to split your logic into separate functions for each Dialog tree, and call them one at a time, from UpdateBlocking. You can check if D.Current ==null there to see if there's one showing. D.Previous also shows the last dialogue tree used if that's helpful.


Actually, another alternative which might suit you better though is to use E.WaitForInlineDialog, which *is* a blocking function...

https://powerquest.powerhoof.com/interface_power_tools_1_1_quest_1_1_i_power_que...

(2 edits)

Thanks, that's cleared up a lot. I suspected Dialog was non-blocking.

I am going to try "WaitFor" as long as D.Current != null, that could be very simple and straightforward.

Can you tell me if the background animation of characters will continue just replacing that one line below each call to show the dialogue? 

Very simple fix. 

Thanks for your help, I am going to try this to see if it works. I may need to follow up with you.

My game under Powerquest is looking absolutely wonderful. I was trying to write my entire turn-based combat engine in game script instead of all the extra code I originally put it. If I am successful I would love to post a tutorial showing people how I built it using PowerQuest alone with some minor extensions. I know there are a lot of people who want a similar engine for their game content.

P.S. I didn't know it is was a bug or not - do commands like "E.WaitFor" need the yield return or does the script implement those automatically in the current version? I tried this and many variations, they were not working for me. Does "UpdateBlocking" need to be called in a loop while waiting?

Yeah you can't just WaitFor a regular Dialog Tree since then the player won't have control to be able to pick options.

 I'm AFK right now, but I'll try and show how you could put something in UpdateBlocking to start the next Dialog tree when the previous one finished if that'd be helpful.

(1 edit)

I tried some things but they didn't work.

It's a little more coding but I think the WaitInlineDialog might be the easiest way forward.

One thing about that ... can you send it a list of text strings instead of physically putting them in literals?

... of course ... param [] strings. Excellent,

This way I could compose the string(s) as I am doing now with the regular Dialog - only showing what is appropriate for the character in the actions they can take in combat.

I could not get any of that working right. Other dialogs getting called, etc.

Have another approach driven by GUI clicks on a menu to advance, going to try that one.

Yeah GUI clicks are blocking so should be fine. Surprised the Update Blocking code didn't work, but I didn't test it so probably just a dumb mistake on my part ;)


Btw if you use discord it's a *lot* more active than these itch forums, and easier to post code there too to get help when something's not working. 

Thank you for your help. Luckily I saved some of the code from the old approach, which was working well. 

Can I ask you one more question - since StartCutscene is such an easy way to disable all input and take the kind of control needed for the turn-based combat, is there a way to block any escaping the cutscene with the key as at present? I think I can get it all working if I wrap the combat sequence in a Start/End Cutscene. This was semi-working now but the user could escape out with the key.

All Start/EndCutscene() does is set the place that pressing the "Skip cutscene" button will skip to. So if you have particularly long ones you want the player to be able to skip, etc. It doesn't disable any input or anything. 

All "blocking" scripts are basically an uninteractive cutscene already. So just remove the Start/EndCutscene() functions so that you can't skip them ;)

(4 edits)

Alright, this might need fixes since the code is just off the top of my head, but this is a basic way i'd have done it with UpdateBlocking.

In Header:

int m_combatCharacterId = -1;

In UpdateBlocking():

// Only try and show a dialog if there's none showing
if ( D.Current == null ) 
{
    // Can add more characters here if necessary
    ICharacter[] characters = new ICharacter[]{C.Jonah, C.Goliath, C.Eddy, C.NurseJan};
 
    // Increment which character we're trying to show this update
    m_combatCharacterId++;
    if ( m_combatCharacterId >= characters.Length )
        m_combatCharacterId = 0;
     
    // Grab the character, and start their dialog tree if its time
    ICharacter character = characters[m_combatCharacterId];
    if(character.IsDead() == false && character.JoinedParty == true && character.TurnOrder == Character.TurnOrderMode.None)
    {
        Display: Showing {character.ScriptName} combat menu
        E.GetDialogTree(character.ScriptName+"CombatMenu").Start();
    }
}
End

Very clean!

I hope you will forgive me, my original code worked similar but I kept being puzzled by nuances of the implementation, I was never quite certain if the code was doing what I thought it was doing.

Going to try to drop this in to see if it works, thanks again.