Hi,
I was wondering if someone can give me some pointers on how to do pathfinding for NPCs in Twine. Since passages do not necessarily correspond to locales, I don't see an easy way of doing this.
I imagine that there are some info on this already, so pointers would be great.
Thanks.
PS) I am new here, so I should remember to mention that I am using the standard format (Harlowe?).
Comments
—Sage.
(
He uses a grid to figure out where the player is and where he can go (which solves the issue for NPCs moving around too). However, he is using a different format than Harlowe (SugarCube). I am trying to do a 2d array in Harlowe, but with no luck. What's wrong here:
(set:$mapArray to
[[0,0,0,0],
[0,1,1,0],
[0,0,1,0],
[0,1,1,0],
[0,0,0,0],
[0,0,0,0]]
)
I get an "unexpected token"-error.
or maybe I should simply switch to the other story format now? Can anyone supply a link that details the differences between formats?
Harlowe Resource: http://twine2.neocities.org/
SugarCube: http://www.motoslave.net/sugarcube/docs/macros.html
If you are using Twine 2.0 then setting an array in Harlowe looks something like this:
Two-dimensional arrays need a bit more coding but I hope that clarifies the syntax for Harlowe.
----
Here's a link that might help with regard to Pathfinding in 1.4.2 with SugarCube, would need a bit of modification to work with 2.0 but at least the example code is there for you to poke around:
Pathfinding Widget for Maze-Games [Sugarcube]
As a total newbie, it's a little confusing with the different formats. I will read the provided guides, but maybe someone could tell me what the main reasons are for using one over the other?
Basically, I am trying to learn the syntax of T2 and thought it would be interesting to do an oldschool text adventure first just to get to know the system.
But as to whether there's a good reason to use Twine 2, honestly if you are using SugarCube then you might like Twine 1.4.2 better.
The main strength of Twine 2 imo is Harlowe. While you can run SugarCube in Twine 2, the experience is not as smooth as working with SugarCube in 1.4.2, as I think 1.4.2 has a better interface than Twine 2 (some sacrifices were made to make Twine 2 browser based).
This is what I am looking for. Could you do an example with a 2d array?
The link for Twine 2 Guide should help as well as L's resource guide for Harlowe 2.0. I keep both of those up in tabs in my browser at all times when I am working with 2.0 and Harlowe. You'll get the hang of it pretty quickly, just takes some practice and there are lots of people here willing to help.
As for selecting a format, info is here that might help: How to Choose a Story Format
P.S. I love old school text adventures.
Thanks! I'll be sticking to T2 and Harlowe then.
Just an FYI, (a:) is shorthand for (array:).
Also: Additional examples by @greyelf here:
Can you use multidimensional arrays in Harlowe?
Well to clarify, there's nothing actually wrong with SugarCube in Twine 2, it's just some Twine 2 things that some people don't like, like tying the story saves to your browser cache, and the lack of full screen passage editing.
IMO, these are big enough reasons to use 1.4.2 over 2 if you can, so for SugarCube which supports both, I prefer 1.4.2.
Other people really like Harlowe so use Twine 2 despite these issues.
All this isn't to hate on Twine 2, it's just to point out that the choice is not "2 is automatically better because it's a bigger number than 1". Some people like Harlowe because it does what they want, others prefer 1.4.2. Both versions of Twine have good things going for them.
Thank you, I'll try that out.
Oh, one more thing: Do you know the syntax for getting data out of the array too?
length of mapArray:
all entries in mapArray:
first entry in mapArray:
first element of first entry in mapArray:
print mapArray as a grid:
If you want to set values into a variable you would simply use (set:) instead of print.
NOTE: Not sure why commas are being printed. Seems like they shouldn't.
Harlowe's overview / commit log did mention something about being able to use variables directly in a future version of Harlowe, so you may want to check the beta version of Harlowe to see if it was implemented. From memory it was something like the following:
My question is more about displaying the map. For some reason, if I use the (print:) function to show the whole map, it shows commas and all.
In the video from Dan Cox (using Sugarcube) use the <for> to set up the map (replacing 0 with #, and 1 with -, etc), which I think in Twine2 and Harlowe would be the (replace:) function. But I don't know if that would do anything about the commas showing up.
Not sure if that explains what I'd like to know. Am I right about the for and replace? Is there any more information from that video that has a parallel in Harlowe, but isn't the same? How do i get rid of those commas in the map print?
And, ya know, any other knowledge that you'd like to pass unto me.
There is no direct equivalent in Harlowe but you can simulate it using a $variable and the (live:) macro:
WARNING: If not careful doing the following could cause the Reader's web-browser to slow down or become unresponsive.
Harlowe's (replace:) macro is using to replace the contents of a named hook with something else.
another question concerning this topic. I have a one-dimensional array and I want a variable to move randomly up and down the array.
I'm looking for the command that let's me add or substract a position in the array. Moving from the 5th to the 4th position for example.
I'm using Twine 2.0 and Harlow.
Thanks
Passage Name: INI
X is you. Y is the enemy. Every time you make a move up or down the array, Y makes a random move up or down the array.
Passage Name: UP
When I execute it, it doesn't change the position though and I get no errors. What am I missing?
a. assign the same value to $X and $Y, that value being whatever is stored in the $pos element of the $mapArray array.
b. assign $X the value stored in the $pos element of the $mapArray array and assign $Y the value stored in the $pos -1 element which if equal to -1 will be the value stored in the last element of the array.
eg. If $pos is 1 then $X will equal $mapArray's 1st and $Y will equal either the same as $X or it will equal $mapArray's (0) => $mapArray's 8th