More open / close problems

Well I say more, but it's the same issue. I'm starting a new thread to try and keep things less cluttered.

With the doors I assumed I'd got to the bottom of this when Jay pointed out it was probably because I was using my own flags. With this new issue that's not the case, but the object is still closing itself automatically.

The object in this case is a music box which plays its tune when opened, and stops when closed.

This is my set up:

  • The object is called music box.
  • In the object tab I've given it box and lid as other names
  • In the Features tab I set it to Container, then in the Container tab make it openable/closable
  • I have both Can be opened and Can be closed ticked, and Is open unticked.
  • The script for when container is opened is:
msg ("You open the lid. It's a music box and it begins to tinkle out its little tune.")
play sound ("innmusicbox.mp3", false, false)
  • The script for when container is closed is:
msg ("You close the lid.")
stop sound

In the verbs tab for the object I have: lift lid; open lid; open box (and the relevant scripts from above) and shut lid; close lid; close box; shut box (and the relevant scripts from above)

Despite all this, when I run the game and lift the lid, the music starts as it should, but when I type close lid I get It is already closed and the music plays on.

Can anyone see why this isn't working?

I think it might be good old custom commands to the rescue here! It would be so much easier in fact.


The code below works just fine for me.

EDIT: If I were to do this again, I would definitely choose a LIMITED container and set objects to zero!! I just added a dog object. Picked it up and put it in the music box. So... unless there is a way around this that I am missing, I would choose limited container so some snarky asshat wouldn't stuff something like a dog into a music box. In the container is full box, after you set limit to zero, you can handle all objects someone might toss in there as "That's not possible, you snarky asshat." =)

<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Music Box Test">
    <gameid>ddb1b1a6-52c6-433d-b976-6b994b1c3e91</gameid>
    <version>1.0</version>
    <firstpublished>2016</firstpublished>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <object name="music box">
      <inherit name="editor_object" />
      <inherit name="container_closed" />
      <alt type="stringlist">
        <value>lid</value>
        <value>box</value>
      </alt>
      <look type="script">
        if (music box.isopen) {
          msg ("It's a music box.  It's open and currently playing music.")
        }
        else {
          msg ("It's a closed music box.")
        }
      </look>
      <feature_container />
      <openmsg>You open it and a lovely tune starts to play.</openmsg>
      <closemsg>You close it and the music stops.</closemsg>
      <lift type="script">
        HelperOpenObject (music box)
        msg ("You open it and a lovely tune starts to play.")
      </lift>
      <shut type="script">
        msg ("You close it and the music stops.")
        HelperCloseObject (music box)
        stop sound
      </shut>
      <onopen type="script"><![CDATA[
        play sound ("Tech N9ne - Strange Music Box (Feat. Krizz Kaliko & Brotha Lynch Hung).mp3", false, true)
      ]]></onopen>
      <onclose type="script">
        stop sound
      </onclose>
    </object>
  </object>
  <verb>
    <property>lift</property>
    <pattern>lift</pattern>
    <defaultexpression>"You can't lift " + object.article + "."</defaultexpression>
  </verb>
  <verb>
    <property>shut</property>
    <pattern>shut</pattern>
    <defaultexpression>"You can't shut " + object.article + "."</defaultexpression>
  </verb>
</asl>

The difference I think is:

  1. I have it set as a closed container.
  2. put lift and shut as different verbs under the music box object. Do you have 'lift lid' as a verb or just 'lift'?
  3. Do you have an 'open object' script under the verb lift?

Also, not sure if you did this or not, but if you put the scripts to play and stop the sound in ONLY the upon open and upon closing area under container tab, you only need to do this one time as long as you have your open/close object scripts under your verbs lift and shut.


Yes, I have 'lift lid' as the verb.

I'm not sure about 3.

But just looking at all that for such a simple action makes me wonder why I don't just use custom commands for everything. All I need to do is create the object, fill out the 'look/x' description and leave everything else alone. Then all I need is two custom command patterns in the room; one that handles the opening and another for the closing.


