Hi folks,
I am really new to Twine and coding. Everything I know I have learned through google and reading through this forum. I am currently stuck with a few different issues, and I was hoping someone may be able to point me in the right direction.
I am currently working in Sugarcube and have a code for an inventory/codex system. In this code, each inventory/codex item as a separate passage that describes or gives further information for that item/person/etc. I was wondering if there is away to put the "Codex entry added" part of this code at the bottom of the passage? I was thinking that may be something that happens in the footer, but I haven't entirely figured that out yet.
<<linkappend "Wolves">><<addToCodex "Wolves">> Codex entry added. <</linkappend>>
I was having a really hard time figuring out the best way to operate my Codex/Inventory codes. If you have any advice, I would love it.
Next question:
I am trying to build a combat system in Sugarcube. I haven't been able to figure out how to create variables to deduct and add health. The code I have right now is:
<progress id="health" max=100></progress>
<div id="val"></div>
<script>
while (true){
document.getElementById("health").setAttribute("value", $health);
}
</script>
I have this code in the StoryCaption passage because I wanted it to appear in the sidebar for consistency. I haven't been able to figure out what I'm doing wrong.
I'm sorry these are kind of silly questions. I appreciate any help.
Comments
Another method might be to create a <span> area that gets added to the page via the <<link>>.
There might be a way to assign something to a footer section, but I'm not a very good coder either (Greyelf, Madexile, and Chapel will a have much better idea of how to go about things).
A span is a designated area. You can give it a class that will work with any defined class you put into the CSS section. It can also have an ID that gets referenced if you want a piece of code to <<replace>> its contents with something else. The backslashes stop it from printing out a new linebreak. I don't know if that will help much, but it could be one way to update and add text to the end of the page on doing something.
Also, I think anybody familiar will be able to tell from your code that you're using one of the 2.versions of sugarcube, but it's usually best to be specific around here about which versions of everything you have. It can make quite a big difference sometimes. =^^=
Also. Please use the code tag—it's C on the editor bar—when posting code or markup.
You could do something like the following. In your PassageFooter special passage: Then whenever you want to add something to that notification area: The line break (<br>) within the <<append>> is there simply so that if multiple notifications happen during the same passage, they'll appear on separate lines. If that will never happen or you'd prefer them to appear on the same line, simply remove it.
You have several problems here.
The following, which comes in three parts (markup, styles, and code), is what I'd suggest.
Meter markup: (goes wherever; though I suggest a passage named StoryMeters, see the code section below for additional details)
To be used with the code below, the ID must match the name of the associated story variable. I hope the other attributes are self-explanatory—if not, ask away.Meter styles: (Twine 2: goes in Story Stylesheet; Twine 1: goes in stylesheet-tagged passage)
Meter code: The following code creates a new UI bar element, populates it with the contents of the custom StoryMeters special passage, and sets up a recurring timer to update all of the meters: (Twine 2: goes in Story JavaScript; Twine 1: goes in script-tagged passage)
For the styles. Simply add new rules, after the set given in my last post, prefixed by the ID selector of the meter for which you want to provide an override. For example, here's how you'd change the health and mana meters' colors to red and blue:
For the code. Nothing needs to change. Just remember that the ID of the meter must match the story variable name—i.e. if the ID is health the story variable must be $health, ID mana ⇒ story variable $mana, etc.