Author Topic: global variable isn't recognized, help![SOLVED]  (Read 812 times)

hey guys, i'm using the monkey island template and i have this bool global variable that is by default set on false and can get turned to true by some npcs, changing their dialogue accordingly
it works fairly well for everything except for this one character that you can't normally talk to, but if you give it an item he starts a little conversation (not in a dialogue, at least at first, just back and forth messaging between player and npc). Thing is he should react accordingly if the global variable is set to true or false, but it only ever picks the option tied to "false" and doesn't seem to react to the variable changing.

i attached the script i have stripped of all the animation and dialogue stuff, but if you think it's not enough to figure out what's wrong i can include the whole thing.

the variable in question is called here "variable" the "charactermet" global variable is used to check if you met the character already, i included it just because it's the only other variable in the script.

thanks in advance for your help people!

Code: Adventure Game Studio
  1.  
  2.    // GIVE TO
  3.   else if (UsedAction(eGA_GiveTo)) {
  4.    
  5.     if (ItemGiven == iitem) {
  6.          
  7.         //dialogue & animation stuff
  8.  
  9.         }
  10.        
  11.          if (variable==true) {
  12.      
  13.         //dialogue & animation stuff
  14.  
  15.         charactermet = true ;
  16.         }
  17.        
  18.         else {
  19.        
  20.         //different dialogue & animation stuff
  21.  
  22.         charactermet = true ;
  23.         variable = true ;
  24.         }
  25.    
  26.     }
  27.  
  28.  
« Last Edit: 19 Mar 2017, 22:42 by Ardentsideburns »

Dualnames

  • AGS Baker
  • Rottwheelers
  • Pretty Badass
    • Dualnames worked on a game that was nominated for an AGS Award!
      Dualnames worked on a game that won an AGS Award!
Re: global variable isn't recognized, help!
« Reply #1 on: 19 Mar 2017, 02:32 »
is "variable" a global variable ?
No more military army stuff. I'm alive and back.

Re: global variable isn't recognized, help!
« Reply #2 on: 19 Mar 2017, 02:34 »
Quote
is "variable" a global variable ?

yep! and so is charactermet

Gurok

  • Rottwheelers
  • When life hands you lemons, combine them with the mop
    • I can help with AGS tutoring
    •  
    • Best Innovation Award Winner 2016, for improving and extending the AGS scripting language
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • Gurok worked on a game that was nominated for an AGS Award!
      Gurok worked on a game that won an AGS Award!
Re: global variable isn't recognized, help!
« Reply #3 on: 19 Mar 2017, 02:55 »
Please include the whole thing -- everything you stripped out and replaced with comments.

Re: global variable isn't recognized, help!
« Reply #4 on: 19 Mar 2017, 03:32 »
Quote
Please include the whole thing -- everything you stripped out and replaced with comments.

sure, if it helps.