Can you take the music box? If so, it will be a mess to put the custom command as universal. What I did is very simple, it just looks a lot in code.

  1. Create music box.
  2. Choose limited container. Set limit to zero. Type proper full container message.
  3. In the when open box, play sound.
  4. In the upon closing box, stop sound.
  5. Add 'lift' verb to box. Add 'open object music box' script.
  6. Add 'shut' verb to box. Add 'close object music box' script.
  7. In the description box, add an 'if object music box is open' print message. Else print message script.

EDIT: And why would you have 'lift lid' as the verb? If you have lid added as another name for the music box, just 'lift' will do.


Yeah, the lift lid was a mistake. In fact they all are. None of the verbs should have the object names afterwards (maybe that was the problem)??

No, you can't take the music box.

Anyway I added the two custom command patterns to the room and it works perfectly. Custom commands are the best thing I was ever told about in Quest. They're the future! They handle practically anything and are a fraction as complex to set up as the purpose built functions.


So...
1a. You added a command like:
open box; open music box; open music; open lid
1b. You put the scripts to play the music under this command.
1c. You set a flag to identify the box is open.

2a. You added another command like:
close box; close music box; close music; close lid; shut lid; shut box; shut music box; shut music
2b. You put the scripts to stop the music under this command.
2c. You unset the flag from 1c to identify the box is closed.

You also added a If flag is set script on the music box under the look at description for the music box.

Right?

How would you deal with someone, like me, who types 'open mus'?
I know there are ways to creatively code for shut/close lid/box/music in one fancy regular command script like:
^(open|lift|play|use) (the |)(music|music box|lid) but that is super confusing to me...

To each their own I guess, but your way seems more complicated with a higher risk of error. lol =P

Best of luck!


But isn't your method just as lax at catering for the various commands that may be used? They both rely on the player typing the correct command, yes? And wouldn't your method of 'open mus' be handled by 'open music box', or does it have to be the exact wordage with commands?

As for setting an if flag on the look description, that's not necessary as I've made sure the look description is relevant whether the music box is open or closed. I haven't even used if flags on the open close because if they close it manually they will get a message saying so, and if they allow it to play out it should just be assumed they close it when it's finished. I know what you're saying - if they open it and then leave the room, it should still be open if they go back in, but I can live with that not being so. The game just assumes they closed it before leaving the room.

So, to answer your question, all I did was:

  1. Create the music box object and add a look description.
  2. Create a command pattern catering for all the possible 'open' commands (run a script to open and play music)
  3. Create a command pattern catering for all the possible 'close' commands (run a script to close and stop the music)

Three simple steps.

I think the reason yours looks so daunting is because you've pasted the entire test game code, rather than just the UI scripts.


The problem in the original post is, I think, that you need to set the isopen attribute to true when the box is opened, and false when closed. Quest will do that for you if you have no script, but if you add your own script, you need to do it yourself (this would allow you to only open it if the player has the key, say).


"Open mus" will not be accounted for with commands although there is a way to create a regular expression command to handle that but I don't know it.
So, if they look at an open music box vs a closed one, they get the same description? I'm incredibly obsessed with this minutia so I almost always put an if script in look at description for ANYTHING that can open, play sound, be turned on or off, or just change appearance for whatever reason. All my NPCs have if scripts in their descriptions.
I've used your method before but I tend to get muddled by commands - either forgetting obvious ones, doubling already typed ones, etc. I reserve commands for simple, one-direction type processes only. I guess I just need more practice with them! :)


Thanks, TP, I didn't know this.

Xan, I double up my commands all the time - something I always have to watch for - so you're not alone there.

I know exactly where you're coming from in regards to the current 'state' of objects, but I suspect I'm either getting lazy or just over-coming my obsession to cater for this attention to detail.

My 'look' description for the music box just refers to its approx dimensions, decorative painting and a lid which is hinged at the back. This means that the only time this description wouldn't make sense, is if the player typed > open music box and then immediately followed it up with > x music box - even then it still kind of makes sense anyway. Add to this the fact that when it's open it will be playing music, so do they really need telling it's open?


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums