Quantcast
Channel: Help! with 2.0 - Twine Forum
Viewing all 1844 articles
Browse latest View live

Adding to a 'time' variable to indicate time passing? (Harlowe)

$
0
0
Hi, everyone. I've been working on a game recently where you are given a list of tasks you can do, and each task results in a certain amount of time being spent. When a certain amount of time passes, instead of being directed back to the list of tasks you go to another passage that takes place afterwards.
I'm doing this with a 'time' variable that is set in a previous passage like this:

(set: $time to 0)

then in each task passage, this is used to indicate time passes:

(set: $time to $time + 1)

but it comes up with an error stating I can't use the set variable to do this? Anyone know what I should use instead.
By the way, the part I'm using to move from the tasks bit to the passage after is this:

(if: $time > 3)[\
[[That's enough for today.->waiting]]
\]
(else:)[\
[[Back to work.->january]]
\]

But I think that works alright?

Background Music in Harlowe

$
0
0
Hi all, I've made a few Twine fictions using Twine 2 (whatever the most recent is, it's all updated on my computer) and Harlowe 1.2.1. I am fairly dedicated to using Harlowe, since I do well with the macros and don't have time right now to teach myself a whole new story format.

I am looking to include just one sound in my story if possible. I just want an ambient soundtrack of "space noises" in the background of the passages. It is about 14 minutes long, so if the reader continues to play I would like the soundtrack to loop if possible. It doesn't need to change based on passage, just keep playing in the background. Is there a way to do this in Harlowe? I know that everyone here argues that SugarCube is better for sound, but I'm hoping that since this is fairly straightforward, someone can help me manage it in Harlowe.

Thanks!

Upgrading Harlowe 2.x

$
0
0
I don't see a story format download area anywhere for Harlowe. Will I have to wait for the next version of Twine to upgrade Harlowe? I am using whichever version that comes with Twine 2.1.0

[Sugarcube 2.16.0] How to display links based on player action without a page reload?

$
0
0
I am wondering how to go about having n links showing one of them at a time based on user interaction without a page refresh/load.

As an example:
<<set _doorLocked to false >> 
<span id="action-text"></span>

<<if _doorLocked>>
	<li><<link "Unlock the Door">>
			<<replace "#action-text">>You unlock the door.<</replace>>
			<<set _doorLocked to false>>
		<</link>>
	</li>
<<else>>
	<li><<link "Lock the Door">>
			<<replace "#action-text">>You lock the door shut.<</replace>>
			<<set _doorLocked to true>>
		<</link>>
	</li>
<</if>>

Now this obviously won't work as is due to conditionals being processed on page rendering. I'd like to be able to either show the unlock or the lock links and execute the necessary code based on these actions without having to do a page reload if at all possible.

I am using Twine 2.1.1 and Sugarcube 2.16.0.

how do you hide an option after a different one has been chosen? (harlowe)

$
0
0
hello! im making a world-of-warcraft style game, except obviously in twine form, and i am having a problem with the character creation. heres an example:
at the top of the page, it says "pick your race", and under that the options human, elf, and dwarf. after an option has been selected, i want the others to go away and the next question, "choose your gender". right now,if i select elf, it ends up being this:
pick your race:
human (this is a link)
Race set as elf!
choose your gender:
male (this is a link)
female (this is a link)
orc (this is a link)

basically what im looking for is the opposite of the new "show" macro. does such a thing exist?

Harlowe not creating/maintaining links between pages properly

$
0
0
In the twine project I'm working on right now, I want to do something like footnotes, by having superscript numbers be links to pages that show citations. So it would look something like this:

Blah blah blah[[^^1^^|Citation 1]].

or

Blah blah blah^^[[1|Citation 1]]^^.

And the Citation 1 page will be the one with more information. But for some reason, I'm having trouble getting the link to the page Citation 1 to work. I've been trying for a while now. Sometimes it will create the page, but then if I add more links to the same page later on the links will break and no longer direct anywhere. Sometimes it just won't create the page at all, and if I create it manually the link stays broken. Am I somehow doing something wrong with my link syntax? Doing things this way has always worked for me before, but I might not have ever involved numbers or superscript, so maybe that's the problem?

[SugarCube 2.14.0] Sanity check: Am I serialising my objects correctly?

$
0
0
As I continue down the path of trying to create a real-time, event-driven story in SugarCube, I find myself encountering some interesting challenges. The latest of which is getting object prototypes and anonymous functions to play nicely with story variables.

I think I've fixed the problem by following advice given by @TheMadExile in the thread Keeping complex JS objects in variables?, but I'm not sure I've fixed it "correctly".

If any of you have experience with JSON serialisation, could you please take a look over the following and let me know if there's a better way?

Events:
Creates a future-dated event, to be fired when $game_clock >= Event.time
/*
setup.Event(time, [title[, passage[, openFn[, closeFn[, bHidden[, bPopUp[, log]]]]]]])
time:    When the event will occur, the only mandatory field.
title:   Name of event to be displayed on UI.
passage: Passage to be displayed if user clicks on the event's title in UI (title will only be a link if passage is not undefined).
openFn:  Function to be fired immediately after the event is fired.
closeFn: Function to be fired after the user closes the pop-up dialog, only works if bPopUp is true and log is not undefined.
bHidden: Whether or not the event should be displayed on the UI.
bPopUp:  Whether or the event's log should pop-up on screen as a SugarCube dialog, only works if log is not undefined.
log:     Historical log entry to be created after the event is fired.
*/

setup.Event = function(time, title, passage, openFn, closeFn, bHidden, bPopUp, log) {
  if (!(time instanceof Date)) {
    time = new Date(time);
  }
  if (openFn instanceof Array) {
    openFn = eval(openFn[1]);
  }
  if (closeFn instanceof Array) {
    closeFn = eval(closeFn[1]);
  }
  if (log instanceof Array) {
    log = eval(log[1][0]);
  }
  
  this.time = time;
  this.title = title;
  this.passage = passage;
  this.openFn = openFn;
  this.closeFn =  closeFn;
  this.bHidden =  bHidden;
  this.bPopUp = bPopUp;
  this.log = log;
};

setup.Event.prototype = {
  toJSON: function () {
    var logStr, returnFn;
    
    if (this.log) {
      /* log is an instance of setup.EventLog, see below */
      logStr = this.log.toJSON();
    }
    
    returnFn = 'new setup.Event(';
    returnFn += JSON.stringify(this.time.getTime()) +',';
    returnFn += JSON.stringify(this.title) +',';
    returnFn += JSON.stringify(this.passage) +',';
    returnFn += JSON.stringify(this.openFn) +',';
    returnFn += JSON.stringify(this.closeFn) +',';
    returnFn += JSON.stringify(this.bHidden) +',';
    returnFn += JSON.stringify(this.bPopUp) +',';
    returnFn += JSON.stringify(logStr) +')';

    return JSON.reviveWrapper(returnFn);
  }
};


Event Logs:
Creates a log, a historical record of past events for the user to see.
/*
setup.EventLog(time, logSev, logType, logMessage[, learnid[, learnmsg[, read]]])
time:       When the event occured.
logSev:     Log's severity, for filtering purposes.
logType:    Log's type, for filtering purposes.
logMessage: Main body text of the log message.
learnid:    What $player_knowledge is unlocked the first time the user reads this log.
learnmsg:   Additional text to display the first time this $player_knowledge is found.
read:       A boolean to track if the user has read this log.
*/

setup.EventLog = function(time, logSev, logType, logMessage, learnid, learnmsg, read) {
  if (!(time instanceof Date)) {
    time = new Date(time);
  }
  
  this.time = time;
  this.severity = logSev;
  this.type = logType;
  this.message = logMessage;
  this.learnid =  learnid;
  this.learnmsg =  learnmsg;
  this.read = (read || false);
};

setup.EventLog.prototype = {  
  /* Prints the number of days since epoch */
  getDays: function () { /* snip */ },

  /* Prints the current time (24H). */
  getTime: function () { /* snip */ },

  /* creates a summary of this log for use in a <jQuery>.wiki() call */
  format: function() { /* snip */ },

  /* display a SugarCube dialog containing this log's information */
  showDialog: function(closeFn) { /* snip */ },
  
  toJSON: function () {
    var returnFn = 'new setup.EventLog(';
    returnFn += JSON.stringify(this.time.getTime()) +',';
    returnFn += JSON.stringify(this.severity) +',';
    returnFn += JSON.stringify(this.type) +',';
    returnFn += JSON.stringify(this.message) +',';
    returnFn += JSON.stringify(this.learnid) +',';
    returnFn += JSON.stringify(this.learnmsg) +',';
    returnFn += JSON.stringify(this.read) +')';

    return JSON.reviveWrapper(returnFn);
  }
};


Example Usage:
This creates a hidden Event that will be not be displayed in the 'Upcoming Events' section of the UI. When the event fires, it will immediately stop any time acceleration, and add this event's EventLog to the list of historical logs.

It will also display a SugarCube dialog displaying the same log information. When the user closes this dialog, they will be taken to the passage 'Event Intro Alarm'.
setup.cannedEvents = {
  /* snip */

  introCollisionWarning: function() {
    var time = new Date('1901-04-07T07:20:00Z');

    var event = new setup.Event(
      time, //time
      'introCollisionWarning', //title
      null, //passage
      setup.timeSystem.clearTimeGoal, //openFn
      function() { Engine.play("Event Intro Alarm"); }, //closeFn
      true, //bHidden
      true //bPopUp
    );

    var log = new setup.EventLog(
      time, //time
      'High', //logSev
      'Collision Warning', //logType
      "Sensor event SE-4562 has now been upgraded to a high severity, anomaly appears to be mass-bearing. Due to possibility of kinetic impact, ship status has been upgraded to high alert status.<br/><br/>''Warning:'' Current trajectory suggests ESSD Cetacea will now encounter anomaly in ''T-1 hour.'' Brace for severe warp turbulence." //logMessage
    );

    setup.eventSystem.addEvent(event, log);
  },

  /* snip */
}

ternary operator doesnt work with state.variables sugarcube

$
0
0
i have two somekind of health bar in header and some code in passage to calculate the health bar and animate it, but some error popup and said bad evaluation:energyTotal is not defined
::PassageHeader
<div class="section-stats btcf">
	<div class="stats-wrapper energy-bar" data-status="energy-bar">
		<span>Energy</span>
		<div class="stats-bar">
	  		<div class="bar">
		  		<div class="hit"></div>
	  		</div>
		</div>
	</div>
	<div class="stats-wrapper hunger-bar" data-status="hunger-bar">
		<span>Hunger</span>
		<div class="stats-bar">
	  		<div class="bar">
		  		<div class="hit"></div>
	  		</div>
		</div>
	</div>
</div>
::Passage
<<script>>
$('.section-stats .stats-wrapper').each(function(index, el) {
	var dataStats = $(this).data('status');

	var eBar = $('.'+ dataStats +' .stats-bar'),
		bar = eBar.find('.bar');

	var varTotal = (dataStats = "energy-bar")?energyTotal:hungerTotal;
	var varName = (dataStats = "energy-bar")?energy:hunger;
	var varLoss = (dataStats = "energy-bar")?energyLoss:hungerLoss;

	var total = State.variables.varTotal,
		value = State.variables.varName,
		damage = State.variables.varLoss,
		barWidth = (value / total) * 100,
		delayReset = false;

	if (damage != 0) {
		value -= damage;
		barWidth = (value / total) * 100;
		State.variables.varName = value;
		State.variables.varLoss = 0;
		delayReset = true;
	}

	eBar.data('total', total);
	eBar.data('value', value);
	if (State.variables.varName <= State.variables.varTotal){
		if(State.variables.varName>0){
			bar.css('width', barWidth + "%");
		}else{
			bar.css('width', '0');
			State.variables.varName = 0
		}
	}else{
		bar.css('width', "100%");
		State.variables.varName = 100
	}
});
<</script>>

is using ternary operator is wrong ? or the whole concept is bad ? im using ternary operator because i want multiple health bar like.

any help will be appreciated, thx before.

Multiple Twine 2.1.1 instances

$
0
0
Is there any way to achieve this anymore in 2.1.1, or some other way to have multiple stories open at once? I used to run two instances so I could look at both my story and a map of my story without switching back and forth within the program, I'd like to still be able to do this. Thanks :)

How do I get rid of a broken link?

$
0
0
I'm using Twine 2 Harlowe. For some reason, I have a problem where the links on some of my pages aren't clickable. They are red when I simulate the game and instead of letting me click on them they display a "banned" symbol (like the no smoking sign without the cigarette) when hovered over. Because of this there's no way I can continue the game. I've attached a screenshot of my Start page for convenience. Is there something wrong I'm doing? Thanks!

[Sugarcube 2.16.0] Ignoring Variable on Return

$
0
0
I have a variable that produces a game over when it reaches 100, but the player has (limited) healing potions that are selectable from the sidebar. This seems to be working fine, and I have noreturn tags on the potion select screen to avoid getting stuck.

However, if I have an incremental variable increase on a passage (a storyline one with no noreturn), when I return it will just add the damage back on.
The demon swings at you. You are damaged!
[[Keep running!|forest2]]
<<set $health -= 40>>

If I heal at this point, then return to this passage, it will damage me all over again. I can't push it to the next passage because you can heal at any point. Is there any way to avoid this?

getElementByID("ID").style.backroundImage = url(img) doesnt show in browser

$
0
0
So, I wrote a short script, by which depending on the race the player chooses the backgroundimage is surposed to change:
<<script>>
document.getElementById("map_1").style.backgroundImage= "url(http://something.com/pics/race_" + state.active.variables["race"] + ".png)";
console.log("Javascript sucess. map_1.style.backgroundImage = " + document.getElementById("map_1").style.backgroundImage);
<</script>>

which should change the background image from a div (map_1).
And it even outputs the correct filepath, and it works with normal html/css/js, but the browser doesn´t show any change in the div.
I dont want to change the class, because i would need about 20 different classes then.
Any suggestions?
(Using Sugarcube btw.)

[Sugarcube 2.16.0] Replace text during page render

$
0
0
I've been using the standard link replace which I love once I got the hang of it. But I was wondering how I could go about modifying the contents of an element during render.

What I mean is say I'm hoping to accomplish something like the following:
<p>This is just a simplified example of the coding scenario.</p>

<p id="action-text"></p>

Select an option:
<hr style="padding:0px; margin:0px" />
<br />
<ul style="padding-top:0px; margin-top:0px">

	<<if random(1) eq 0>>
		<<replace "#action-text">>
			Hello World!
		<</replace>>
	<<else>>
		<<replace "#action-text">>
			Goodbye World!
		<</replace>>
	<</if>>

	<li>
		<<link "Brush your teeth (0:05)">>
			<<replace "#action-text">>
				scrub scrub scrub
			<</replace>>
			
			<<addmins 5>>
		<</link>>
	</li>
</ul>

However I understand that won't work because the macros will be processed before the html is rendered. I saw in the manual the task objects and a postrender which I'm assuming is something I would need to use in a situation like this. But I'm not sure where to start.

Any suggestions, dumbed down examples, or general hand holding would be appreciated.


Edit:

I just came across twinery.org/forum/discussion/comment/15366/#Comment_15366. I'm not sure how crazy the situation still is, but what I'm hoping to accomplish is to group together like content, in this case content that takes place in a single room for ease of organization and updating. It doesn't feel like it would make sense to use a link replace and I was trying to keep the html generic with replaces to keep the code from bloating or being overly complicated.

In my current layout I have a set place where text is displayed to the player and I'd like to keep re-using it if possible so long as the player is in that passage.

Visited links: controlling colour

$
0
0
Apologies if this has already been answered, but I haven't managed to find it. I'm working with Harlowe in Twine 2.1.1, and I have added some simple code to the stylesheet to keep all links the same colour, whether or not the reader has visited them.

This has mostly worked fine, but where there is a link to a passage that the reader has previously visited, even if they haven't used this link to get there, the link appears in a different colour (purple not blue). How can I change this, if it isn't tw-link and isn't tw-link.visited?

[Sugarcube 2.16.0] Pluck a tagged passage from an array

$
0
0
I have several passages with several tags like this:
:: Event1 [event suburbs]

My sidebar uses tags().includes("event") check to show some special info, and that works fine.
However when I try to get all the passages with "suburbs" tag, I don't get any. The code I'm using:
<<set $suburbs to Story.lookup("tags", "suburbs")>>

To get that particular passage into the array I need to change it to:
<<set $suburbs to Story.lookup("tags", "event,suburbs")>>

But the set of tags might be different per passage, so I need a way to get all the passages, one of which tags is "suburbs". Is there a way to do this?

After I get the list of these passages I need to create a link, which would pluck one passage and <<goto>> it. But I get an error with different variations of this code:
<<link "To the Suburbs">>
    <<set _e to $suburbs.pluck()>>
    <<goto _e>>
<</link>>

Could you help me, please?

P.S. using sugarcube 2.16 with entwine, if that matters.

[SugarCube 2.14] Dynamic variables in textbox?

$
0
0
Hello, I am currently writing a widget for a trading system and have run into a bit of an issue passing variables to a textbox within the widget.

My integer variables in the passage are _NumGeneral, _NumSurgery and _NumPharma and the widget is called with "General", "Surgery" or "Pharma" as $args[0].

Is it possible to write a generalized case within the widget for something like <<textbox "'_Num'+$args[0]" _Num+$args[0]>>, or will I need 3 separate widgets instead?

[Sugarcube 2.14] Creating brief, dramatic pauses in presentation of text?

$
0
0
I have a game in which during a battle the player can fire torpedoes at a target. The code then runs a <<for>> loop for each torpedo to determine if it hit and if so then what the damage, if any, was. The code currently just prints out all of the results for all torpedoes at once. I would like for it to create a little tension by pausing for a second or so between results such as:

"Fire one!" [pause] "Hit!" [pause] "Deflected by armor" [pause]
"FIre two! [pause] Miss! [pause]
etc.

I've experimented with <<delay>> and <<timer>> and haven't gotten even close. The best I got was for the loop to present all the "Fire!" texts at once, pause, and then all the hits and results at once.

Is there a way to get Sugarcube to stop/pause printing to the screen intermittently?

Thanks!


Twine 2, Harlowe

$
0
0
{
(set: $alpha to false)
(if: $alpha)[The quick brown fox jumped over the lazy dog.]\
(if: $alpha is false)[The lazy dog failed to jump over the quick fox.\

[Give the dog a rest]<rest_dog|
(click-replace: ?rest_dog)[You gave the dog a rest.(set: $alpha to true)]]\
}

Harlowe 2.0.0, Twine 2, Help with whitespacing and embeded Hooks.

$
0
0
Hello there,

Recently new to both programming and Twine. I've been working on a small project now for a month or so. Slowly getting through the macros, trying to deploy them in various ways. I've now gotten to the stage in a project of trying to adjust the spacing, making it look good. I seemed to have reached the tricky area of whitespace and linebreaks.

I am using Harlowe 2.0.0 and Twine 2.

Having followed this discussion:

https://twinery.org/forum/discussion/6316/lists-whitespace-and-seperate-lines-harlowe

I managed to deploy Greyelf's solution, using the backslash, inside the associated hook. This worked great for me, when creating a long quest list, with various (if: )'s. The problem I currently have is, how to escape and suppress a line break, while inside a hook, and execute another hook (this time linked).

This is an example of the current trouble I am having. This example fails in that the [Give the dog a rest] hook looses all spacing with the text above it.
{
(set: $alpha to false)
(if: $alpha)[The quick brown fox jumped over the lazy dog.]\
(if: $alpha is false)[The lazy dog failed to jump over the quick fox.\

[Give the dog a rest]<rest_dog|
(click-replace: ?rest_dog)[You gave the dog a rest.(set: $alpha to true)]]\
}

The link usually rams up against the other text around it. I've been putting backslashes everywere to see if I can make a difference but I am having no luck. Any help would be appreciated.

Help debugging this HTML please

$
0
0
Hey!

I'm still pretty new to Twine and teaching myself basic HTML and CSS. Wondering why this piece of code isn't working? Have tried debugging myself to no avail.

<div class="fade-in four"><i><span class="zuberitext">"Character A speech"</span></i></div>
<div class="fade-in five"><b>"Character B speech"</b></div>
<div class="fade-in six"><i><span class="zuberitext">Character A speech
<div class="fade-in seven">More of the same speech from Character A
<div class="fade-in eight">End of the same speech from Character A" </span></i></div>

<div class="fade-in nine">Do you [[choice|passage]]? Or do you think [[choice|passage]]?</div>

I removed the particulars of the story just to give an idea of the passage shape. The classes I have are a timed fade in for text and particular colour for Character A's speech.

Any ideas greatly appreciated, cheers!
Viewing all 1844 articles
Browse latest View live