Code: Adventure Game Studio
  1.      
  2.  
  3.  // GIVE TO
  4.   else if (UsedAction(eGA_GiveTo)) {
  5.    
  6.     if (ItemGiven == ipainkillers) {
  7.  
  8.         player.Say("buh.");
  9.           protagonist.LoseInventory(ipainkillers);
  10.           Oberon.LockView(120);
  11.           Oberon.Animate(0, 10, eOnce, eBlock );
  12.           Wait(20);
  13.           Oberon.LockView(116);
  14.           Oberon.Animate(0, 10, eOnce, eBlock );
  15.           Oberon.ChangeView(122);
  16.           Oberon.SpeechView=121;
  17.            cChar1.ChangeRoom (16, 150, 165);
  18.         cChar2.ChangeRoom (16, 400, 170);
  19.         cChar1.LockView(52);
  20.         cChar2.LockView(123);
  21.         cChar2.IgnoreWalkbehinds = true;
  22.         cChar1.IgnoreWalkbehinds = true;
  23.         cChar2.IgnoreWalkbehinds = true;
  24.         cChar1.ManualScaling = true;
  25.         cChar2.ManualScaling = true;
  26.         cChar1.Transparency=0;
  27.         cChar2.Transparency=50;
  28.         cChar1.LockView(52);
  29.         player.Say("blluh?");
  30.         cChar1.Transparency=50;
  31.         cChar2.Transparency=0;
  32.         cChar2.LockView(4);
  33.         Oberon.Say("bler.");
  34.         cChar2.LockView(110);
  35.         Oberon.Say("blah.");
  36.         Oberon.Say("bluhh");
  37.         }
  38.        
  39.          if (necroknowlbasic==true) {
  40.            cChar1.Transparency=0;
  41.         cChar2.Transparency=50;
  42.         cChar1.LockView(52);
  43.         player.Say("blahblah");
  44.         cChar1.Transparency=50;
  45.         cChar2.Transparency=0;
  46.         cChar2.LockView(4);
  47.         Oberon.Say("bleh!");
  48.         oberonmet = true ;
  49.         }
  50.        
  51.         else {
  52.         cChar1.Transparency=0;
  53.         cChar2.Transparency=50;
  54.         cChar1.LockView(53);
  55.         player.Say("blar");
  56.         cChar1.UnlockView();
  57.         cChar1.Transparency=50;
  58.         cChar2.Transparency=0;
  59.         Oberon.Say("bluh");
  60.                     cChar1.Transparency=0;
  61.                    cChar2.Transparency=50;
  62.         player.Say("blah");
  63.                  cChar1.Transparency=50;
  64.                  cChar2.Transparency=0;
  65.         Oberon.Say("blah ");
  66.         Oberon.Say("bluh");
  67.                    cChar1.Transparency=0;
  68.                    cChar2.Transparency=50;
  69.        player.Say("the demons?");
  70.                     cChar1.Transparency=50;
  71.                     cChar2.Transparency=0;
  72.        Oberon.Say("bluh");
  73.        Oberon.Say("blah ");
  74.                      cChar1.Transparency=0;
  75.                      cChar2.Transparency=50;
  76.        player.Say("bluhbluh");
  77.        player.Say("bluuhh");
  78.          cChar1.Transparency=50;
  79.         cChar2.Transparency=0;
  80.         cChar2.LockView(4);
  81.         Oberon.Say("bleeh");
  82.         oberonmet = true ;
  83.         necroknowlbasic = true ;
  84.         }
  85.    
  86.     }

Gurok

  • Rottwheelers
  • When life hands you lemons, combine them with the mop
    • I can help with AGS tutoring
    •  
    • Best Innovation Award Winner 2016, for improving and extending the AGS scripting language
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • Gurok worked on a game that was nominated for an AGS Award!
      Gurok worked on a game that won an AGS Award!
Re: global variable isn't recognized, help!
« Reply #5 on: 19 Mar 2017, 04:10 »
A few questions:
 - How did you create this global variable? Did you use the Global Variables section of the project explorer or export variables manually?
 - Can you do a global search for "necroknowlbasic" in your project and report back with the results? Go to Edit->Find All..., set Look In: to Current Project, put necroknowlbasic in the textbox and hit Find All.

Also, just a note. With the way it's currently structured, every item will give you the standard response and the painkillers will display some additional text before that. I'm not sure if that's what you're after. I tidied up your indenting to hopefully show you what I mean:
Code: Adventure Game Studio
  1. // GIVE TO
  2. else if (UsedAction(eGA_GiveTo))
  3. {
  4.         if (ItemGiven == ipainkillers)
  5.         {
  6.                 player.Say("buh.");
  7.                 protagonist.LoseInventory(ipainkillers);
  8.                 Oberon.LockView(120);
  9.                 Oberon.Animate(0, 10, eOnce, eBlock );
  10.                 Wait(20);
  11.                 Oberon.LockView(116);
  12.                 Oberon.Animate(0, 10, eOnce, eBlock );
  13.                 Oberon.ChangeView(122);
  14.                 Oberon.SpeechView=121;
  15.                 cChar1.ChangeRoom (16, 150, 165);
  16.                 cChar2.ChangeRoom (16, 400, 170);
  17.                 cChar1.LockView(52);
  18.                 cChar2.LockView(123);
  19.                 cChar2.IgnoreWalkbehinds = true;
  20.                 cChar1.IgnoreWalkbehinds = true;
  21.                 cChar2.IgnoreWalkbehinds = true;
  22.                 cChar1.ManualScaling = true;
  23.                 cChar2.ManualScaling = true;
  24.                 cChar1.Transparency=0;
  25.                 cChar2.Transparency=50;
  26.                 cChar1.LockView(52);
  27.                 player.Say("blluh?");
  28.                 cChar1.Transparency=50;
  29.                 cChar2.Transparency=0;
  30.                 cChar2.LockView(4);
  31.                 Oberon.Say("bler.");
  32.                 cChar2.LockView(110);
  33.                 Oberon.Say("blah.");
  34.                 Oberon.Say("bluhh");
  35.         }
  36.         if (necroknowlbasic==true)
  37.         {
  38.                 cChar1.Transparency=0;
  39.                 cChar2.Transparency=50;
  40.                 cChar1.LockView(52);
  41.                 player.Say("blahblah");
  42.                 cChar1.Transparency=50;
  43.                 cChar2.Transparency=0;
  44.                 cChar2.LockView(4);
  45.                 Oberon.Say("bleh!");
  46.                 oberonmet = true ;
  47.         }
  48.         else
  49.         {
  50.                 cChar1.Transparency=0;
  51.                 cChar2.Transparency=50;
  52.                 cChar1.LockView(53);
  53.                 player.Say("blar");
  54.                 cChar1.UnlockView();
  55.                 cChar1.Transparency=50;
  56.                 cChar2.Transparency=0;
  57.                 Oberon.Say("bluh");
  58.                 cChar1.Transparency=0;
  59.                 cChar2.Transparency=50;
  60.                 player.Say("blah");
  61.                 cChar1.Transparency=50;
  62.                 cChar2.Transparency=0;
  63.                 Oberon.Say("blah ");
  64.                 Oberon.Say("bluh");
  65.                 cChar1.Transparency=0;
  66.                 cChar2.Transparency=50;
  67.                 player.Say("the demons?");
  68.                 cChar1.Transparency=50;
  69.                 cChar2.Transparency=0;
  70.                 Oberon.Say("bluh");
  71.                 Oberon.Say("blah ");
  72.                 cChar1.Transparency=0;
  73.                 cChar2.Transparency=50;
  74.                 player.Say("bluhbluh");
  75.                 player.Say("bluuhh");
  76.                 cChar1.Transparency=50;
  77.                 cChar2.Transparency=0;
  78.                 cChar2.LockView(4);
  79.                 Oberon.Say("bleeh");
  80.                 oberonmet = true ;
  81.                 necroknowlbasic = true ;
  82.         }
  83. }

