intfiction.org

The Interactive Fiction Community Forum
It is currently Wed Jun 19, 2013 2:58 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Mar 20, 2012 4:55 pm 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 904
I'm trying to adapt the pop-up menu from the "One with Everything" demo in such a way that a given command will appear in the menu only once, until it's used. I can't see how to do this. Here's what I tried:
Code:
      + vorple.html.p(
              vorple.html.link([
                        {
                            content: 'Look at her',
                            url: './lookatjulia',
                            classes: 'once'
                        },
                        {
                            content: 'Talk to her',
                            url: './talktojulia'
                        }
                    ],
                    'Julia' ,
                    { classes: 'transient' }
                )
                + " kneels at the prow, leaning forward over the onrushing sea."
          )

However, setting the upper item to classes: 'once' has no effect. The command is still in the menu after being used, and can be used again. Obviously, I don't want the make the whole link 'once', because it will ultimately contain four or five commands. I just want 'once' to apply to individual commands within it.

This code is declarative rather than procedural, so there's no obvious way to insert an if-test. I could possibly insert an if-test at the very start of the enter function, but that would mean duplicating the entire system.write block 2-to-the-(n-minus-1) times, where n is the number of menu items that may need to be shut off. That type of thing would be hideous to maintain, so there just has to be an easier solution. But I'm nowhere near familiar enough with Javascript, CSS, or the Vorple library to see how to do it.

Suggestions would be much appreciated!


Top
 Profile Send private message  
 
PostPosted: Wed Mar 21, 2012 4:48 am 
Offline

Joined: Tue Dec 25, 2007 10:06 am
Posts: 898
The easy solution is to use disposable links instead of once links. Once-links clear from the screen only at the time they're clicked, and since the popups are hidden anyway there's no actual effect.

The downside is that with disposable links the choice is not removed from the popup, it's just not clickable anymore. If you want the entire choice removed, you need to build the list of choices dynamically.

Initialize a flag in undum.game.init():

Code:
character.sandbox.juliaSeen = false;

The situation:

Code:
vorple.html.p(
    vorple.html.link(
            (function() {
                // start with an empty set of choices
                var choices = [];
               
                // add the choice only if a flag is not set
                if( !character.sandbox.juliaSeen ) {
                    choices.push({
                        content: 'Look at her',
                        url: './lookatjulia'
                    });
                }
               
                // this choice is always available
                choices.push({
                    content: 'Talk to her',
                    url: './talktojulia'
                });
               
                // return the choice set we just built
                return choices;
            })(),
            'Julia' ,
            { classes: 'transient' }
        )
        + " kneels at the prow, leaning forward over the onrushing sea."
  )

In the lookatjulia action toggle the flag and remove the choice:

Code:
character.sandbox.juliaSeen = true;
$( '.linkPopup a[href="./lookatjulia"]' ).parent().remove();


The anonymous function in vorple.html.link builds the choice set dynamically based on whatever logic you put there every time the reader enters the situation. The last line in the lookatjulia action removes the choice in the current popup, otherwise the choice would not be disabled until after the reader enters the same situation again. (Note that the "don't use SimpleSituation with a string argument" caveat applies.)

_________________
Vorple UI libraryBeta testing siteBlog


Top
 Profile Send private message  
 
PostPosted: Wed Mar 21, 2012 11:27 am 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 904
Thanks, Juhana. That all makes sense to me, except for the final line of code, the one starting with $. I sort of get that that causes the script to "forget" the return value of the anonymous function, so it runs again the next time the menu is used. But the actual syntax, and the reasons why it works, are shrouded in veils of mystery....

I think it's probably time for me to start studying Javascript seriously. There's a lot that can be done with it -- basically, anything. But it's very much a DIY situation, so it would be wrong for me to keep pestering you for solutions to one-off problems.

BTW, Ian Millington tells me he's not planning to add a more robust game-saving functionality to Undum unless/until he gets more requests. There's another reason why I need to become proficient in Javascript! Customizing Undum should ultimately be easier than customizing the behavior of TADS, because the TADS compiler and virtual machine are black boxes. (To me, at least -- the source code is available.) But the path to mastery of the "normal" functionality of Undum is not easy at all.


Top
 Profile Send private message  
 
PostPosted: Wed Mar 21, 2012 1:22 pm 
Offline

Joined: Tue Dec 25, 2007 10:06 am
Posts: 898
Jim Aikin wrote:
That all makes sense to me, except for the final line of code, the one starting with $. I sort of get that that causes the script to "forget" the return value of the anonymous function, so it runs again the next time the menu is used. But the actual syntax, and the reasons why it works, are shrouded in veils of mystery....

Actually the last line just removes one option from the popup and leaves the rest there, the anonymous function isn't affected at all. The $ is a jQuery object which is mostly used to manipulate HTML document elements. Normally you wouldn't need it but this case is more of a hack. (I'll think about adding the functionality to Vorple.)

Now that I think about it the last line is all you need, provided that the reader can never return to that same situation again. All the rest is just for making sure the popup is built correctly when entering the situation more than once. The anonymous function trick is still useful to know, it comes in handy in many cases.

_________________
Vorple UI libraryBeta testing siteBlog


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: Shadow Wolf and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group