Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: vrazumijin on Sat 22/06/2024 02:30:50

Title: [SOLVED] I can't change variable values
Post by: vrazumijin on Sat 22/06/2024 02:30:50
Hello

So, there is a room with a rooster. If the main character talks to the rooster, the game should run one dialog
If the main character gives coffe to the rooster and talks to the rooster, the game should run another dialog
If the main character gives coffe to the rooster again and talks to the rooster, the game should run a third dialog.

For that, first i create a global variable (varGALLOCAFE) with value 1
Then, in the global script, I declare the variable and write two functions, one to use the inventory object on the character cGallo and another to talk to the character cGallo.

Like this

Code (AGS) Select
int varGALLOCAFE = 1;

function cGallo_Talk(Character *theCharacter, CursorMode mode) {
   if (varGALLOCAFE == 1) {
      dGallo1.Start();
      varGALLO=2;
      }
 
   if(varGALLOCAFE == 2) {
      dGallo2.Start();
      varGALLO=3;
      }

   if (varGALLOCAFE == 3)  {
       dGallo3.Start();
       }
}

function cGallo_UseInv(Character *theCharacter, CursorMode mode) {
        if (cEgo.ActiveInventory == iCafetera) {
            if (varGALLOCAFE==1) {   
                SetTimer(2, 300);
                cGallo.Walk(800, 900, eBlock, eWalkableAreas);
                cEgo.Walk(870, 900, eBlock, eWalkableAreas);
                varGALLO=2;
                }
            if ((varGALLOCAFE==2) && IsTimerExpired(20))  {
                SetTimer(2, 300);
                cGallo.Walk(800, 900, eBlock, eWalkableAreas);
                cEgo.Walk(870, 900, eBlock, eWalkableAreas);
                varGALLO=3;
                }
            if ((varGALLOCAFE==3) && IsTimerExpired(20)) {
                cEgo.Say("Creo que ya es suficiente");
                 }
}

And it doesn't work, when the main character first give coffe to the rooster, they move to the expected place, but the first dialog remains the one that appears.

Can someone explain what I'm doing wrong?
thanks
Title: Re: I can't change variable values
Post by: Crimson Wizard on Sat 22/06/2024 02:41:49
You maybe are mixing 2 variables, you are checking varGALLOCAFE variable, but change varGALLO.

Another thing that I must point out: that you are using wrong combination of "if" commands. In your current script "cGallo_Talk", it first checks "if (varGALLOCAFE == 1)", there it sets varGALLOCAFE = 2. Then it checks "if(varGALLOCAFE == 2)", but it is already set to 2, so it will run the second case right away, and so on.

It should be "if/else if" combination instead (in both functions):
Code (ags) Select
if (varGALLOCAFE == 1) {
else if (varGALLOCAFE == 2) {
else if (varGALLOCAFE == 3)  {

In this case script will only run one of these choices, and ignore others.
Title: Re: I can't change variable values
Post by: vrazumijin on Sat 22/06/2024 02:57:20
 :grin:  Thanks a lot, I fell stupid, but at the same tame released. I was going crazy. Time to go to bed.