Trigger Event with bools SOLVED

Started by Caracal, Tue 07/01/2014 21:31:07

Previous topic - Next topic

Caracal

Ok, it is me again, with a really easy problem- I guess. I have been trying around but just cant figure out a way.
There is a task in one of my rooms. The player is suppose to place 3 objects at certain locations in the room
(inventory items on hotspots, really easy). As soon as the player has delivered all 3 items, doors in that very
same room are suppose to open. (Doors are objects, visible = false, and restore walkable area to access a new room)
In order to tell AGS that the items are all together I set up 3 bools in the roomscript.
(ITEMI, ITEMII, ITEMIII) And once the 3 Items are at their places I wanted to trigger the event with a rep. execute, like this:

Code: ags

function room_RepExec()
{
if (Game.DoOnceOnly("DoorOpened")){
  if (ITEMI && ITEMII && ITEMIII == true){
cBellatrix.Say("Das waren alle fehlenden Ornamente.");
Wait(20);
cBellatrix.Say("Die Türen müssten nun offen sein");
oDoorI.Visible = false;
oDoorII.Visible = false;
}
}
}


But this does not work. And I really cant see why. Nothing happens instead. Not even an error occurs.
Any ideas, guys?
And thanks in advance!

Khris

In general, for booleans, if (bool_var == true) is exactly the same as if (bool_var). That's why your code is fine in principle, and you can even use if (ITEMI && ITEMII && ITEMIII) instead.
For other conditions though, you have to spell them out. Say you want to check whether three ints are all equal to 5, in that case you have to do if (a == 5 && b == 5 && c == 5), you cannot do if (a && b && c == 5) instead, since this will be true if a and b are anything other than 0.

As for why your code fails, Game.DoOnceOnly has to go inside the other check. As soon as you enter the room, GameDoOnceOnly will return true, but only once. Which means the check for the three booleans is only made once, then never again.
Since conditions are checked left to right, you can do this to avoid nesting:
Code: ags
function room_RepExec()
{
  if (ITEMI && ITEMII && ITEMIII && Game.DoOnceOnly("DoorOpened")){
    ...
  }
}

Caracal

Ok,
So i did this:
Code: ags
  
function room_RepExec()
{
  if (ITEMI == true && ITEMII == true && ITEMIII == true && Game.DoOnceOnly("DoorOpened")){
...
}
}

But it still does nothing. (even if i dont put the "== true" or the "game.doOnceOnly(...)" in there at all)

Khris

I'm pretty sure it should work that way, but let's try this first:
Code: ags
function room_RepExec()
{
  if (ITEMI == true && ITEMII == true && ITEMIII == true) {
    if (Game.DoOnceOnly("DoorOpened")) {
      ...
    }
  }
}


If that still doesn't work, you either didn't link the function to the room event or there's an error somewhere else and the bools don't get all changed to true.

Caracal

Quote from: Khris on Wed 08/01/2014 00:45:09
the bools don't get all changed to true.

My apologies, the code works perfectly fine! I really messed up and changed "ITEMI" to "true" twice and forgot "ITEMIII".
But i didnt know that i have to write out the bools properly, like " if (ITEMI == true && ...). So thank you once again!

Crimson Wizard

#5
Quote from: Caracal on Wed 08/01/2014 10:12:47
But i didnt know that i have to write out the bools properly, like " if (ITEMI == true && ...).

No, you do not have to write "== true" every time, it is valid to write just "ITEMI && ITEMII && ..." for boolean variables, as in the example Khris gave few posts above:
Quote from: Khris on Tue 07/01/2014 22:03:55
Code: ags
function room_RepExec()
{
  if (ITEMI && ITEMII && ITEMIII && Game.DoOnceOnly("DoorOpened")){
    ...
  }
}


Khris

Yes, I explained this in detail...
In fact, " == true" is the only test you actually can remove without changing the outcome.

SMF spam blocked by CleanTalk