Ask several characters before you can continue

Started by Blondbraid, Thu 19/05/2016 00:13:59

Previous topic - Next topic

Blondbraid

Hello! :)
I'm wondering what I should do if I want to make the player having to ask several different characters something before an option in a certain dialog becomes available.

What I want is that the player has to chose a certain option in three different dialogues, in any random order as long as all three has been chosen, before a forth dialog is triggered.
How can this be done?


Khris

Asked an answered dozens of times.

Create a global bool for each part of the puzzle, here three in total.
Create a global function that checks all three bools.

in a dialog script:
Code: ags
@4
... bla
 dialog_puzzle_5_1 = true;
 check_dialog_puzzle_5();


in the global script
Code: ags
// header
import function check_dialog_puzzle_5();

// top of main script
function check_dialog_puzzle_5() {
  if (!dialog_puzzle_5_1 || !dialog_puzzle_5_2 || !dialog_puzzle_5_3) return;  // not achieved yet, do nothing

  // all three flags are true
  if (Game.DoOnceOnly("dialog puzzle 5")) {
    dGuy.SetOptionState(6, eOptionOn);
  }
}


Using Game.DoOnceOnly() is of course optional, but can be useful if the final code isn't supposed to run multiple times.

Blondbraid

Quote from: Khris on Thu 19/05/2016 00:31:45
Asked an answered dozens of times.
I suspected as much, but couldn't find any answers I was looking for when I tried to search the forums... (roll)

Anyway, I tried using the script that you gave me, but an error line shows up:
GlobalScript.asc(151): Error (line 151): undefined symbol 'dialog_puzzle_5_1'

I put the first line into the Header of the global script and the rest into the main global script. Have I missed something?

Also, this script shows how you turn a dialog option on, but I wanted to have a new dialog start once you enter a specific room after you chose all the options, but only once...


Matti

As Khris said, you have to create global bools (dialog_puzzle_5_1 etc).

If you want a new dialog to start in a specific room then put check_dialog_puzzle_5(); in the room script, not in the dialog script. Also, in the function Khris posted change dGuy.SetOptionState(6, eOptionOn); to dDialogName.Start();


Blondbraid

Quote from: Matti on Thu 19/05/2016 10:44:03
As Khris said, you have to create global bools (dialog_puzzle_5_1 etc).
I'm sorry but I don't know how to create a global bool, how do you do that?


Haggis

You need to create a Global variable - type Boolean (true/false)

You can do this in the AGS menu by double clicking 'Global Variables', right clicking in the list of variables (which might be empty) and selecting add variable. Under type choose 'bool'.

A global variable is shared across all code so you can call it in any room, dialog script etc.


Blondbraid

Thank you Haggis!
Unfortunately, when I try to start the game this error comes up:
room19.asc(55): Error (line 55): Variable 'check_dialog_puzzle_5' is already imported
Quote from: Matti on Thu 19/05/2016 10:44:03
If you want a new dialog to start in a specific room then put check_dialog_puzzle_5(); in the room script, not in the dialog script.
I did put the script functions from Khris into the script for the room where the dialogue shows up instead of the global script.


Haggis

Ok - my coding knowledge is limited so I'll wait for one of the more experienced members to provide proper advice - but - it sounds to me like you've defined the same variable multiple times.

I guess I have two questions:
1) What's the name(s) of the global variables you created?
2) What variable are you defining in line 55 of room 19?

If you define a global variable - you don't need to also define that variable in each room / you can't define another variable of the same.

Blondbraid

Quote from: Haggis on Thu 19/05/2016 14:28:16
Ok - my coding knowledge is limited so I'll wait for one of the more experienced members to provide proper advice - but - it sounds to me like you've defined the same variable multiple times.

I guess I have two questions:
1) What's the name(s) of the global variables you created?
2) What variable are you defining in line 55 of room 19?

If you define a global variable - you don't need to also define that variable in each room / you can't define another variable of the same.
Well, the lines I used is:
Code: ags

function check_dialog_puzzle_5() {
if (!dialog_puzzle_5_1 || !dialog_puzzle_5_2 || !dialog_puzzle_5_3) return;

I tried disabling those lines, but then a message saying Script link failed: Runtime error: unresolved import `"check_dialog_puzzle_5".


Snarky

#9
Quote from: Blondbraid on Thu 19/05/2016 14:09:48
I did put the script functions from Khris into the script for the room where the dialogue shows up instead of the global script.

I believe this is your problem. It would surprise me if dialogs can call room scripts. I think you need to put them in the global script/header like Khris told you to do. Matti didn't say to move the function, just move the call to the function.

BTW, if you're unclear on the difference between the function import (declaration), the function definition and calls to the function, you may want to read up in the manual. The scripting tutorial (part 1 and 2) and the article on multiple scripts together provide a pretty good intro to this topic.

Khris

#10
Not to be rude or anything, but didn't we go through all this less than a month ago...?

http://www.adventuregamestudio.co.uk/forums/index.php?topic=53456.msg636534214#msg636534214

Anyway, the function declaration goes into the global script, the import line goes into the global header. This is done so you can actually call the function everywhere, including room scripts.

However, if the game will check the three puzzle variables only upon entering a specific room, you don't really need the function.
In that case, just do this in the room's After Fadein event / function:
Code: ags

  if (dialog_puzzle_5_1 && dialog_puzzle_5_2 && dialog_puzzle_5_3 && Game.DoOnceOnly("dialog_puzzle_5")) {
    dGuy.Start();
  }


Note that I have used "dialog_puzzle_5_x" for the three variable names, but you are obviously free to use any name you want. You can call them "asked_barber", "asked_baker" and "asked_butcher", or "ts4", "ts5" and "ts45453" if you like. There's also no relation between the variable names and the function's name or the text inside Game.DoOnceOnly(...). It's all completely arbitrary.

The important thing is to get down the basic logic: you create three flags, and set each one as you talk to the three guys. At a point where the fourth dialog might happen, you check the flags and start it, if they all are true.

The initial solution had a function because in a situation were tghe game is supposed to do X as soon as the third flag is set to true, you need to check all three flags right after setting each one of the three. Instead of pasting the same code into three different dialogs (which violates DRY), I used a function.

Snarky

Quote from: Khris on Thu 19/05/2016 16:10:15
Anyway, the function declaration goes into the global script

Just so we're consistent, Khris: the bit that goes in the global script (the actual function) is conventionally called the function definition. The "declaration", telling the compiler that there's going to be a function with this particular signature, most closely maps on to the AGS import statement (though the way AGS does it is slightly non-standard).

Khris

I'm used to Java, where the function/method body is called declaration (because there are no headers, I guess).
I'll keep it in mind when talking about AGS though.

Snarky

Hmmm, I didn't know that (even though Java is the language I use the most). If the distinction is not as widespread as I thought, I guess it doesn't make sense to impose it on AGS. Sorry!

I do find it a bit odd that Java calls the C-definition the "declaration", because you could easily draw the same distinction between declaring a method signature (in an interface) and actually defining it in an implementing class.

Blondbraid

The problem has been solved elsewhere,
I received a few messages and a lot of help from Haggis, and it has just been solved.
I'm so sorry I didn't notice your replies here sooner! :-[


Khris

I looked around a bit and Android Studio / IDEA and Eclipse call it "declaration".
The Java Tutorials call it "declaring a method", under the headline "Defining Methods" :)
Some guy in a forum said that
int a;
is a declaration and
int a = 10;
is a definition...

Anyway, the distinction used by C makes sense for AGS so I'll try and use that in the future.

SMF spam blocked by CleanTalk