You can see how if (necroknowlbasic==true) has the same indentation as if (ItemGiven == ipainkillers). If you give painkillers, you'll get two chunks of text, currently.

Re: global variable isn't recognized, help!
« Reply #6 on: 19 Mar 2017, 04:24 »
well i created it using the global variables section of the project explorer. And i did the search and it appears well, every time i need to change it from false to true. there's many occasions for the player to change it to true, and it's supposed to stay that way.

and oh you're right!! when i tried giving him another item , and when i do the dialogue for the false state of the variable pops off. That must be it and it's absolutely not intended...the text in this section should only show up when the painkiller is given to the npc... can you guys help with this ? i can't figure what i did wrong...

Re: global variable isn't recognized, help!
« Reply #7 on: 19 Mar 2017, 04:30 »
oh, nevermind about the extra text on the item  thing, i realized i put one bracket too much in an attempt to see what was wrong with the script. Now i fixed it, (by removing the bracket before if(necroknowlbasic==true) and adding one at the end) but the problem about having the npc saying different things depending on the state of the variable necroknowlbasic still remains....

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on a game that was nominated for an AGS Award!
Re: global variable isn't recognized, help!
« Reply #8 on: 19 Mar 2017, 08:29 »
This line is useless necroknowlbasic = true ; where it is. Since you can only give the painkillers once, your next if/else  necroknowlbasic = true ;  will only run once, and will run the false statement if it's false, and the true if it's true, as in you turned it on someplace else in the script before you give the painkillers to the npc.

There are those who believe that life here began out there...

Re: global variable isn't recognized, help!
« Reply #9 on: 19 Mar 2017, 20:06 »
Quote
This line is useless necroknowlbasic = true ; where it is. Since you can only give the painkillers once, your next if/else  necroknowlbasic = true ;  will only run once, and will run the false statement if it's false, and the true if it's true, as in you turned it on someplace else in the script before you give the painkillers to the npc.

i'm not sure if i understand , but from what you said it sounds like it should work like i intended: if the player meets the npc and the variable hasn't turned true yet, this encounter will switch it to true, and if he doesn't encounter the npc and give him the item the variable still won't be true, and it will remain false. did i understand what you said wrong?

anyways, still trying to make this work but without success. i really don't get why in every other single instance when this happen it works like a charm, but in this particular case it doesn't.

like, this is another example, this happens in a dialogue after you reply to a character about the topic the necroknowlbasic  variable affects. It works perfectly.

Code: Adventure Game Studio
  1.  
  2. NPC: dialogue
  3.  
  4.  if (necroknowlbasic==true) {
  5.   player.Say("dialogue"); }
  6.    else {
  7.       player.Say("dialogue");
  8.       NPC.Say("dialogue");
  9.       player.Say("dialogue");
  10.       NPC.Say("dialogue");
  11.       player.Say("dialogue");
  12.  
  13.      
  14.       necroknowlbasic=true;
  15.      }
  16.  
