Started on twine few days ago and got a few questions.
I've been using this to assign points at character creation:
<<if $PC.Strength gt 1>><<click "[←]">><<set $PC.Strength-->><<set $karma++>><<replace "#cc-str">><<print $PC.Strength>><</replace>><<replace "#karma">><<print $karma>><</replace>><<script>>state.display(state.active.title, null, "back")<</script>><</click>><<else>>[←]<<endif>> \
<span id="cc-str"><<print $PC.Strength>></span> \
<<if $karma gte 1 and $PC.Strength lt 18>><<click "[→]">><<set $PC.Strength++>><<set $karma-->><<replace "#cc-str">><<print $PC.Strength>><</replace>><<replace "#karma">><<print $karma>><</replace>><<script>>state.display(state.active.title, null, "back")<</script>><</click>><<else>>[→]<<endif>>
I'd like to know if there is a way to update <<if>> without using state.display(state.active.title, null, "back"). It does the page transition which gets annoying when there are that many clicks and it also resets radio/checkboxes I used for other things on that passage. I wouldn't mind if anyone shared an easier way to do the whole thing either.
How can I use <<return>> to go to last visited passage with a certain tag? I've seen method by Novbert in another topic, just asking if there is a simpler way.
A way to apply <abbr> without having words underlined.
I placed Clock in StoryMenu but that only updates it when passage changes. Is there a way to make it immediately update on any action that changes it(without including it in the action)?
I was also thinking of calculating time something like $time.minutes % 60 and add 1 to $time.hour. Is this possible?
How to append st nd rd th to $time.date (1st, 2nd, etc).
Made array for weekdays and months but not sure how to cycle them...
I don't expect handouts but right now I'm more or less just copy/pasting from various sources and I'm not sure if some of these things are built in and if not whether they should be done in java or CSS.
Comments
I covered a simpler way to do this here, involving multiple passages and disabling transitions between passages: http://twinery.org/forum/discussion/2625/distributing-stat-values-for-a-player-character#latest
I don't know how you're going to get persistent radio buttons, but there might be a way to dynamically update page content without reloading the passage. I would probably just redesign the page to not use radio buttons.
I actually based that on your example, though I haven't figured out how to disable transition without disabling it everywhere. I am using span to refresh displayed variables but I wasn't able to use that method on <> part.
In your css write:
.passage.notransition
{
transition: none;
-webkit-transition: none;
-moz-transition: none;
}
And then add the tag notransition to the relevant post.
If that still produces flicker, you can in the previous passage write something like:
timedcontinue 1s
addclass ".passage" "notransition"
((with << >> around each of those lines, but this forum hates that formatting))
This will apply the notransition class to the passages before it needs to, so should turn off the transitions before the next passage is called. You may need the replace macro set from the sugarcube website for the timedcontinuie macros.
to undo that you simply use removeclass in place of addclass.
Use CSS. Something like the following:
Wrap the clock display in an element with an ID and update it via <<replace>>. You can wrap the entire update method in a widget to make it easier to use. What does your update process look like?
As for the other questions, you're going to need to detail what you're actually doing first.
I'm using if to replace click or else stat could go into negative or exceed its cap. I tried putting whole if into a span and have it replace itself but that only works for a single click.
Not really related but doesn't warrant another topic:
I looked at some js tutorials and it seems clock part is more complex than I expected. I meant to make widget or macro to add time on action but I'd have to calculate everything in lowest time unit which is a headache because calculating time would be important mechanism for the game.
I imagined having objects age, for example creating $apple and adding age, so at 0 it would be fresh and once reaching certain age it would become rotten. Another idea was to have say, training weights and while character has it equipped it would increase strength over time up to certain point.
Of course, my knowledge of js and css is almost non-existent. Guess I'll have to do more research.
That said, if you're married to the idea of disabling the buttons, then you could place all of the stat modification code in another passage and (re)display the whole thing via a <<display>> inside a <<replace>>. The effect is similar to what you're doing now, except without the unnecessary passage navigation. As a beneficial side-effect, it also reduces both the number of target elements to one and instances of <<replace>> macros. Example in the attached TWS (which has been ZIP archived, because TWS files aren't currently allowed).
Thanks, that is exactly what I was trying to make it do.
Today I went and created a passage It works mostly as I intended but when its saturday and I advance time by 8 days result is 0 and nothing gets displayed. Tried adding if 0 set to 1 but then result is monday.
Also, will using this method for time bite me in the ass when I try to make something to calculate object age and effects over time?
Is there a reason you are building your own date handling instead of using Javascript's built-in Date class?
You can even extend the Date class so that it can return day / month names.
Place the following into your Story Javascript: And then the following will work:
Tried that method and when I month comes out as february.
The month value range is from 0 for January to 11 for December.
A story generated using Twine is basically a HTML web-application that contains a javascript engine that creates the story pages/passages as they are needed, these pages are styled using CSS.
To get full usage from Twine it helps to know some CSS to make your story look the way you want, some HTML to structure the content, and maybe even some Javascript if you want to do non-basic things.
Assuming you were shooting for the date January 08 2017 12:42:00 (local time), then what you wanted was the following: Alternatively, you could instead supply a full, or partial, ISO 8601date string, if that would be easier. For example, the same date using a partial date string:
When I took a look at making time pass topic I got idea to make object like this: so it would work something like $apple.health - (($now - $before) * $apple.rateofdecay).
Except I'd want it to affect every object that has .health and .rateofdecay. Though I should probably somehow limit it to player inventory array or every apple in game would become rotten.
Anyway, my question is how to affect every object with a specific property?
Second, how can I target specific property of object, for example, displaying tooltip with $apple.description on mouseover?
And last, how can I make a top bar that would work like the sugarcube side bar does?
Couldn't you just set a normal variable to decrease at certain times and use that to determine the status of an $applehealth variable?
As for apple, wouldn't that work only if there was just one apple object? How would I track 2 apples that were added to array at different times? Besides, apple was just an example. Hm, maybe if I included a for and if $target.rateofdecay in a time widget...
It'd be simple enough to do something like:
<<set $heldapple1 to 5>> , <<set $heldapple2 to 5>> etc, and decrease 1 from $heldapple$1, 2, 3, 4, 5 etc every time the timer advances. When they get to 0, they get replaced by rotten apples.
If you're only expecting to have the player carry a limited amount of apples, it seems the simplest way, and while the code takes a few extra lines and variables, you could write it in a fraction of the time you needed to learn how to make another way work.
For your other question: http://stackoverflow.com/questions/7503183/what-is-the-easiest-way-to-create-an-html-mouse-over-tool-tip
http://sixrevisions.com/css/css-only-tooltips/
Try something like the following, to replace the contents of a nearby element: Or the following, to replace the the Misc link itself:
Using this for displaying inventory: Filled array with couple of objects and then used to change value.
First time I used it it worked as intended. Then I accidentally hit ctrl Z instead of T in the main window(damn you qwertz!) and had to write it again. Except now it just overwrites the first object in array with that value instead of objects quantity value.
If $yellowApple is the cached index (I'm going to assume it is), then you've simply got .quantity in the wrong place. It goes outside the square brackets, like so:
I set the $yellowApple object, push it into array and can see it with checkvars macro. But when I try to set quantity with click macro
Does it hold a reference to the object within the array itself? If so, then the above isn't going to work. You'd simply do something like: That works since it's a reference to the object within the array (i.e. $yellowApple and $invMisc[ /* "Yellow apple" index */ ] both refer to the same object). See the warning below.
If it's not a reference, then as I said before, you either need to have the index on hand or you'll have search for it.
Reference Caution
Because of the way most story formats work, references in story $variables will be broken each "turn" (i.e. each time you navigate passages). So, you should probably only use references in cases where you can recreate the reference each turn and doing so isn't onerous.
In most cases, and especially if you need to maintain a "reference" to an array member or object property across turns, what you should do is record the index and/or property name of the thing you wish to access rather than a reference to it.
For example, search and set using <<for>>: As you can see, that's pretty cumbersome. Alternatively, you could use <Array>.find() if you don't mind a little JavaScript: That could be made shorter by being wrapped up within a utility function.
If you're going to be doing that a lot, you may be better off using an object to hold your inventory, rather than an array. For example:
Then, later on, changing the quantity of yellow apples would simply be:
Printing out the inventory would require a few changes, but nothing too severe, for example:
Now, the question.
How can I store function inside object, like this: Tried defining whole object in JS and while I don't get any errors testing it, I don't see it with checkvars. And I can't figure out how to do the same in twine.
The <<checkvars>> debugging macro only shows story $variables, so you're not going to see JavaScript variables, if that's what you were trying.
Anyway, the code you have there is correct, and one way to attach a method to an object.
As to how to do it in Twine, which I assume means how to do it with story $variables, is exactly the same. For example: