So I got a bit stuck because of my limited knowledge of both SugarCube and JavaScript. I manage to create a dungeon with 20 seperate passages (rooms) and added a custom macro that puts you randomly in one of those passages each time you move through the door. I've also created a basic turn based combat system using few different passages for player turn/enemy turn, using magic, items and death. The way it works is that there's a set chance for enemy to appear each time player enters a new random room and then he's moved to combat passages.
Now, the problem I have. When the battle ends (with player still alive) the player should be moved back to the exact same room he got attacked. For example, he enters the dungeon and custom macro puts him in the room 9. Then he moves through the door and, again, custom macro puts him in, let's say, room 14 where he gets attacked. He's moved to the combat passages. He defeats his enemy and after the firght he should be moved back to the exact same room, which in this case is room 14. Problem is that the fight can start in each one of those 20 rooms and I want the player to always get back to the same room he got attacked in.
Is there any way, through maybe somehow saving the passage where the fight starts, to set it in a way that will always move the player to the same room he got attacked in?
I'd appreciate any kind of help.
Comments
You haven't exactly given a lot of details about how all of these things tie together, so I'm going to guess that the simplest is to have the macro do it, assuming the macro is actually playing the next room passage and that you do not call it within the combat passage(s).
Try something like the following in your macro, before you play the next passage: Then you'd simply reference $lastPassage in your combat passage(s) to return the player to the last passage they were in. For example:
Might as well use this thread to ask one more question.
I'll try to be more specific this time.
My test macro for attack during exploration looks like this:
Now, what I want to do is when player gets back from combat passage to the room where he was attacked (thanks to your line of code), mAttack macro wont activate. So basically I don't want player to be attacked again right after exiting the combat menu, though the macro should activate if the player will leave this rooms and revisit it later on.
There are several ways to do it, however, the easist would likely be to have the "door" passage unset $lastPassage and to check its value within the macro—i.e. if it has no value, then the player should be coming from the "door" passage, elsewise the player should be coming back from combat.
For example, do something like the following near the top of your "door" passage: And your updated mAttack macro: Though, if we assume that 100 will always be "nothing happens", then I might write that instead as:
PS: Of course, one might wonder why you're even using a macro when standard markup would suffice—again assuming that 100 is "nothing happens".
2. I guessed as much. Sorry for that, but I just started learning both Twine/SugarCube and JavaScript so most of it is bound to look terrible. At least for now.
3. I'm lost here. How should I do that?
As for the <<unset $lastPassage>> I guess I messed something up but I get an error while I try to get back to the room after the fight. It's telling me that the passage "$lastPassage" does not exists. Where should I exactly place the <<unset $lastPassage>>? In each one of the random rooms?
I decided to use macro to train a bit with JavaScript and also so I wouldn't have to place that markup in every random room passage. Maybe not the most practical way but it's fun to make a working custom macro. :P
Also, excuse me the long time it took me to write an answer. I literally had no time during the last week to even open up Twine
Thanks again for your help.
As for now, there's the starting passage that connects to the "Dungeon entrance" passage. Then there is a set of 20 passages and all of them are basically the same rooms just numbered 1-20. There's a macro placed in the exit link of "Dungeon entrance" passage that puts you randomly in one of those 20 rooms. Also, each room has a 50% chance to spawn North/South/East/West passage links (or any mix of them) each time player enters said room. All of them works the same as exit passage link from "Dungeon entrance", so they just launch the randomizer macro and put you in another random room. Room no. 1 is also the only room with the exit doors that lets you leave the dungeon.
I hope that explains the structure of it, more or less.
And now, to touch upon something that I didn't comment on previously: Widget macros. I'm not saying that you shouldn't write custom JavaScript macros, however, widgets are the solution to the quoted issue.
First, what's inside each of the random rooms:
Now for passage link macro, which is really the same for each direction:\
And finally, the code for my "randomizer". It probably looks terrible but that's the first solution I found on my own when I was trying to build randomly generated dungeon:
In The Meantime, Code Suggestions
The <<north>> macro:
The <<dungeon>> macro: