0 votes
by (230 points)

I´m creating an inventory system where you can also see your character appearance change as you equip different clothes.For example, here I'm trying to show a piece of armor that's inside an object. BTW i´m using sugarcube 2 and twine 2.

//This is how I declare the object previously, I want all the information about the item to be inside an object, including the image

<<set $ACplate ={name:"Plate Armor", pro:10, prc:50,img:"Char/plate.png"}>>

In the passage where I want to display all the images of the character wearing the armor, I have been able to show images without a problem, and they show in the correct place, size and they overlap each other well.

<div
	style="position: relative; width: 574px; height: 1000px; padding: 5px; border: 0px solid grey">
<img
		src="Char/default.png"
		style="position: absolute; left: 0; top: 0; width: 574px; height: 1000px">

<<if ($face eq 1)>>
<img
        src="Char/face1.png"
        style="position: absolute; left: 0; top: 0; width: 574px; height: 1000px">
<<else>>
<img
        src="Char/face2.png"
        style="position: absolute; left: 0; top: 0; width: 574px; height: 1000px">
<</if>>

//Around here is where i would like to put the sentence that shows the image, and it would have to be in the same position as all the other images

</div>

But these ones aren't inside an object so i know how to display them, the question is how do i call the image from inside the object and how do i make it appear in the right size, position and what determines which images are going to overlap.

1 Answer

0 votes
by (68.6k points)

In the current version of SugarCube (v2.23.5), which is more recent than what comes with Twine 2.2.1, you may use the evaluate attribute directive:

<img @src="$ACplate.img" style="…">

In older versions, you may use the Stupid Print Trick™:

<<print '<img src="' + $ACplate.img + '" style="…">'>>

 

There are other ways, but those are the easiest two.

...