Object on Object Boolean loop, Aghhhhh!

Started by harmonicapress, Sat 21/05/2016 20:44:52

Previous topic - Next topic

harmonicapress

So I've painted myself into a bit of a corner here. I have an object on an object, specifically a wad of gum over the peephole on a door. My character has to ask an NPC to leave the room before the main character can interact with the door or the gum. (The character must 'talk to' or eat the gum to get it off the peephole. So I set a boolean at the beginning of the script for isgumondoor = true; so that when he chews it i can set that to false and have the gum permanently disappear. The problem I'm having is that when I close the door, the gum disappears and doesn't come back when I open it. I've tried everything and I just keep getting caught in a mental loop. It's driving me bonkers, please help!
Ps if the door is closed, the gum is outside the room and should not be visible
    if the door is open the gum should be visible unless the main character has tripped the boolean by 'talking to' (or chewing) the gum.
Thanks guys


Code: ags

function oGum_Look()
{
cBingo.Say("Looks like a wad of chewing gum covering the peephole.");
}


function oGum_Interact()
{
if ( cMackey.x<500) { 
cBingo.Say("It's too sticky to grab with my fingers...");
} 
else { 
cBingo.Say("Mackey is blocking the door.");
}
}

function oOpenHotelDoor_Look()
{
cBingo.Say("It's the door to the victim's room.");
}

function oOpenHotelDoor_Interact()
{
if ( cMackey.x<500 ) { 
cBingo.Walk(590, 450, eBlock, eWalkableAreas);
oOpenHotelDoor.Visible = false;
oClosedHotelDoor.Visible = true;
oGum.Visible = false;
}
else { 
cBingo.FaceObject(oOpenHotelDoor);
cBingo.Say("Mackey is blocking the door.");
}
}

function hCSExit_Interact()
{
cBingo.Walk(569, 378, eBlock, eWalkableAreas);
cBingo.ChangeRoom(2,405,445 );
}



function hCSExit_Look()
{
cBingo.Say("It's the way back to the elevators.");
}


function oClosedHotelDoor_Interact()
{
if (isgumondoor == false) { 
cBingo.Walk(590, 450, eBlock, eWalkableAreas);
oClosedHotelDoor.Visible = false;
oOpenHotelDoor.Visible = true;
oGum.Visible = false;
}
else {
  cBingo.Walk(590, 450, eBlock, eWalkableAreas);
  oClosedHotelDoor.Visible = false;
oOpenHotelDoor.Visible = true;
oGum.Visible = true;
}}

function oGum_Talk()
{
cBingo.Say("Gross, but ok. I'll chew it off.");
oGum.Visible = false;
isgumondoor = false;
cBingo.AddInventory(iGum);

}

Cassiebsg

Haven't checked all you code, just simplified this bit for you. Maybe it'll be easier to see what you're doing. ;)

Code: ags

function oClosedHotelDoor_Interact()
{
  cBingo.Walk(590, 450, eBlock, eWalkableAreas);
  oClosedHotelDoor.Visible = false;
  oOpenHotelDoor.Visible = true;
  if (isgumondoor) oGum.Visible = true;
  else oGum.Visible = false;
}
There are those who believe that life here began out there...

Matti

You can simplify it even more, because making oGum invisible is unnecessary at that point ;)

Honestly, I don't know why your code isn't working, I don't see a mistake. But one thing you should consider is to learn to indent your code correctly and consistently right from the beginning. It looks cleaner that way and makes it easier to spot bugs. This is how I'd do the code (I just took the important parts):

Code: ags
function oOpenHotelDoor_Interact()
{
  if ( cMackey.x < 500 ) 
  { 
    cBingo.Walk(590, 450, eBlock, eWalkableAreas);
    oOpenHotelDoor.Visible = false;
    oClosedHotelDoor.Visible = true;
    oGum.Visible = false;
  }
  else 
  { 
    cBingo.FaceObject(oOpenHotelDoor);
    cBingo.Say("Mackey is blocking the door.");
  }
}

function oClosedHotelDoor_Interact()
{
  cBingo.Walk(590, 450, eBlock, eWalkableAreas);
  oClosedHotelDoor.Visible = false;
  oOpenHotelDoor.Visible = true;
  if (isgumondoor) oGum.Visible = true;
}

function oGum_Talk()
{
  cBingo.Say("Gross, but ok. I'll chew it off.");
  oGum.Visible = false;
  isgumondoor = false;
  cBingo.AddInventory(iGum);
}


Also, I would just have one single object for the door and change its view when it's opened or closed.

dayowlron

1. i would shorten it even more but this is not your problem.
function oClosedHotelDoor_Interact()
{
  cBingo.Walk(590, 450, eBlock, eWalkableAreas);
  oClosedHotelDoor.Visible = false;
  oOpenHotelDoor.Visible = true;
  oGum.Visible = isgumondoor;
}

2. I am guessing that the problem with the gum not showing up is the baseline. Be sure the baseline for the gum is lower (higher number) than the one for the door. ie. Set the baseline for oOpenHotelDoor is 0 and then the baseline for the gum is 1.
Question: can the player walk behind the open hotel door? If so then you may want to leave the baseline for the door alone and set the baseline for the gum to be one more than the StartY of the open hotel door.
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

Monsieur OUXX

Baseline issue +1
Some object appears on top of the gum, hiding it.
 

Khris

Quote from: harmonicapress on Sat 21/05/2016 20:44:52The problem I'm having is that when I close the door, the gum disappears and doesn't come back when I open it.
This points to a logic error, not a baseline issue. We should wait for harmonicapress to get back to us.

harmonicapress

Yes, Definitely a logic issue. I tried the code supplied by matti, and the behavior definitely changed, now when I close the door, the gum floats in the air where it was when the door was open. Here is the code as I have it currently, this time I supplied both interact with closed door and interact with open door, might be easier to spot the flaw. Ps. Don't forget I have boolian set at the game start that says isgumondoor == true. Thanks for your diligence friends!
Code: ags

function oOpenHotelDoor_Interact()
{
if ( cMackey.x<500 ) { 
cBingo.Walk(590, 450, eBlock, eWalkableAreas);
oOpenHotelDoor.Visible = false;
oClosedHotelDoor.Visible = true;
if (isgumondoor == false)
oGum.Visible = false;
else oGum.Visible = true;
}
else { 
cBingo.FaceObject(oOpenHotelDoor);
cBingo.Say("Mackey is blocking the door.");
}
}

function hCSExit_Interact()
{
cBingo.Walk(569, 378, eBlock, eWalkableAreas);
cBingo.ChangeRoom(2,405,445 );
}

function oClosedHotelDoor_Interact()
{
  cBingo.Walk(590, 450, eBlock, eWalkableAreas);
  oClosedHotelDoor.Visible = false;
  oOpenHotelDoor.Visible = true;
  if (isgumondoor) oGum.Visible = true;
}

Matti

You changed the opendoor interact function and now line 9 leaves the gum visible, while it shouldn't.

Try this (again):

Code: ags

if ( cMackey.x < 500 ) 
{ 
  cBingo.Walk(590, 450, eBlock, eWalkableAreas);
  oOpenHotelDoor.Visible = false;
  oClosedHotelDoor.Visible = true;
  oGum.Visible = false;
}

SMF spam blocked by CleanTalk