global variable isn't recognized, help![SOLVED]

Started by Ardentsideburns, Sun 19/03/2017 01:39:14

Previous topic - Next topic

Ardentsideburns

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: ags
 
   // GIVE TO
  else if (UsedAction(eGA_GiveTo)) {
    
    if (ItemGiven == iitem) {
          
        //dialogue & animation stuff 

        }
        
         if (variable==true) {
      
        //dialogue & animation stuff 

        charactermet = true ;
        }
        
        else {
        
        //different dialogue & animation stuff 

        charactermet = true ;
        variable = true ;
        }
   
    }


Dualnames

Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Ardentsideburns

Quoteis "variable" a global variable ?

yep! and so is charactermet

Gurok

Please include the whole thing -- everything you stripped out and replaced with comments.
[img]http://7d4iqnx.gif;rWRLUuw.gi

Ardentsideburns

QuotePlease include the whole thing -- everything you stripped out and replaced with comments.

sure, if it helps.

Code: ags
      

 // GIVE TO
  else if (UsedAction(eGA_GiveTo)) {
    
    if (ItemGiven == ipainkillers) {
 
        player.Say("buh."); 
          protagonist.LoseInventory(ipainkillers);
          Oberon.LockView(120);
          Oberon.Animate(0, 10, eOnce, eBlock );
          Wait(20);
          Oberon.LockView(116);
          Oberon.Animate(0, 10, eOnce, eBlock );
          Oberon.ChangeView(122);
          Oberon.SpeechView=121;
           cChar1.ChangeRoom (16, 150, 165);
        cChar2.ChangeRoom (16, 400, 170);
        cChar1.LockView(52);
        cChar2.LockView(123);
        cChar2.IgnoreWalkbehinds = true;
        cChar1.IgnoreWalkbehinds = true;
        cChar2.IgnoreWalkbehinds = true;
        cChar1.ManualScaling = true;
        cChar2.ManualScaling = true;
        cChar1.Transparency=0;
        cChar2.Transparency=50;
        cChar1.LockView(52);
        player.Say("blluh?"); 
        cChar1.Transparency=50;
        cChar2.Transparency=0;
        cChar2.LockView(4);
        Oberon.Say("bler.");
        cChar2.LockView(110);
        Oberon.Say("blah.");
        Oberon.Say("bluhh");
        }
        
         if (necroknowlbasic==true) {
           cChar1.Transparency=0;
        cChar2.Transparency=50;
        cChar1.LockView(52);
        player.Say("blahblah");
        cChar1.Transparency=50;
        cChar2.Transparency=0;
        cChar2.LockView(4);
        Oberon.Say("bleh!");
        oberonmet = true ;
        }
        
        else {
        cChar1.Transparency=0;
        cChar2.Transparency=50;
        cChar1.LockView(53);
        player.Say("blar");
        cChar1.UnlockView();
        cChar1.Transparency=50;
        cChar2.Transparency=0;
        Oberon.Say("bluh");
                    cChar1.Transparency=0;
                   cChar2.Transparency=50;
        player.Say("blah");
                 cChar1.Transparency=50;
                 cChar2.Transparency=0;
        Oberon.Say("blah ");
        Oberon.Say("bluh");
                   cChar1.Transparency=0;
                   cChar2.Transparency=50;
       player.Say("the demons?");
                    cChar1.Transparency=50;
                    cChar2.Transparency=0;
       Oberon.Say("bluh");
       Oberon.Say("blah ");
                     cChar1.Transparency=0;
                     cChar2.Transparency=50;
       player.Say("bluhbluh");
       player.Say("bluuhh");
         cChar1.Transparency=50;
        cChar2.Transparency=0;
        cChar2.LockView(4);
        Oberon.Say("bleeh");
        oberonmet = true ;
        necroknowlbasic = true ;
        }
   
    }

