Local Variables

Is there a problem in accessing local variables from a different object? I have an object NPC with a local variable flagged=0. I want to check that variable from a different object, e.g. a room, so I check if(NPC.flagged==0). Error during gameplay, not while compiling. What’s wrong?

By local variable, do you mean a property? Any property of a named object should be accessible from code elsewhere…

If you can’t get it figured out you’ll have to post some code that I could look at…

Given an object defined as:

pebble: Thing 'small round pebble' 'pebble'
        "It's a small, round pebble. "

        foo = 'red'

        frob() {
                local bar;

                bar = 'blue';
 
                return(bar);
        }
;

Then elsewhere pebble.foo will return “red” but pebble.bar will be nil. If you need access to the local variable bar from the method frob(), you can return it from the context it’s defined in. In this case frob() does this by using bar as its return value, but there are other tricks you can use if this is what you’re trying to do, the simplest of which would be to use a property (like foo) defined on the object instead of a local variable defined only in the method.

Lemme know if this doesn’t answer your question.

1 Like

After much trying I found out it wasn’t the property, but I had done something wromng in a TravelMessage function. Sorry to have kept you up!

1 Like