Howdy, Stranger!

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

Sugarcube 2.7.0 Is it possible to set an image as a variable?

Hello All,

In the game I'm working on, I'm having the player write their team name and choose an icon to represent that team.

So far, I've got:
What is your team name?
<<textbox "$team.name" "">>

Choose a symbol to represent your team:

<<click [img[images/01.png]]>><<set $team.icon to '<img src="01.png" />'>>
<</click>><<click [img[images/02.png]]>><<set $team.icon to '<img src="02.png" />'>>
<</click>>

I'm setting up the widget macro so that it displays the team name and icon along the top of the story throughout the duration, like this:
@
...

The image displays just fine, and when I clicked on the image and set the $team.icon to text, it displayed no problem. Is it possible to have an image stored as a variable? Or is my syntax just off? Thank you!

Comments

  • Try:
    <<click [img[images/01.png]]>><<set $team.icon to "images/01.png">><</click>>
    
    @
    
  • Awesome. That did it. You guys are so good, and quick, too.

    Follow-up question: would you be able to point me in the right direction to get the image and the $team.name to appear next to each other instead of on top of one another? I tried:
    @<;/b><</nobr>>
    

    ...to no avail. Image appears on one line, and text appears below it. Both are aligned left.
  • hausrath wrote: »
    Follow-up question: would you be able to point me in the right direction to get the image and the $team.name to appear next to each other instead of on top of one another?
    The main issue with your example is that you are using a h2 heading element.

    By default all heading elements are displayed as a block, which is causing your image to appear on a difference line. If you remove the h2 tag then the image and text will appear on the same line.

    note: The h2 element's default font-size is 1.5em.
  • As an alternative to greyelf's suggestion to remove the heading, you could move the heading markup so that it wraps both the team icon and name. For example:
    @.emboss;$team.name@@<;/h2>
    
  • You guys are great! Thanks very much once again!
Sign In or Register to comment.