if and elses in dialogs

Started by funnyboy044, Tue 02/05/2017 23:09:23

Previous topic - Next topic

funnyboy044

I want to set up an if and else thing in one of my dialogs, I would like to know how to set up one.
Here's what I've got:
Code: ags

cJoe: Did you know you're being pranked right now?
cLord: What!? Pish-posh! Balderdash! Epizootics of the blowhole!
cLord: You're lying!
cJoe: No! Your fence is being egged and your backyard is getting fucked up!
cJoe: Go check if you don't believe me!
cLord: All right then, I well.
 cLord.Walk(1, 473,eBlock);
 cLord.ChangeRoom(3, 260, 445,eDirectionLeft);
 Wait(50);
  if(GrassBoozed && FenceEgged){
    cLord.Say("AHHHHHHHHHHHH!");
    cJoe.Say("Oooh.");
    else{
      cLord.ChangeRoom(4, 1, 473,eDirectionRight);
      cLord.Walk(551,473,eBlock);
      cLord.LockViewFrame(9,0,0);
cLord: You liar! You caused me to be alarmed for such a minor offense. 
cJoe: Hmmm, silly me.
cLord: Don't fuck with me again!
,

Cassiebsg

You don't exactly explain what the problem is, but I can spot 3 errors in there:

1) You never close the if and else brackets, so I can only expect the code to totally fail to compile.

2) If cLord is the player character, you can not change rooms in the middle of the dialog. ChangeRoom needs to always be the last action in a function. So in a dialogue, the next line should be stop.

3) you don't use the cLord: in the names in dialogues, you just use Lord:.
There are those who believe that life here began out there...

funnyboy044

Allow me to explain a little more. The player character is cJoe and I would like the code to recognize the symbols "GrassBoozed" and "FenceEgged". Also,I might want to know other things about putting if and elses into dialogs if they are helpful.
Code: ags

cJoe: Did you know you're being pranked right now?
cLord: What!? Pish-posh! Balderdash! Epizootics of the blowhole!
cLord: You're lying!
cJoe: No! Your fence is being egged and your backyard is getting fucked up!
cJoe: Go check if you don't believe me!
cLord: All right then, I well.
 cLord.Walk(1, 473,eBlock);
 cLord.ChangeRoom(3, 260, 445,eDirectionLeft);
 Wait(50);
  if(GrassBoozed && FenceEgged){
    cLord.Say("AHHHHHHHHHHHH!");
    cJoe.Say("Oooh.");
  }
    else{
      cLord.ChangeRoom(4, 1, 473,eDirectionRight);
      cLord.Walk(551,473,eBlock);
      cLord.LockViewFrame(9,0,0);
    }
cLord: You liar! You caused me to be alarmed for such a minor offense. 
cJoe: Hmmm, silly me.
cLord: Don't fuck with me again!


Also, should I put brackets around the entire if/else situation?
,

Cassiebsg

No, you just put the brackets around the conditions that need them. Consider them as "blocks" of code that run together.

In order for GrassBoozed & FenceEgged to be recognized you need to make them Global Variables, click the blue Globe icon in the project tree, then add them there. If you have created them elsewhere, like in a room script, don't forget to delete those lines.
There are those who believe that life here began out there...

Khris

@funnyboy044:
ALWAYS state error messages you're getting. Verbatim, and including line numbers.

Just to make sure: when you use if, you either want to run a single command conditionally, or multiple ones. You don't need to wrap a single command, but if you want to run multiple commands based on a test, you need to tell the computer which exactly those are. That's why you wrap the commands in { and }.
Note that this can be easily visualized by using proper indentation:
Code: ags
  cLord.Walk(1, 473,eBlock);
  if (GrassBoozed && FenceEgged) {
    cLord.Say("AHHHHHHHHHHHH!");
    cJoe.Say("Oooh.");
  }
  else
    cJoe.Say("Let me get back to you."); // only this will run depending on "else"
  cLord.Say("Bye.");

See how it's immediately obvious which commands are depending on which outcome?

Finally, .ChangeRoom() will move a character to another room. Usually not what you would do right before having them .Say() something. Calling it on the player character makes AGS switch rooms, but not right away. The current function, here: the dialog script, will finish first, then the queued player.ChangeRoom() command will execute.

(Pretty much all of this is explained in the manual, btw.)

SMF spam blocked by CleanTalk