Trying to make a Quest System

Started by Narehop, Fri 20/04/2018 17:14:39

Previous topic - Next topic

Narehop

Hi guys, i'm trying to make a Quest System for my game but i've some problems with it.

i'm going to explain how it must work (sorry for my english):

0. In header's script i have this:
Code: ags

//import function open_menuQuest;
import function open_menuQuest();

//import function close_menuQuest;
import function close_menuQuest();

//import function openQuest(int a);
import function open_quest (int number);

//import function openQuest(int a);
import function close_quest (int number);

  // [x] is the totally numbers of quests have the game.
  //how to work with quests: 0-off    1-turn on     2-finished
  int arrQuest[2];


1. Enter on a Region for example and run this script (GUI named "gNewObjective" appears)
Code: ags

function open_menuQuest()
{
  gNewObjective.Transparency = 100;
  gNewObjective.Visible = true;
  gNewObjective.TweenTransparency(0.3, 0, eEaseInCubicTween, eNoBlockTween);
  a0000_bell_objective.Play();
}


2. We call a new objective (quest) and it appears too with our own function
Code: ags

function open_quest(int number)
{
  if(arrQuest[number] == 0)
  {
    gQuest.Visible = true;
    gQuest.TweenX(0.1, 0,  eEaseOutQuintTween, eNoBlockTween);
    int questY = 0;
    for(int i = 0; i < gQuest.ControlCount; i++ )
    {
      if(arrQuest[i]==1)
      {
        gQuest.Controls[i].Y = 20+(questY*30);
        questY++;
      }
    }
    //turn on quest
    arrQuest[number] = 1;
    gQuest.Controls[number].Y = 20 + (questY*30);
    gQuest.Controls[number].TweenX(1.0, 60, eEaseOutBackTween, eNoBlockTween);
  }
}



3. (optional) With a similar function we can finish our quests
Code: ags

function close_quest (int number)
{    
  arrQuest[number] = 2;
  gQuest.Visible = true;
  gQuest.Transparency = 100;
  gQuest.TweenTransparency(0.3, 0, eEaseInCubicTween, eNoBlockTween);
  gQuest.TweenX(0.5, 0,  eEaseOutQuintTween, eNoBlockTween);
  gQuest.Controls[number].TweenX(1.0, -800, eEaseInBackTween, eNoBlockTween, 1.0, eTweenSeconds );
  
  int questY = 0;
  for(int i = 0; i < gQuest.ControlCount; i++ )
  {
    if(arrQuest[i]==1)
    {
      gQuest.Controls[i].Y = 20+(questY*30);
      questY++;
    }
  }
}


4. And finishing we have to close our Quest GUI:
Code: ags

function close_menuQuest()
{
  gNewObjective.Transparency = 0;
  gNewObjective.TweenTransparency(1.0, 100, eEaseInCubicTween, eNoBlockTween, 3.0, eTweenSeconds);
  gQuest.Transparency = 0;
  gQuest.TweenTransparency(1.0, 100, eEaseInCubicTween, eNoBlockTween, 3.0, eTweenSeconds);
}


5. Now this code is where i'm going to call the functions:
Code: ags

  open_menuQuest();
  close_quest(0); //close quest number 0
  open_quest(1); //open quest number 1
  close_menuQuest();


Ok so, now i'm going to show how it works with ONE QUEST.


And now we close the first Quest and open a second Quest at the same time:


Here's the problem... In my code i said that i want to check if we have one or more Quests opened and put the next quest 20+(questY*30) in Y position. And obviously this doesn't work and i don't know why :(

If someone can help me to do this work fine... if you need, you can copy the code and try to run it.

Thank you so much.

Narehop


Snarky

Quote from: Narehop on Fri 20/04/2018 17:14:39
Here's the problem... In my code i said that i want to check if we have one or more Quests opened and put the next quest 20+(questY*30) in Y position. And obviously this doesn't work and i don't know why :(

Looks to me like it does work, you're just not thinking clearly about what you're telling it to do:
You remove the first quest, so the list is now empty.
Then you add the second quest, and it shows up in the first free slot (at the top).

If you want the second quest to show up in the second slot, you should add it to the list before you remove the first quest. Alternatively, you can add a delay, so it only shows up in the first slot after the first animation has finished and the first quest is gone.

Also, you shouldn't update the positions each time you add or remove an entry, unless you want exactly this behavior (other entries instantly move up or down). You should do it when you display the menu. (If you're going to add new quests in the middle of the list while it's being displayed, you probably need another state: a "save a space for this quest but don't actually display it yet" state.)

Finally, I should say that I think there are better ways to solve this whole task, but if you've found an approach that (almost) works for you, that's great.

Narehop

Quote from: Snarky on Sat 21/04/2018 10:29:05
Quote from: Narehop on Fri 20/04/2018 17:14:39
Here's the problem... In my code i said that i want to check if we have one or more Quests opened and put the next quest 20+(questY*30) in Y position. And obviously this doesn't work and i don't know why :(

Looks to me like it does work, you're just not thinking clearly about what you're telling it to do:
You remove the first quest, so the list is now empty.
Then you add the second quest, and it shows up in the first free slot (at the top).

If you want the second quest to show up in the second slot, you should add it to the list before you remove the first quest. Alternatively, you can add a delay, so it only shows up in the first slot after the first animation has finished and the first quest is gone.

Also, you shouldn't update the positions each time you add or remove an entry, unless you want exactly this behavior (other entries instantly move up or down). You should do it when you display the menu. (If you're going to add new quests in the middle of the list while it's being displayed, you probably need another state: a "save a space for this quest but don't actually display it yet" state.)

Finally, I should say that I think there are better ways to solve this whole task, but if you've found an approach that (almost) works for you, that's great.

I don't have any idea how to do this code better Snarky :(
Not always have to close and open Quests at the same time. Sometimes I'll open quests but no one were closed. So I can't make a delay for this question. I need to do this in real time.

Snarky

Quote from: Narehop on Sat 21/04/2018 10:38:52
Not always have to close and open Quests at the same time. Sometimes I'll open quests but no one were closed. So I can't make a delay for this question. I need to do this in real time.

The way around that is to have a separate function, something like replace_quest(int questToRemove, int questToAdd) that does it, with a delay. (You might need to add a delay parameter to open_quest(), and set it to 0 by default.)

Narehop

Quote from: Snarky on Sat 21/04/2018 10:55:27
Quote from: Narehop on Sat 21/04/2018 10:38:52
Not always have to close and open Quests at the same time. Sometimes I'll open quests but no one were closed. So I can't make a delay for this question. I need to do this in real time.

The way around that is to have a separate function, something like replace_quest(int questToRemove, int questToAdd) that does it, with a delay. (You might need to add a delay parameter to open_quest(), and set it to 0 by default.)

i'm gonna try it

Narehop

Quote from: Snarky on Sat 21/04/2018 10:55:27
The way around that is to have a separate function, something like replace_quest(int questToRemove, int questToAdd) that does it, with a delay. (You might need to add a delay parameter to open_quest(), and set it to 0 by default.)

I can't run it... I think, the problem is that my functions are running at the same time:

Code: ags

  open_menuQuest();
  close_quest(0);
  open_quest(1);
  open_quest(2);
  close_menuQuest();


Maybe I've to close Quest and make some delay before open_quest start to run. But if I try to do "Wait()" it doesn't work... i don't know if I try to do this with timer will be work correctly. What do you think?

SMF spam blocked by CleanTalk