[code/ags]
player.Say("okay.");
object[2].Visible = !object[2].Visible;
stove = true;
So as of now the stove turns off and on but obviously, once this happens once the bool stays on forevor. anyone to set it to false in conjecture with !object
I think you just need to change it to stove = !stove;
A longer, more comprehensible code would be this:
if (stove == false)
{
stove = true;
object[2].Visible = true;
}
else
{
stove = false;
object[2].Visible = false;
}
I'm just assuming that the object should turn visible when the variable is true. You didn't provide much info and didn't even post the function your code snippet is in.
object[2].Visible is a bool, too; you can use the same syntax to toggle both.
Or just use
stove = object[2].Visible;
after toggling the object's visibility.
Also, unless stove is a global bool you need to switch in other rooms, you don't really need it at all; you can just use object[2].Visible itself to find out if the stove is turned on or not.
I should have mentioned I have for different burners on the stove. each with similiar coding. Object 0,1,2,3
function hDial1_AnyClick()
{
if (Verbs.UsedAction(eGA_WalkTo)) {
} else if (Verbs.UsedAction(eGA_Use)) {
player.Say("okay.");
object[0].Visible = !object[0].Visible;
stove = object[0].Visible;
}
}
I have it set when the charater leaves the room, he warns the player that the house will burn down if he leaves the burners on. So now when I try to leave it shows that dialogue over and over again.
Why does it show the message over and over again? Where did you put it?
Anyway, you can do this:
bool stove = false;
for (int i = 0; i < 4; i++) if (object[i].Visible) stove = true;
if (stove) Display("Better turn off that stove before leaving.");
function room_LeaveLeft()
{
if (stove == true){
player.Say("Lets not burn the house down, in the first 5 minutes of the game.");
}
if (stove == false) {
player.ChangeRoom(12, 250, 350);
}
}
I made the bool already, the rest of it I honestly do not understand.
I'm guessing that function is called each frame as long as the player is outside the left edge, so you would have to add a blocking walk back inside the edge at line 7 of that snippet.
My code iterates over the first four objects and checks if at least one of them is true. Use it like this (and remove the global bool):
function room_LeaveLeft()
{
bool stove = false;
for (int i = 0; i < 4; i++) { // long version with blocks
if (object[i].Visible) {
stove = true;
}
}
if (stove) {
player.Say("Lets not burn the house down, in the first 5 minutes of the game.");
player.Walk(50, player.y, eBlock);
}
else player.ChangeRoom(12, 250, 350);
}
That Code boggles my mind lol. It worked tho, once again you are amazing. many thanks!