Hi
after my character walks on a region talking starts if he has correct inventory items. When talking is over the character continues.
my problem is i don't want it repeated every time he steps on the region, but if i disable the region it affects the light level, although only a few pixels its annoying.. How can I incorporate a Do Only One so talking is not repeated?
This i s what I have at the moment:
function region2_WalksOnto()
{
if (player.HasInventory(ikey1) && player.HasInventory(ikey2))
{
cSlocombe.FaceLocation(188, 270);
cFrankj.FaceCharacter(cSlocombe);
cSlocombe.Say( "Hey uncle. I've found 2 Key pieces!!");
cFrankj.Say("That's absolutely splendid my dear boy!");
cSlocombe.Say("And I've fixed the water");
cFrankj.Say("You're a marvel Morgan");
cSlocombe.Say("Oh, and the electrics are working now");
cFrankj.Say("Jolly good");
cFrankj.Say("Let me know when you have found more Key pieces. I'm really tired today!");
cFrankj.Say("I'm going back to bed");
cSlocombe.Say("Ok uncle");
cFrankj.Walk(532, 140, eBlock);
cFrankj.Transparency=100;
cSlocombe.Say("Well, guess I should look around in the house some more");
region[2].Enabled = false;
region[3].Enabled = true;
}
}
cheers for any help
barefoot
Just use Game.DoOnceOnly() (http://www.adventuregamestudio.co.uk/manual/Game.DoOnceOnly.htm) which literally does what it says
So,
function region2_WalksOnto() {
if (player.HasInventory(ikey1) && player.HasInventory(ikey2)) {
if (Game.DoOnceOnly("have both keys already")) {
cSlocombe.FaceLocation(188, 270);
cFrankj.FaceCharacter(cSlocombe);
cSlocombe.Say( "Hey uncle. I've found 2 Key pieces!!");
cFrankj.Say("That's absolutely splendid my dear boy!");
cSlocombe.Say("And I've fixed the water");
cFrankj.Say("You're a marvel Morgan");
cSlocombe.Say("Oh, and the electrics are working now");
cFrankj.Say("Jolly good");
cFrankj.Say("Let me know when you have found more Key pieces. I'm really tired today!");
cFrankj.Say("I'm going back to bed");
cSlocombe.Say("Ok uncle");
cFrankj.Walk(532, 140, eBlock);
cFrankj.Transparency=100;
cSlocombe.Say("Well, guess I should look around in the house some more");
//region[2].Enabled = false; //comment this out if you don't want to disable it.
region[3].Enabled = true;
}
}
}
Hi
I am trying this:
function room_AfterFadeIn()
{
if (Game.DoOnceOnly("found ruler"))
if (player.HasInventory(ikey1) && player.HasInventory(ikey2))
{
cSlocombe.FaceLocation(188, 270);
cFrankj.FaceCharacter(cSlocombe);
cSlocombe.Say( "Hey uncle. I've found 2 Key pieces!!");
cFrankj.Say("That's absolutely splendid my dear boy!");
cSlocombe.Say("And I've fixed the water");
cFrankj.Say("You're a marvel Morgan");
cSlocombe.Say("Oh, and the electrics are working now");
cFrankj.Say("Jolly good");
cFrankj.Say("Let me know when you have found more Key pieces. I'm really tired today!");
cFrankj.Say("I'm going back to bed");
cSlocombe.Say("Ok uncle");
cFrankj.Walk(532, 140, eBlock);
cFrankj.Transparency=100;
cSlocombe.Say("Well, guess I should look around in the house some more");
}
}
barefoot
Just seen your reply Iceboty
cheers
barefoot
You *should* be able to incorporate it into the first if statement.
When ags evaluates sets of boolean expressions it does so from left to right. So as soon as it encounters 'false' it will stop evaluating the expression (or at least it *should* i'm not 100% sure if ags does this correctly)
so for instance:
if (1 == 2 && IsthisTrue()) {
//do something
}
IsThisTrue() will *never* be run because the first condition means that the expression as a whole can never be true and AGS evaluates from left to right.
So if we apply this to your code:
function region2_WalksOnto()
{
if (player.HasInventory(ikey1) && player.HasInventory(ikey2) && Game.DoOnlyOnce("SomeKey"))
{
cSlocombe.FaceLocation(188, 270);
cFrankj.FaceCharacter(cSlocombe);
cSlocombe.Say( "Hey uncle. I've found 2 Key pieces!!");
cFrankj.Say("That's absolutely splendid my dear boy!");
cSlocombe.Say("And I've fixed the water");
cFrankj.Say("You're a marvel Morgan");
cSlocombe.Say("Oh, and the electrics are working now");
cFrankj.Say("Jolly good");
cFrankj.Say("Let me know when you have found more Key pieces. I'm really tired today!");
cFrankj.Say("I'm going back to bed");
cSlocombe.Say("Ok uncle");
cFrankj.Walk(532, 140, eBlock);
cFrankj.Transparency=100;
cSlocombe.Say("Well, guess I should look around in the house some more");
region[3].Enabled = true;
}
}
The above *should* work without any problems.. however if i'm wrong about the operator preference then you can just use a nested if like this
function region2_WalksOnto()
{
if (player.HasInventory(ikey1) && player.HasInventory(ikey2)) {
if (Game.DoOnlyOnce("SomeKey") {
cSlocombe.FaceLocation(188, 270);
cFrankj.FaceCharacter(cSlocombe);
cSlocombe.Say( "Hey uncle. I've found 2 Key pieces!!");
cFrankj.Say("That's absolutely splendid my dear boy!");
cSlocombe.Say("And I've fixed the water");
cFrankj.Say("You're a marvel Morgan");
cSlocombe.Say("Oh, and the electrics are working now");
cFrankj.Say("Jolly good");
cFrankj.Say("Let me know when you have found more Key pieces. I'm really tired today!");
cFrankj.Say("I'm going back to bed");
cSlocombe.Say("Ok uncle");
cFrankj.Walk(532, 140, eBlock);
cFrankj.Transparency=100;
cSlocombe.Say("Well, guess I should look around in the house some more");
region[3].Enabled = true;
}
}
}
I dont actually have the editor with me so i cant be sure if AGS respect boolean preference like this.
Put the DoOnceOnly() check
after checking for the two keys, like in my example.
This is because the "DoOnce" condition is set to have been accomplished the
first time it is encountered in the script. In your version, if the player does not have both items and walks onto the region, the "found ruler" condition will be set to have been accomplished and then since the player does not have both items the remaining codes will not be run. Even after the player gets both items and walks onto the region again in a later time this part will never be checked, as the "found ruler" condition is already considered done.
* Calin ninjaed me, but I won't recommend checking all the conditions in a single if-clause, since it would be easier to read and debug (at least to general users) when using two separate if clauses (and more importantly this can be confusing as I remember that this evaluation of expressions behaviour was implemented quite recently; everything in the expression was evaluated (or something like that) in some older versions of AGS).
Edit: Okay. I've checked and it's added in V2.71:
Quote- Implemented lazy evaluation for && and || operators.
Though this is sorta safe to do this now but still I'll recommend breaking them up for better clarity.