bool flag

Started by Alen101, Wed 06/01/2016 06:05:31

Previous topic - Next topic

Alen101

Character Bern :grin: makes a little talk if you go to his room.
I have a phone in other room. So if the player :-D want to talk to the phone, he can.
Every time player :-D get the phone, phonecall 1 dialog plays.
But the player  :-D can only see phonecall 2 dialog, if he go to Bern's room, and listen to a character Berns talk. :grin: (The talk activates when the player enters the room)


Im trying to do that,

So to solve the problem i have tryed this:

I put this in global script:
Code: ags
bool planb = false;


When Bern :grin: do certain talk it activates a flag. So, i ve putted this code at the end of the talk:
Code: ags
bool planb = true;


Then, later in the game, when player :-D talks to the phone,
if that boolean is set to false(:grin: Bern's first talk was not seen by the player)   
if that boolean was set to true(:grin: Bern's first talk was seen by the player)   
and it activtes the phonecall 2 dialog.
This is what i want to do because i want to make sure that phonecall 2 dialog only activates if the player have seen the Bern's talk

So then ive tried this in the room containing the phone scripting:
Code: ags

if (phoneflag01 == 1 && planb = true )
        {
      player.Say("phonecall 2 dialogs");
      
        }

But it gives me this error:

Code: ags
room7.asc(184): Error (line 184): undefined symbol 'planb'




Almost the full length scripting:
Code: ags

// room script file
int phoneflag01 = 0;




This goes inside a function called on NumberClick
{

else if (telephoneNumber == ERIC_NUMBER) 
 {
 player.Say("Hello eric.");
 cEric.Say("I dont have time bye.");
 }
    
   
    else if (telephoneNumber == DELIVERY_NUMBER)
{
    if (phoneflag01 < 2) 
    {
    phoneflag01 += 1;
    }
  
         if (phoneflag01 == 0) 
         {
         player.Say(" phonecall 1 dialog, version 01.");
         }
  
  
            if (phoneflag01 == 1) 
            {
            player.Say(" phonecall 1 dialog, version 02.");
            }
 
 
               if (phoneflag01 == 2) 
               {
               player.Say(" phonecall 1 dialog, version 03.");
               }

          
      
                    if (phoneflag01 == 1 && planb = true )
                    {
                    player.Say(" phonecall 2 dialog");
                    }

                           else  
                           {
                           player.Say("tone");
                           }

}



Any help would be great!


Khris

You should define global variables in the project tree section of the same name for now.
If you must do it in script, it should look like this:

GlobalScript.ash
Code: ags
// import line, which must state the type
import bool planb;


GlobalScript.asc
Code: ags
// declaration, which states the type and optionally, an initial value
bool planb = false;  // bools in AGSScript are false by default anyway
// export line, which needs just the name
export planb;


You can now change the value by using
Code: ags
  planb = true;
The variable already exists, so restating it's a bool is not necessary (and not allowed, anyway).

And again, proper indentation is something you should look into. Whenever you use a {, indentation embiggens. When you close the block using }, it deembiggens.
Code: ags
  if (phoneflag01 == 0) 
  {
    player.Say(" phonecall 1 dialog, version 01.");
  }
  
  else if (phoneflag01 == 1) 
  {
    if (planb)
    {
      player.Say(" phonecall 2 dialog");
    }
    else
    {
      player.Say(" phonecall 1 dialog, version 02.");
    }
  }
  
  else if (phoneflag01 == 2) 
  {
    player.Say(" phonecall 1 dialog, version 03.");
  }
  
  else  
  {
    player.Say("tone");
  }


Also: if you have three ifs followed by an else, the else is only connected to the 3rd if. So regardless of how the first two tests went, the else block WILL run if the 3rd test fails. You need to use "else if" for every test except the first to get only a single block to run.

Alen101

Thank you very much Khris it works great!:grin::-D

SMF spam blocked by CleanTalk