Howdy, Stranger!

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

How do I link variable images with

edited November 2016 in Help! with 2.0
<<set $pies = [ "Blueberry", "Cherry", "Cream", "Pecan", "Pumpkin" ]>>

  <<set _x = $pies.pluck()>>


<<set $x = $pies.pluck()>>

 
I'll choose the <span id="pie"></span>, please.\
<<timed 3s>><<replace "#pie">><<link "OPTION 1" >><<print '<img src="' + $x + '.jpg" height="100" width="100">'  >> <<goto _x>> <</link>><</replace>>\
<<next>><<replace "#pie">><<link "OPTION 2" >><<goto $x>><<print '<img src="' + $x + '.jpg" height="100" width="100">'  >> <</link>><</replace>>\
<</timed>>
This doesn't work.
<<link [img[$x][$x]]>> <</link>> 
This ,while not what I want to set out to do, also doesn't work for various reasons which I dont understand. First <<link>> only reads $x as $x and not as a value from an array..

Okay, I got the image to work by putting the <<print ...>> code before the <<link>>.

That made me realize that the image will be the same one each time unless I can print $pies.pluck() instead of $x for the <<print>> image variable.

Perhaps a loop..



Edit 3:
IT works
<<timed 3s>><<replace "#pie">><<link "OPTION 1" >><<print '<img src="' + $pies.pluck() + '.jpg" height="100" width="100">'  >> <<goto _x>> <</link>><</replace>>\
<<next>><<replace "#pie">><<link "OPTION 2" >><<goto $x>><<print '<img src="' + $pies.pluck() + '.jpg" height="100" width="100">'  >> <</link>><</replace>>\
<</timed>>
Suddenly $pies.pluck() works for me and now my code goes through different random images.

I was used to $pies.pluck() not working
because of stuff like this
<<link [[$pies.pluck()|$t]] "$t">><</link>>

Comments

  • edited November 2016
    Ideally I want to be able to have different images displayed and replaced with the timed macro but ive spent hours trying different variations of ways to make it work in the link macro with no luck.
    <<link [[$pies.pluck()|"$x"]]>><<script>><</script>><</link>>
      <<link [[$pies.pluck()|"$x"]]>><<goto $pies.pluck()>><</link>>
    
    but
    <<link "$x">><<goto $x><</link>>
    This does work. Now I'd like to insert an image link there and have different images cycle through, thats what I cant get it to work
  • edited November 2016


    Edit: Okay, shut down the thread. Just kidding. I have everything I wanted working.
    <<timed 3s>><<replace "#pie">><<set _t = $pies.pluck()>><<print '<img src="' + _t  + '.jpg" height="100" width="100">'  >><<link "OPTION 1" >> <<goto _t>> <</link>><</replace>>\
    
    This takes a random number, assigns it to a variable, and displays that numbers associated image and passage.

    And I repeat this code over and over until the need for using loop arises.
  • edited November 2016
    <<set $pies = [ "Blueberry", "Cherry", "Cream", "Pecan", "Pumpkin" ]>>
    
    
    <<for $i to 1; $i lte 100; $i++>>
    
    I'll choose the <span id="pie"></span>, please.\
    <<timed .3s>><<replace "#pie">><<set _t = $pies.pluck()>><<print '<img src="' + _t  + '.jpg" height="100" width="100">'  >><<link _t >> <<goto _t>> <</link>><</replace>>\
    
    <<next>><<replace "#pie">><<set _t = $pies.pluck()>><<print '<img src="' + _t  + '.jpg" height="100" width="100">'  >><<link "_t" >> <<goto _t>> <</link>><</replace>>\
    
    <<next>><<replace "#pie">><<set _t = $pies.pluck()>><<print '<img src="' + _t  + '.jpg" height="100" width="100">'  >><<link "_t" >> <<goto _t>> <</link>><</replace>>\
    
    <<next>><<replace "#pie">><<set _t = $pies.pluck()>><<print '<img src="' + _t  + '.jpg" height="100" width="100">'  >><<link "_t" >> <<goto _t>> <</link>><</replace>>\
    
    <<next>><<replace "#pie">><<set _t = $pies.pluck()>><<print '<img src="' + _t  + '.jpg" height="100" width="100">'  >><<link "_t" >> <<goto _t>> <</link>><</replace>>\
    
    <<next>><<replace "#pie">><<set _t = $pies.pluck()>><<print '<img src="' + _t  + '.jpg" height="100" width="100">'  >><<link _t >> <<goto _t>> <</link>><</replace>>\
    
    <<next>><<replace "#pie">><<set _t = $pies.pluck()>><<print '<img src="' + _t  + '.jpg" height="100" width="100">'  >><<link "_t" >> <<goto _t>> <</link>><</replace>>\
    
    <<set $pies = [ "Blueberry", "Cherry", "Cream", "Pecan", "Pumpkin" ]>>
    <</timed>>
    
    <<set $pies = [ "Blueberry", "Cherry", "Cream", "Pecan", "Pumpkin" ]>>
    <</for>>
    
    
    Why doesn't this work? I thought it would keep repopulating the array and keep putting random images on display until a large amount have been shown.
  • I'm not going into detail over every single thing wrong with all of the code within these posts—including, but not limited to: quoting variables, using <<goto>>, using .pluck() instead of .random(), loop scoping issues, etc.

    How about you explain what it is, exactly, you're attempting to do and I tell you how to do that.
  • I'm trying to loop 5 images tied with passage links over and over until the loop limit has been reached.
    So I want , and made, an image of pecan and a link to go to pecan passage to show up for a set amount of time, before going to the next $pie.

    This i've done with the above code. Now I'd like to loop it,.
  • You should use the <<repeat>> macro instead of <<timed>>. The former is best used when you want to repeat some code an arbitrary number of times on a timer. The latter is best used when you want to run some code once on a timer.

    For example, the following will show 100 image links—an initial one, then it will cycle 99 more:
    <<set
    	_pies to clone($pies),
    	_p    to _pies.pluck()
    >>
    \I'll choose the <span id="pie">[img[_p  + '.jpg'][_p]]</span>, please.
    \<<silently>>
    	<<set
    		_i   to 0,
    		_max to 99
    	>>
    	<<repeat 3s>>
    		<<if _i lt _max>>
    			<<if _pies.length is 0>>
    				<<set _pies to clone($pies)>>
    			<</if>>
    			<<set _p to _pies.pluck()>>
    			<<replace "#pie">>[img[_p  + '.jpg'][_p]]<</replace>>
    		<<else>>
    			<<stop>>
    		<</if>>
    		<<set _i++>>
    	<</repeat>>
    <</silently>>
    
    If you just wanted to cycle through the image links in-order over and over, rather than randomly plucking the list to exhaustion and restarting, then this could be a bit simpler.
  • <<link "$x">><<script>><</script>><</link>>

    why doesn't this work for me?
  • Two issues with that construct. You're quoting the variable when you should not be and you have a useless empty <<script>> tag. Beyond that, unless your going to do something meaningful with the <<link>> macro, then the link markup is sufficient to create the link. For example:
    [[$pies.pluck()|$x]]
    
Sign In or Register to comment.