Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Random Words with Cycling Link?

Is it possible to use the cycling link macro to generate random words? Instead of using just three words it will select a random word every time you click the word to cycle.

Thank You
InsertCoin25

Comments

  • Not sure if it's what you mean, but I recently played with randomizations recently with this project:

    http://gamejolt.com/games/other/rose-window/37018/

    And basically I just used the "either ()" function such as:

    [quote][[<<print either("It's chasing me","It has to stop","I can't cry","It's burning","It's staring at me","I want to hurt it","It's on me","It knows","I lose it","It's crawling","Its mouth","It's strangling me","Silently","Endlessly","It's still here","I can't hurt it","I am not worth it","It aches","Its eye","Its nail","It's falling","It craves for more","It's flaying me","It's going deeper","My mind","It's crumbling","I hate it","It hisses","It's on the ground","My hair", "It's melting", "It's seeping in me","I can't scream","I can't flee","I can't look at it","It's laughing at me", "Fiercely","I can't move","I can't breathe","Or maybe it's not","Maybe I like it","I can't help it","Maybe I deserve it","Maybe I was born this way","Maybe it's my fate","It's not the first time","It's growing in me","It's sucking my skin","It's ravaging me","It's angry","It's slippery")>>|window1]]

    Basically the link is linking to the same passage - window1.

  • I was looking more toward the cycling link selecting a random word out of the list each time it is clicked. For example you have 50 words in one cycling link and it chooses at random a word from those 50 words every time you click it. Thank you for the example though Galejade I greatly appreciate any feedback I can get.

    Thank You
    InsertCoin25

    Example Code:<<cyclinglink print either ("grass" "a flower" "a cloud" "the road")>> ---- Would this work or is the code completely wrong? In theory this should print either of these four words at random. But, my theory may be wrong:).
  • The example you supplied would not work even if you formatted it correctly like:

    <<print "<<cyclinglink " + either("grass" "a flower" "a cloud" "the road") + ">>">>
    This is because the either function only returns one of the items from the list you supply it, so the output of the above would be something like:

    <<cyclinglink "a flower">>
    How the existing code works is it creates a single link containing each of the different option you supplied:

    <<cyclinglink "grass" "a flower" "a cloud" "the road">>

    becomes the following HTML

    <a class="internalLink cyclingLink" data-cycle="0">
    <span class="cyclingLinkInit cyclingLinkEnabled">grass</span>
    <span class="cyclingLinkInit cyclingLinkDisabled" style="display: none;">a flower</span>
    <span class="cyclingLinkInit cyclingLinkDisabled" style="display: none;">a cloud</span>
    <span class="cyclingLinkInit cyclingLinkDisabled" style="display: none;">the road</span>
    </a>

    And each time you click on the link the previous option becomes invisible/disabled and the next visible/enabled until the last item in the list is shown and will either go back to the first item or stop if the <b>end</b> or <b>out</b> option was used.
    It would only take two small changes to a copy of the existing macro's code to make the selection of the next text to show random: (note: this code can result in the same item shown multiple times in a row, it is random after all)

    u = (u + 1);
    becomes:
    u = (u + randomIntFromInterval(1,m));

    add function:
    function randomIntFromInterval(min,max) {
    return Math.floor(Math.random()*(max-min+1)+min);
    }
    But there is a problem with what to do about the end and out features of the cyclinglink macro, because the items are shown in a random order there is not really a last item in the sequence so how does the code know when to stop showing another item from the list?
  • This may help out. There will be 3 or 4 different cycling links and these cycling links will be words that form a sentence. After the user has formed a sentence there will be another link that is used to execute and check to see if the sentence is valid. So a crude illustration:

    Link 1 (Word) Link 2 (Word) Link 3 (Word) Link 4 (Word)  Link 5 (Checks Sentence)

    Thank you greyelf for the examples and code. I am wondering if you can put the end and out of the cycling link in the link that executes and checks the sentence?

    Thank You
    InsertCoin25






  • Try the following code:
    (note: Using TWEE notation. Lines starting with a double colon :: indicate a new passage with a related title, a title ending with [script] indicates Script Passage.

    :: StoryInit
    <<set $final_1 to "">>
    <<set $final_2 to "">>
    <<set $final_3 to "">>


    :: Start
    Click on the links: \
    <<randomlink $final_1 "Aaaa" "Bbbb" "Cccc" "Dddd" "Eeee">> \
    <<randomlink $final_2 "Aaaa" "Bbbb" "Cccc" "Dddd" "Eeee">> \
    <<randomlink $final_3 "Aaaa" "Bbbb" "Cccc" "Dddd" "Eeee">>
    To check what was selected go to the [[Next Passage]]


    :: Next Passage
    Final options were: 1: <<print $final_1>> 2: <<print $final_2>> 3: <<print $final_3>>
    The back link rewinds history. so forgets what was selected: <<back>>
    The return link remembers what was selected: <<return>>


    :: randomlink macro [script]
    version.extensions.randomlinkMacro={major:1,minor:0,revision:0};
    macros.randomlink={handler:function(a,b,c){var rl="randomLink";function toggleText(w){w.classList.remove("randomLinkInit");w.classList.toggle(rl+"Enabled");w.classList.toggle(rl+"Disabled");w.style.display=((w.style.display=="none")?"inline":"none");}function randomIntFromInterval(min,max){return Math.floor(Math.random()*(max-min+1)+min);}var v="";if(c.length&amp;&amp;c[0][0]=="$"){v=c[0].slice(1);c.shift();}var h=state.history[0].variables;var l=Wikifier.createInternalLink(a,null);l.className="internalLink randomLink";l.setAttribute("data-cycle",0);for(var i=0;i<c.length;i++){var on=(i==Math.max(c.indexOf(h[v]),0));var d=insertElement(null,"span",null,"randomLinkInit randomLink"+((on)?"En":"Dis")+"abled");if(on){h[v]=c[i];l.setAttribute("data-cycle",i);}else{d.style.display="none";}insertText(d,c[i]);l.appendChild(d);}l.onclick=function(){var t=this.childNodes;var u=this.getAttribute("data-cycle")-0;var m=t.length;toggleText(t[u]);u=(u+randomIntFromInterval(1,m));u%=m;if(v){h[v]=c[u];}toggleText(t[u]);this.setAttribute("data-cycle",u);};}};
    I modified a copy of Leon's cyclinglink macro, all the hard work and good parts are his, any bad parts are mine.
  • Awesome...thank you for the code. I will try when I get home. Is it possible to have the link check the sentence in the same passage instead of a new passage? Thank you again greyelf.

    InsertCoin25
  • Each usage of the randomlink only knows about the variable it is setting so can't check the others.

    There is no link macro that I know of that knows how to check a set of variables for predetermined values and that only proceeds to the next passage if those values are correct. To build such a macro would require combining the expression evaluation functionality of the <<if>> macro with the standard link code, adding a dash of notification to let the end-user know why the link does not seem to be working when the related variables don't contain the correct values.

    It would take me awhile to build such a macro, it make be worth your while asking Leon or TheMadExile for help.
  • Ouch!!! That is exactly what I needed. Thank you greyelf for the help that you provided up until this point. Well Leon or TheMadExile if you are reading this post is there anyway this could be achieved or worked on? Thank you again for the help greyelf, I do greatly appreciate this.

    Thank You
    InsertCoin25
Sign In or Register to comment.