Coding issue?

Hey, so I wonder if anyone could help me out with this stuff. It seems straightforward to me, but it’s not working for some reason. And, I don’t know why.

So, telling the story through pics, you can see the situation, and the piece of code I’m playing with. The situation is, one lever, and the goal is to turn it on, and then off. But, I can’t turn it off. So, is it a problem with how I’m trying to do that, or some code issue? I’ll describe what I perceive as the issue after the pics.



So, I’m just debugging what’s happening, so that’s why there’s a few comment-outed lines. But, what I want to point out is… in the first set, it’s not getting into the branch that puts the PORTAL variable in the lever. It’s just not getting into that branch with that configuration of code.

But, then, in the second set, you see that it does get into that branch (because you can see it when I click on the lever to check). So, even though it’s getting into that branch, it’s still not destroying the portal object that I’m aiming for.

Those two sets are done in the original version, because I wondered if there might be a difference. And, the final pic is of the same exact code running in EE (and it’s the project I mostly did the tutorial on). But, it seems to have the same result.

So, does anyone know what’s going on? And, am I missing something?

Edit: Oh, and I might add… I think it’s not getting into the branch with PORTAL in it, because in the first set, it doesn’t see the actual portal as a valid object. It can’t pass that conditional, and so doesn’t enter the else branch. And, so I was wondering about the scope the variables might have within nested if statements. That’s why I’m trying to find a configuration that does have a valid portal reference, and can delete that reference.

I’m not sure the first set has even got that valid portal creation.

Every time this runs it will create a portal.
The first set should create the portal, but the second set needs to get the portal then destroy it if it exists.

int nUsed1 = GetLocalInt(OBJECT_SELF, "LEVER_STATE");
if(nUsed1) == 0) {
    ActionPlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);
    SetLocalInt(OBJECT_SELF, "LEVER_STATE", 1);
    object oPortalSpot = GetWaypointByTag("TM_INWP");
    object oPortal = CreateObject(OBJECT_TYPE_PLACEABLE, "plc_portal", GetLocation(oPortalSpot), TRUE, "portal_tag");
}
else {
    ActionPlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE);
    SetLocalInt(OBJECT_SELF, "LEVER_STATE", 0);
    object oPortal = GetNearestObjectByTag("portal_tag", OBJECT_SELF);
    if(GetIsObjectValid(oPortal)) {
        DestroyObject(oPortal);
    }
}

Oh, so that’s how it works. I makes sense you have to search and find it when you use the lever again. But, my mind really hadn’t gone there, so you were a big help. I doubt I would have figured out the mechanism I was missing.

Good luck!