Hi All,
I'm a fairly new user to twine but have managed to make a couple of small games.
One thing I've found, is that in one game I used a script to update a stats window (showing health etc) and
this works fine if I use the <<set $health to 1>> and then <<updatestats>> in a passage but if I use the setter links command version
[[health|Forrest][$health = 2]] no matter where I put <<updatestats>> it does not work.
Can anyone explain a simple way I can make it work as I am trying to convert my second game to work in the same format as the game with the stats window but this game mainly uses setter links and I don't want to have to rewrite the whole thing.
I have no knowledge or ability with scripts!
Thanks for any help
nowherecity24
Comments
Based on your description, your original code works because you're modifying
$health
and then calling<<updatestats>>
, probably very close together. The main point is that you've actually modified your stats before you call<<updatestats>>
.When using setter links, the setter component is only evaluated when you click the link, which means your stat modifications happen after you've clicked on the link and just before the new passage is displayed. So, your call to
<<updatestats>>
needs to happen either as part of the link (but still after the stats are modified) or after link navigation.The easiest thing to do might be to call
<<updatestats>>
as part of the passage display process. This script should work for that: (put that in ascript
tagged passage)Thanks for the quick reply but unfortunately I couldn't get that to work, you can correctly assume its because I don't know what I am doing.
It's probably how the passages are organised.
If I understand this correctly <<updateStats>> is a macro in my story, the script is in a passage called Story Region Module (tagged script)
This is the macro code in that passage
macros['updateStats'] =
{
handler: function()
{
var title = 'Stats';
if($("story"+title)) {
setPageElement("story"+title,title,"");
}
I copied your code (modifying the name to updateStats as per the macro) into a new passage I called it UpdatePassage and tagged it script
but nothing happens, my value $health doesn't get set if you click the setter link and the stats window is not updated.
I'm not really sure if I correctly did what you suggested so appreciate if you could assist further.
Thanks very much
nowherecity24
Where'd you get those scripts (
Story Region Module
, etc.)? It's possible that it's doing something like dynamically (re)generating the target (which is#storyStats
, based on the macro code), meaning that it could be overwriting the changes made by the postrender call to<<updateStats>>
. To know for sure, I'd need to look at the code.Did you modify both instances of
updatestats
? Changing both isn't required, though it wouldn't hurt anything, but the actual call has to be changed. For example:Basically I like the story format that this sylesheet uses. Previously I had the stats/inventory in the top line of every passage but as they grow it just pushes the text down. So now what I would like is a separate stats window off to the side. I managed to do this but now can't get the stats to update using setter links (even with your macro), although if you use <<set>> they work
To make it a bit more complicated in the stats window I also show inventory items and when your at certain locations you can click on the inventory item and it will use it to solve the puzzle.
I hope you don't mind but I've attached a cut down example of what I am trying to do to try and show you.
Thanks
nowherecity24
postrender
code I gave you before (theUpdatepassage
script passage). It won't work with what you're doing.Second: Replace your
Story Region Module
with this updated version: I refactored the code (it was in pretty bad shape) and added a call toupdateStats
after the realdisplay()
method has been called. That will solve your problem with setter links. Furthermore, you probably won't need to call<<updateStats>>
manually in your code anymore, the way it's setup now should cover most cases for you automatically.Suggestions:
1. Use
StoryInit
special passage to initialize $variables, not a<<silently>>
block at the top of theStart
passage. For example:2. In a conditional expression, don't test $variables containing boolean values against the boolean literals (
true
andfalse
), simply evaluate the $variable. For example:3. Double assignments are bad.
That's great. I want to thank you for your extensive help, you really went out of your way to assist a NOOB!
I'll take on board your suggestions for improving my code.
One thing I've found with the twine help is that the commands are poorly documented with a lack of clear examples.
Sometimes even if you cut and paste the given example it won't work because the format is wrong.
One of the most basic things you want to do when writing a game is manage variables and there is almost no documentation in the twine help to show you how to do it.
Then there are things that contradict each other for example don't use = but use eq to set a variable but in the setter command you do use =
Most frustrating.
Anyway moan over thanks again for your help
Cheers
nowherecity24
I hope you are still around.
You previously solved my problem with updating a stats window in sugercane and it all works fine, my question is I would like to duplicate another stats window on the right hand side of the page, I've tried creating another stats box on the right in my stylesheet but I can't get anything to appear in the new box. My question is can I still call the same update stats macro using same tags but different passage name or is that just going to confuse everything?
Thanks
nowherecity24
Story Region Module
I gave you, no. The post-display update portion was never setup to handle multiple regions.It wouldn't be difficult to modify it to do so, however, so I can knock that out for you real quick.
Here you go. Replace your
Story Region Module
with this updated version: Note: Similar to last time, you should never need to manually call<<updateStats>>
with this code (thedisplay()
function automatically calls it). However, it's still there in case you do. I also didn't change its name, even though it updates all regions now (just in case you are calling it manually).