Axe Software Forums
  Quest Developer Forum
  Please help - changing object properties


Author Topic:   Please help - changing object properties
Mega posted 07-10-2001 04:32 GMT     
Here's my basic problem. I have a room in which I put a 'gate' object. I gave the 'gate' object an 'opened' property initialized to '0' (closed). I want the game to respond to the command 'open gate' with the following: if 'opened' = '0' (closed) then set 'opened' to '1' (open); else (if 'opened' started out as '1'(open)) print out "it's already opened!" I also want it to do the reverse for 'close gate'. However, when I start up the game and type 'open gate' twice, it says "the gate opens" both times, even though it should only say it the first time, and then tell me it's already opened when I try it again. However, when I try typing 'close gate' it tells me 'already closed', which is what it should do. What is going on? I think it has something to do with changing 'opened' from '0' to '1' and vice versa; this doesn't seem to be working right. What am I doing wrong?

Also, this method was a second attempt at solving the problem. What I originally wanted to do was design an object type called 'openclose' that would apply the same principles as I stated above, and could apply to anything of the sort (a door, a cabinet, a treasure chest, etc). However, I couldn't get that working either. I'd prefer to use this method than the one above, so can someone please help me with that?

Here's my code, by the way, if it helps.

' Created with QDK 3.02

define game <>
asl-version <300>
start <outside gate>
game info <Created with QDK 3.02>
command <open #object#> if action <#object#; open> then doaction <#object#; open>
command <close #object#> if action <#object#; close> then doaction <#object#; close>
end define

define synonyms
end define

define room <outside gate>
description msg <You are standing outside the gate of the gloomy castle of the evil wizard Moldrok.>

define object <gate>
look if ( opened = 0 ) then msg <This ancient gate is made of sturdy iron bars, which over the years have become covered in rust and entangling vines. Beyond the gate you can see the castle courtyard.> else msg <The ancient, rusty gate lies open, beckoning you into the castle courtyard.>
properties <opened=0>
action <open> if is <$objectproperty(gate;opened)$; =; 0> then {
properties<opened=1>
msg <It opens>
}
else {if is <$objectproperty(gate;opened)$; =; 1> then msg <Already opened!>}
action <close> if is <$objectproperty(gate;opened)$; =; 1> then {
properties<opened=0>
msg <It closes.>
}
else {if is <$objectproperty(gate;opened)$; =; 0> then msg <Already closed!>}
end define

indescription <You are standing>
end define

define text <intro>

end define

define text <win>

end define

define text <lose>

end define

MaDbRiT posted 07-10-2001 09:33 GMT          
Hi there, you have a few bits of incorrect syntax in your ASL - that's why it won't work as you expect.

Rather than rewrite the whole thing the way I'd do it, here is an amended version of your posted code. This does work as you require :-)

quote:

' Created with QDK 3.02

define game <>
asl-version <300>
start <outside gate>
game info <Created with QDK 3.02>
command <open #object#> if action <#object#; open> then doaction <#object#; open>
command <close #object#> if action <#object#; close> then doaction <#object#; close>
end define

define synonyms
end define

define room <outside gate>
description msg <You are standing outside the gate of the gloomy castle of the evil wizard Moldrok.>

define object <gate>
look if ($objectproperty(gate; opened)$ = 0) then msg <This ancient gate is made of sturdy iron bars, which over the years have become covered in rust and entangling vines. Beyond the gate you can see the castle courtyard.> else msg <The ancient, rusty gate lies open, beckoning you into the castle courtyard.>
properties <opened=0>
action <open> {
if ($objectproperty(gate;opened)$ = 0) then {
property <gate; opened=1>
msg <It opens>
}
else msg <Already opened!>
}
action <close> {
if ($objectproperty(gate;opened)$ = 1) then {
property <gate; opened=0>
msg <It closes.>
}
else msg <Already closed!>
}
end define

indescription <You are standing>
end define

define text <intro>

end define

define text <win>

end define

define text <lose>

end define


I too think this could be better accomplished by creating a type of object that can be opened or closed. If I have the time later today I will do that and post the code here :-)

Hope this helps,

Al

MaDbRiT posted 07-10-2001 11:01 GMT          
Earlier I wrote;

quote:
I too think this could be better accomplished by creating a type of object that can be opened or closed. If I have the time later today I will do that and post the code here.

I have used Mega's original code as a testbed and knocked out an 'openable' object type, the code follows shortly.

The 'type' has open and close actions and deals properly with attempts to open already open objects etc.

I also built in properties called 'opendesc' and 'closeddesc' - these should be used instead of setting a 'look' or 'description' tag for the openable object type. The correct decription is then provided automatically according to whether the object is closed or not :-) These properties replace the object's normal 'look' tag.

If you don't provide the 'opendesc' or 'closeddesc' properties, the type creates an appropriate basic description for you and uses that.

I've added a totally basic object called 'box' to Mega's code - just to demonstrate how an object behaves if just defined as type <openable> and left to use the defaults.

