Page 1 of 1

Needing a Bit of OOP Helpage

Posted: Sun Dec 24, 2006 8:11 am
by Amano Jaku
I've played a lot of ZZT and am trying to make my own game. It's going to involve lots of item-Flags, but I've come up against a snag right from the gate.

There's a door which is supposed to check for a flag (RxK1), which stands for a keycard. If the flag's set, then the door is supposed to open. If not, the door tells him to go find the damn card.

For some reason, the program works backwards. When the flag isn't set, the door opens. When it is set, the door tells you to find the keycard. This confuses me to no end.. I can't seem to figure out why it's working backwards. I've even looked at other programs that use similar situations, but I don't see why mine works the other way around.

Code: Select all

#cycle 1
#end
:touch
#if not RxL1 then nocard
#lock
(text about swiping the card)
(movement and #char stuff)
#unlock
#end
:nocard
(text about needing to get the damn card)
#end

Posted: Sun Dec 24, 2006 8:46 am
by Commodore
not sure if this would exactly help the problem but the #if command could be better written like this:

#if not RxL1 #nocard

"then" is not necessary and maybe (I don't remember) the # is needed. At least that's the way I do it.

Also make sure you haven't set more than 9 flags. That can really screw things up.

Posted: Sun Dec 24, 2006 8:56 am
by Amano Jaku
Hmm. Just tried that, changing it to:

Code: Select all

#if not RxL1 #nocard
but it still does the same. When the flag is NOT set, the door opens, but when the flag IS set, the door stays shut. I don't have more than nine flags 'cus this is the starting map.. this is what frustrates me so much. I've got all this game waiting to be made and I'm stuck at the very beginning.

Thank you for the help, though.

Posted: Sun Dec 24, 2006 11:51 am
by Nixon
I tested your code and got rid of stuff you didn't need, it seemed to work fine, I used another object to set and clear the flag. So I dunno what your doing, maybe you misnamed the flag in another object.

Code: Select all

#end
:touch
#if not RxL1 nocard
you do have the card
#end
:nocard
You have NO card
#end

Code: Select all

#end
:touch
#if RxL1 i
#if not RxL1 #set RxL1
Its set
#end
:i
#clear RxL1
Not set
#end

Posted: Sun Dec 24, 2006 3:36 pm
by gingermuffins
a 2nd # isn't needed in an if statement if you're just calling a label and not issuing a command. Also flags are case insensitive, so RxL1 is the same as rxl1.

Code: Select all

#if not rxl1 nocard
this is kind of useless, but you can fit 8 consecutive flag checks onto one line like this:

Code: Select all

#if a#if b#if c#if d#if e#if f#if g#if h x

Posted: Sun Dec 24, 2006 8:16 pm
by bustaballs
Wait.. what does cycle do again?


Sorry.. I just woke up.

Posted: Mon Dec 25, 2006 4:01 am
by Commodore
changes the speed an object executes commands, higher number = slower object.

Posted: Mon Dec 25, 2006 4:01 am
by Dr. Dos
Changes speed between Spin cycle and Rinse cycle.

Posted: Mon Dec 25, 2006 4:28 am
by bustaballs
I was looking through some of my old code today and I noticed that I used a alot of #lock and #unlock and I don't remember why. They were pretty much stand-alone objects that didn't really have any commands going to or coming from other objects. I remember I had to use the commands to get the things to work like I wanted them to. Anyone know why?

Posted: Mon Dec 25, 2006 2:00 pm
by Commodore
prevent an errant :touch message perhaps? It's good practice to do that though. It's not a problem unless you really get desperate for the extra memory.

Posted: Tue Dec 26, 2006 4:31 am
by Amano Jaku
I added #lock/#unlock commands because the door is one of those nifty "swinging" animated doors, and I didn't want a mis-touch to cause it to swing further out into the hallway and break off the wall.

And it turns out that I had screwed up my coding in a totally different object. I'd made one designed to Set or Clear the flag needed for that door so I could test wether the door worked right or not. But I'd forgotten to put an #end before the :touch part. So every time I started the game, it would automatically Set the RxL1 flag.

Thanks for your help, everyone. =D

Posted: Tue Dec 26, 2006 9:22 am
by Commodore
(insert appropriate sherlock holmes quote here)