Gurok

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: ags
// GIVE TO
else if (UsedAction(eGA_GiveTo))
{
	if (ItemGiven == ipainkillers)
	{
		player.Say("buh."); 
		protagonist.LoseInventory(ipainkillers);
		Oberon.LockView(120);
		Oberon.Animate(0, 10, eOnce, eBlock );
		Wait(20);
		Oberon.LockView(116);
		Oberon.Animate(0, 10, eOnce, eBlock );
		Oberon.ChangeView(122);
		Oberon.SpeechView=121;
		cChar1.ChangeRoom (16, 150, 165);
		cChar2.ChangeRoom (16, 400, 170);
		cChar1.LockView(52);
		cChar2.LockView(123);
		cChar2.IgnoreWalkbehinds = true;
		cChar1.IgnoreWalkbehinds = true;
		cChar2.IgnoreWalkbehinds = true;
		cChar1.ManualScaling = true;
		cChar2.ManualScaling = true;
		cChar1.Transparency=0;
		cChar2.Transparency=50;
		cChar1.LockView(52);
		player.Say("blluh?"); 
		cChar1.Transparency=50;
		cChar2.Transparency=0;
		cChar2.LockView(4);
		Oberon.Say("bler.");
		cChar2.LockView(110);
		Oberon.Say("blah.");
		Oberon.Say("bluhh");
	}
	if (necroknowlbasic==true)
	{
		cChar1.Transparency=0;
		cChar2.Transparency=50;
		cChar1.LockView(52);
		player.Say("blahblah");
		cChar1.Transparency=50;
		cChar2.Transparency=0;
		cChar2.LockView(4);
		Oberon.Say("bleh!");
		oberonmet = true ;
	}
	else
	{
		cChar1.Transparency=0;
		cChar2.Transparency=50;
		cChar1.LockView(53);
		player.Say("blar");
		cChar1.UnlockView();
		cChar1.Transparency=50;
		cChar2.Transparency=0;
		Oberon.Say("bluh");
		cChar1.Transparency=0;
		cChar2.Transparency=50;
		player.Say("blah");
		cChar1.Transparency=50;
		cChar2.Transparency=0;
		Oberon.Say("blah ");
		Oberon.Say("bluh");
		cChar1.Transparency=0;
		cChar2.Transparency=50;
		player.Say("the demons?");
		cChar1.Transparency=50;
		cChar2.Transparency=0;
		Oberon.Say("bluh");
		Oberon.Say("blah ");
		cChar1.Transparency=0;
		cChar2.Transparency=50;
		player.Say("bluhbluh");
		player.Say("bluuhh");
		cChar1.Transparency=50;
		cChar2.Transparency=0;
		cChar2.LockView(4);
		Oberon.Say("bleeh");
		oberonmet = true ;
		necroknowlbasic = true ;
	}
}


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.
[img]http://7d4iqnx.gif;rWRLUuw.gi

Ardentsideburns

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...

Ardentsideburns

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

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...

Ardentsideburns

#9
QuoteThis 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: ags


NPC: dialogue

 if (necroknowlbasic==true) {
  player.Say("dialogue"); }
   else {
      player.Say("dialogue");
      NPC.Say("dialogue");
      player.Say("dialogue");
      NPC.Say("dialogue");
      player.Say("dialogue");

      
      necroknowlbasic=true;
     }

Ardentsideburns

i noticed something while experimenting with various options, if i change

Code: ags
        if (necroknowlbasic==true)
        {


to
Code: ags
        if (necroknowlbasic==false)
        {


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

#11
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: ags

Display("Variable necroknowlbasic is now set to: %d", necroknowlbasic);


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: ags

if (necroknowlbasic) // if the variable is true

if (!necroknowlbasic) // if the variable is NOT true 

(just a faster way to code)
There are those who believe that life here began out there...

Ardentsideburns

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

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...

Ardentsideburns

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

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!
 

SMF spam blocked by CleanTalk