I also extended Mega's 'Open' and 'Close' commands so that they tell the player he 'can't do that' if he tries to open or shut an object that DOESN'T have the appropriate actions defined.

Here then is the code:

quote:

define game <>
asl-version <300>
start <outside gate>
game info <Created with QDK 3.02 - then hacked by MaDbRit :-) >
command <open #object#> {
if action <#object#; open> then doaction <#object#; open>
else msg <You can't do that.>
}
command <close #object#> {
if action <#object#; close> then doaction <#object#; close>
else msg <You can't do that.>
}
end define

define synonyms
end define

define room <outside gate>
description msg <You are standing outside the gate of the gloomy castle of the evil wizard Moldrok.>

define object <gate>
type <openable>
properties <closeddesc = This ancient gate is made of sturdy iron bars, which over __
the years have become covered in rust and entangling vines. Beyond the __
gate you can see the castle courtyard>
properties <opendesc = The ancient, rusty gate lies open, beckoning you into the __
castle courtyard>
end define

define object <box>
type <openable>
end define

end define

' This section defines the 'openable' type and provides open, close & look actions.
define type <openable>
closed
properties <closeddesc = null>
properties <opendesc = null>

action <open> {
if property <$thisobject$; closed> then {
property <$thisobject$; not closed>
msg <You open the #object#.>
}
else msg <The #object# is already open.>
}

action <close> {
if not property <$thisobject$;closed> then {
property <$thisobject$; closed>
msg <You close the #object#.>
}
else msg <The #object# is already closed.>
}

action <look> {
set string <lookedat; $thisobject$>
if property <$thisobject$; closed> then {
if ($objectproperty(#lookedat#; closeddesc)$ = null) then {
set string <lookmessage ;The #lookedat# is closed>
}
else {
set string <lookmessage ;$objectproperty(#lookedat#; closeddesc)$>
}
}
else {
if ($objectproperty(#lookedat#; closeddesc)$ = null) then {
set string <lookmessage ;The #lookedat# is open>
}
else {
set string <lookmessage ;$objectproperty(#lookedat#; opendesc)$>
}
}
msg <#lookmessage#.>
}

end define
'end of type definition

define text <intro>

end define

define text <win>

end define

define text <lose>

end define


I will slightly re-work this type and the related commands and include it into my forthcoming Quest Extensions library (q3extv2.qlb) So far that has over 20 object types defined in it :-)

Any ideas for useful object types that I could add are welcome.

Al

Computer Whizz posted 07-10-2001 16:05 GMT          
ummm.... Al, I just thought I'd better inform you of a slight bug which you have missed :

quote:

else {
if ($objectproperty(#lookedat#; closeddesc)$ = null) then {
set string <lookmessage ;The #lookedat# is open>
}
else {

that "closeddesc" should be "openeddesc"....

that code took me a couple of moments to get around (I HATE object types!! :) ) but I then noticed this little error.

I personally have no idea what object types you already have, and so can't think of what to suggest. Would you mind giving us a quick list??

Computer Whizz

MaDbRiT posted 07-10-2001 18:23 GMT          
Computer Whizz noticed:

quote:

that "closeddesc" should be "openeddesc"....

Well spotted C.W. In fact the code as given works anyway because I have provided both 'opendesc' and 'closeddesc' properties which is why I didn't pick it up when I knocked the type up - D'Oh :-)

quote:

that code took me a couple of moments to get around (I HATE object types!! :)

Do you? I LOVE them, they let me build objects that inherit functionality from others and make really useful specific types of object. I admit they are not always easy to follow or to code, but they are a powerful concept.

quote:

I personally have no idea what object types you already have, and so can't think of what to suggest. Would you mind giving us a quick
list??

Not at all, these types are all added (along with the commands needed to make them work) by my Quest 3 Extension library, which is now at 'beta 4' and is approaching the 1000 lines of code mark!

What the types actually do takes a fair bit of explaining, but they are defined as.

scenery
container
human
object
readable
clothing *
openable

* = The clothing type is never used directly, it is used to define 15 specific articles of clothing which can represent almost any garment with a little lateral thought.

There's a lot of multiple usage, the 'human' type is also a 'container' type by default for instance.

All of the associated commands and functionality these types suggest are in the lib. An example of how it works.

In my demo of the lib I have a 'locker' which is 'scenery', 'openable' and a 'container' all at once.

The locker is defined like this :-

quote:

define object <locker>
type <container>
type <scenery>
type <openable>
properties <closeddesc = The lockers are uniformly tall, green painted metal boxes. Your locker is closed>
properties <opendesc = Your locker is like all the others, except it is open>
examine <Some of the lockers are a little more battered than others, yours is in fairly average condition.>
end define

The 'scenery' means the locker is available for look and examine in the room, but not listed as an item and not take-able. It has an overrideable default response for attempts to do that.

The 'container' means the locker has its own inventory, you can put other things into and take things out of it. Well you can when it is open thanks to it being an 'openable' too :-)

The 'openable' means (literally) that the thing is openable! By default it starts off closed.
When it's closed you can't see its contents, or take things out or put things into it, when it is open you can see the contents and take/put things out/into it. All very logical but it makes for MASSES of code.

Example. examining the locker will show the content only if the locker is open - get the idea?

All of the commands and checking of what cannot be done / seen are provided by the lib. To get a working 'locker' there's nothing more to add to the definition I used above.

The clothing type is very complex. Basically it understands the concept of clothing being worn in 'layers'. So if your player has on a jacket and shirt, he can't take the shirt off without removing the jacket first - can't put his socks on if he already has shoes on - you get the idea I'm sure. Obviously there are 'wear' and 'take off' commands in the lib to deal with this.

To use the clothing - you just have to define it as a type. Everything else is dealt with by the lib. e.g.

define object <parka>
type <jacket>
look <lime green and french blue panels - tasteful!>
end define

Is all you need for a 'fully working' jacket object that knows its place in the clothing layers :-)

All the other types have similarly 'developed' behaviour, The human type is also a container and so on but as the manual explaing it all is 15 pages long I'll leave it at that for now. :-)

I'm trying to build objects that are 'use out of the box' real world items here.

Al

Mega posted 08-10-2001 03:21 GMT          
Thanx for all your help, guys! By the way Al, many thanx for the help with object types. I further modified your code to allow for the overwriting of the message printed in the 'open' and 'close' actions, as well as the 2 messages for 'look'. Here's my version:

define game <>
asl-version <300>
start <outside gate>
game info <Created with QDK 3.02 - then hacked by MaDbRit :-) >
command <open #object#> {
if action <#object#; open> then doaction <#object#; open>
else msg <You can't do that.>
}
command <close #object#> {
if action <#object#; close> then doaction <#object#; close>
else msg <You can't do that.>
}
end define