« Last Edit: 19 Mar 2017, 20:07 by Ardentsideburns »

Re: global variable isn't recognized, help!
« Reply #10 on: 19 Mar 2017, 20:28 »
i noticed something while experimenting with various options, if i change

Code: Adventure Game Studio
  1.         if (necroknowlbasic==true)
  2.         {

to
Code: Adventure Game Studio
  1.         if (necroknowlbasic==false)
  2.         {

it always goes to the shorter option (the one right after  if (necroknowlbasic==true) ) instead of always going for the longer one. again, this is completely independent to which state the necroknowlbasic variable is on at that moment...

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on a game that was nominated for an AGS Award!
Re: global variable isn't recognized, help!
« Reply #11 on: 19 Mar 2017, 20:46 »
Please do this that Gurok suggested:
Quote
- Can you do a global search for "necroknowlbasic" in your project and report back with the results? Go to Edit->Find All..., set Look In: to Current Project, put necroknowlbasic in the textbox and hit Find All.

We can't see how and where you are using this variable, it's like walking blindfolded in a dark room feeling stuff and trying to guess what they are until you find that damn needle.

Quote
i'm not sure if i understand , but from what you said it sounds like it should work like i intended: if the player meets the npc and the variable hasn't turned true yet, this encounter will switch it to true, and if he doesn't encounter the npc and give him the item the variable still won't be true, and it will remain false. did i understand what you said wrong?

Erhmmm what?
Sorry, but I don't get it.
Your code up there is saying: If you give the painkillers you lose them and if the necroknowlbasic is true do A stuff, otherwise, if necroknowlbasic is true, you do B stuff and set the necroknowlbasic to true. Only you will never be able to run this necroknowlbasic true/false statement again. Unless you can pickup the painkillers again and then give it again (can you do that in game?).

Also I notice you are setting oberonmet = true in both statements, which means you can drop it from the  necroknowlbasic if/else check and just put it with the other code for the give painkillers.

If you're in doubt, you can add a debug line to the code right before your last closing bracket to the function:
Code: Adventure Game Studio
  1. Display("Variable necroknowlbasic is now set to: %d", necroknowlbasic);
  2.  

This will show you if the variable is set to 0 or 1 at the end of the function, you can also add the line at the start, and see at what state the variable is at the start and end.

EDIT: You can shorten the check by doing:
Code: Adventure Game Studio
  1. if (necroknowlbasic) // if the variable is true
  2.  
  3. if (!necroknowlbasic) // if the variable is NOT true
  4.  
(just a faster way to code)
« Last Edit: 19 Mar 2017, 20:49 by Cassiebsg »
There are those who believe that life here began out there...

Re: global variable isn't recognized, help!
« Reply #12 on: 19 Mar 2017, 21:19 »
i'm sorry if i'm not being clear... i'm really a super beginner in scripting and i always had trouble finding the logic behind code...

and yes, that particular exchange is one time only, if you give him the painkillers without the variable set to true you won't get that particular message ever again.As i said there are other places in the game where the variable can be switched to true, and even if you never get that particular exchange it's fine.

anyways i did the check as you suggested, i'll attach it here:


Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on a game that was nominated for an AGS Award!
Re: global variable isn't recognized, help!
« Reply #13 on: 19 Mar 2017, 22:16 »
I thought you said you created the variable in the global variables section of the project explorer. Yet, you seem to be setting it in line 798 of GlobalScript.asc !  8-0

GlobalScript and global variables section of the project explorer are NOT the same thing. Try deleting that line and creating it in the Global variables section of the project. It's the blue globe icon, if you're in doubt.
There are those who believe that life here began out there...

Re: global variable isn't recognized, help!
« Reply #14 on: 19 Mar 2017, 22:36 »
YES! thank you so much cassiebsg and gurok, that was it! now it works! to be perfectly clear i did create it on the project explorer, but earlier in the project i thought i had to include it into the script too , that's why i wrote it there . But for some reason, now that i removed that line the character does recognize if the variable is true of false it seems!

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: global variable isn't recognized, help![SOLVED]
« Reply #15 on: 20 Mar 2017, 11:19 »
So, just a quick addendum to the solution:
Yes, the issue was that there were two variables with the same name (the "global" one, created with the editor, and the one declared in the global sript).
But just in case some day you decide to stop using the Editor's "global" variables, and go for the global script variable solution, then be careful with the scope of variables -- watch out for all the export/import stuff. Just sayin'. Good luck for the rest of your game!