Custom Quest Actions

Announcements, support questions, and discussion for Quest Machine.
GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Re: Custom Quest Actions

Post by GorkaGames »

Is it possible to create a new counter in real time? My idea is to create the counters on the Quest Action to simplify the previous work on the editor as much as possible, only with a string (new counter's name) reference.
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Quest Actions

Post by Tony Li »

GorkaGames wrote: Wed Feb 20, 2019 4:38 pm Is it possible to create a new counter in real time? My idea is to create the counters on the Quest Action to simplify the previous work on the editor as much as possible, only with a string (new counter's name) reference.
Yes. You can create a new counter and add it to the quest's counterList. Then you must enable its listeners. Something like:

Code: Select all

var counter = new QuestCounter(new StringField("chests"), 0, 0, 10, QuestCounterUpdateMode.Messages);
counter.messageEventList.Add(new QuestCounterMessageEvent(targetID, message, parameter, operation, literalValue));
quest.counterList.Add(counter);
counter.SetListeners(true);
Since you're doing all this, you might want to create the entire quest at runtime using the QuestBuilder class. Otherwise saving and loading may become a problem since the number of counters may not match. This post has an example.
GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Re: Custom Quest Actions

Post by GorkaGames »

Nooo :) I came from coding my own quest system !!! And it's crazy, that's the reason I choose this.
But I'm trying to create the best workflow when I delegate this work to the Level Designer, I want him to do the quests fast and without errors building as much as we can and avoiding iterating staff. We may end up building up to 100 quests.... and that's a lot of work on the editor :)

Ok, I tried with the code you sent me but: targetID, message, parameter, operation, literalValue are in red on Visual Studio..... it doesn't recognize them. What do I have to do it?


Regarding the number of counters may not match, that's a issue.....

Another option would be to leave the iteration (counters) control on my spawners and Iteractable components and only having a Conditional Action when my counter has reached the Max. On that way I need much less work on the editor (while maintaining all the logic on the visual editor)...
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Quest Actions

Post by Tony Li »

Okay, I think I understand what you want to do.

I think design-time tools will be better than runtime tools.

This is on the roadmap. I've been gathering examples from feedback.

For example, to add "require return to complete" to a hand-written quest, currently you must add a new Condition node. Then you must add a MessageQuestCondition that listens for the Discuss Quest message.

It would be nice to have a button that automatically adds all of this.

Likewise, for counter quests, it would be nice to have a dialog wizard where you can fill in some info and it will create the basic quest for you -- nodes, HUD text, etc.

Would these be useful?
GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Re: Custom Quest Actions

Post by GorkaGames »

Yes sure, I know you want to able the developer to customise as much as possible but the editor right now has too many fields to fill up for "Basic " staff (Nodes) that are the ones you make 90% of the time for making a big puzzle (all quests)

As you are asking me for feedback, in the priority list:

- Copy / paste nodes. This is a must.
- Template Nodes. Most of the time you just want an action and condition with counter (For just one can be counter = 1). and a Parameter for a message. Having a template that autogenerates the action, condition, counter (this is the most annoying thing, having to go to another screen to create a new counter and a new message) and the parameter (same string name than counter to simplify) and the UI in format: "Chests: 3 of 10" would be great. This is what I'm trying to do, customise my actions and condition nodes, and being able to generate the UI. My next step is auto generate also the counters with the same parameter.
- The only one button for pre filled nodes as the "require return to complete" would be great also.

I think this approach can be used by most of the people, as you can create very long and complex quest just joining lots of this "Template" nodes.

Just my cup of tea :)

PS:
Just to remind you if you can give me a hand with this:
Ok, I tried with the code you sent me but: targetID, message, parameter, operation, literalValue are in red on Visual Studio..... it doesn't recognize them in:
counter.messageEventList.Add(new QuestCounterMessageEvent(targetID, message, parameter, operation, literalValue));.
What do I have to do it?
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Quest Actions

Post by Tony Li »

Hi,

I'll try to get copy/paste and templates/shortcut buttons into the next update.
GorkaGames wrote: Thu Feb 21, 2019 6:31 amJust to remind you if you can give me a hand with this:
Ok, I tried with the code you sent me but: targetID, message, parameter, operation, literalValue are in red on Visual Studio..... it doesn't recognize them in:
counter.messageEventList.Add(new QuestCounterMessageEvent(targetID, message, parameter, operation, literalValue));.
What do I have to do it?
I wasn't sure that you wanted to continue with that, since adding counters at runtime will cause problems with saving and loading.

But if you want to continue, see the QuestCounterMessageEvent API reference. The parameters are:

QuestCounterMessageEvent (StringField targetID, StringField message, StringField parameter, Operation operation, int literalValue)

Example:

Code: Select all

new QuestCounterMessageEvent(new StringField("carrots"), new StringField("Got"), new StringField("Carrot"), 
    QuestCounterMessageEvent.Operation.ModifyByLiteralValue, 1);
GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Re: Custom Quest Actions

Post by GorkaGames »

Thanks, now works great. The counter adds in real time and refresh in the HUD.

Yes, regarding to adding counters at runtime will cause problems with saving and loading, I may use them only for UI HUD and I'll have now the "Real" counter on my scripts. Therefore I'll send only one notification to the custom condition quest once my "real" counter reaches the max. value. I'll save my "real" counter with your saver system.

I think that working like this I won't have problems, what do you think?
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Quest Actions

Post by Tony Li »

Certainly test it, but it sounds like it should work.

I'll give priority to the editor features. In case you run into any issue with this approach, the new editor features will make it quicker to add counters at design time.
GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Re: Custom Quest Actions

Post by GorkaGames »

Tested, it works fine.

Now I want to save my counter, but as in the custom saver you helped me to code I return actually the spawner's state as enum, how do I add the int counter? I want to save the enum (state) and the int (counter). Same for loading....


public override string RecordData()
{
/// This method should return a string that represents the data you want to save.
/// You can use SaveSystem.Serialize() to serialize a serializable object to a
/// string. This will use the serializer component on the Save System GameObject,
/// which defaults to JSON serialization.
///

var spawnerPoolOnlyOnceParenttionSpot = GetComponent<SpawnerPoolOnlyOnceParent>();
if (spawnerPoolOnlyOnceParenttionSpot == null)
{
Debug.LogError("SaverChest.RecordData: No encontré SpawnerPoolOnlyOnceParent en " + name, this);
return string.Empty;
}
return ((int)spawnerPoolOnlyOnceParenttionSpot.EstadoSpawnerParentActual).ToString();


Loading:

spawnerPoolOnlyOnceParent.RefreshStateSaver((EstadoSpawnerParent)SafeConvert.ToInt(data));
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Quest Actions

Post by Tony Li »

Hi,

Look at ActiveSaver for an example.

Define a serializable class and object to hold the data:

Code: Select all

[Serializable]
public class Data {
    public MySpawnerEnum enumValue;
    public int i;
}

public Data m_data = new Data();
In RecordData(), set m_data's variables and return its serialized version:

Code: Select all

public override string RecordData() {
    m_data.enumValue = ???; // (enum value to save)
    m_data.i = ???; // (int value to save)
    return SaveSystem.Serialize(m_data);
}

In ApplyData(), deserialize it:

Code: Select all

public override void ApplyData(string s) {
    if (string.IsNullOrEmpty(s)) return;
    var data = SaveSystem.Deserialize<Data>(s, m_data);
    if (data == null) return;
    m_data = data;
    ??? = m_data.enumValue; 
    ??? = m_data.i;
}
Post Reply