define synonyms
end define

define room <outside gate>
description msg <You are standing outside the gate of the gloomy castle of the evil wizard Moldrok.>

define object <gate>
type <openable>
properties <lookcloseddesc = This ancient gate is made of sturdy iron bars, which over __
the years have become covered in rust and entangling vines. Beyond the __
gate you can see the castle courtyard>
properties <lookopendesc = The ancient, rusty gate lies open, beckoning you into the __
castle courtyard>
properties <opendesc = With an eerie creak, the ancient gate slowly opens>
properties <closedesc = The ancient gate slowly closes>
end define
define object <box>
type <openable>
end define

end define

' This section defines the 'openable' type and provides open, close & look actions.
define type <openable>
closed
properties <lookcloseddesc = null>
properties <lookopendesc = null>
'start new
properties <closedesc = null>
properties <opendesc = null>
'end new

action <open> {
set string <lookedat; $thisobject$>
if property <$thisobject$; closed> then {
if ($objectproperty(#lookedat#; opendesc)$ = null) then {
property <$thisobject$ ;opendesc =You open the #lookedat#.>
}
else {
property <$thisobject$ ;opendesc = $objectproperty(#lookedat#; opendesc)$>
}
property <$thisobject$; not closed>
msg <$objectproperty(#lookedat#; opendesc)$>
}
else msg <The #object# is already open.>
}

action <close> {
set string <lookedat; $thisobject$>
if not property <$thisobject$;closed> then {
if ($objectproperty(#lookedat#; closedesc)$ = null) then {
property <$thisobject$ ;closedesc =You close the #lookedat#.>
}
else {
property <$thisobject$ ;closedesc = $objectproperty(#lookedat#; closedesc)$>
}
property <$thisobject$; closed>
msg <$objectproperty(#lookedat#; closedesc)$>
}
else msg <The #object# is already closed.>
}

action <look> {
set string <lookedat; $thisobject$>
if property <$thisobject$; closed> then {
if ($objectproperty(#lookedat#; lookcloseddesc)$ = null) then {
set string <lookmessage ;The #lookedat# is closed>
}
else {
set string <lookmessage ;$objectproperty(#lookedat#; lookcloseddesc)$>
}
}
else {
if ($objectproperty(#lookedat#; lookopendesc)$ = null) then {
set string <lookmessage ;The #lookedat# is open>
}
else {
set string <lookmessage ;$objectproperty(#lookedat#; lookopendesc)$>
}
}
msg <#lookmessage#.>
}

end define
'end of type definition

define text <intro>

end define

define text <win>

end define

define text <lose>

end define

MaDbRiT posted 08-10-2001 08:12 GMT          
quote:

I further modified your code to allow for the overwriting of the message printed in the 'open' and 'close' actions, as well as the 2 messages for 'look'.

Which is one of the things I did when I added the improved 'openable' type to my library too... LOL

Actually in my lib it is a bit more complex because that provides 'container' objects, so the 'examine' messages are also tailored to provide different results for open / shut container objects - the contents are only described if a container is open ('container' and 'openable' are a most useful pairing of course)


Cheers

Al