I need said monster to move in the “map” (not a picture, in the game itself) while the player is wandering around looking for X.
How does one code this?
It cannot move randomly, it must move from one connected room to an adjacent room. If Rooms A and B are connected and B and C are connected, it can go from A to B but not A to C (without going to B first).
The creature should only be moving one room at a time, never two.
Code must track the creature’s exact location (for descriptive text to let you know it’s in the room)
Ideally, there should be a way for you to know if the creature is in the adjacent room so that you know to hide (if player is in room A, creature is in room B, code must know creature is in B while also knowing the player is in room A)
I haven’t decided quite yet. I’m not sure it’s possible (code-wise). I’m guessing by your response, it’s possible?
The rooms would likely be in a grid-like fashion though, yes. They just wouldn’t all connect to each other. I can’t imagine drawing a map any other way. For the number of rooms, let’s assume 25 total but this is including hallways and empty space so we’ll subtract 7 (because yes) for 18 total occupiable rooms.
If you do write a code for this, please explain to my dum dum brain HOW the code works.
What you want to do is a pathfinding algorithm on a graph. I wouldn’t say it’s an advanced topic for someone familiar with computer science, but if you are new to programming, you will have difficulty understanding the algorithm and data structure. The fact that choice script doesn’t have loops and pointers would make the implementation significantly harder.
You can check out the A* algorithm to see what it entails:
My suggestion would be to scale back on the computational difficulty of this puzzle if you are not a computer science student/ don’t have a background in programming.
I would say it’s impossible to wing it. You need a solid understanding of data structures and algorithms to pull this off. However, the puzzle doesn’t have to work in “real time”. You can make it look like the monster is chasing the player through the maze. It’s the experience that matters after all. The player doesn’t care if it’s all just smoke and mirrors.
Anyway, my suggestion is to think about it within the limitations of choicescript. What that means, it means you should lie - every time the player does something you move the monster. You can then change the flavour text based on how close it is.
*if (spooky > 1)
*set monstermove + 1
*set flavourtext spooky + 1
*set monstermove + 2
*set flavourtext spooky + 2
Loop it and you should be good. You can bother with the mini map but choicescript is not a visual medium - in any case, it’s possible to have a minimap, not sure about a moving element.
My proposal is to stop thinking about maps. Maps don’t exist in choicescript Objects don’t exist in choicescript. Just rattle the chains based on wherever PC “goes” and it’ll have the same effect.
Or switch to Unity/Ren’py/maybe RPGmaker.
I think if you’re working with such a large number of rooms, world modelling like this will be very tricky in ChoiceScript (if it was more like four rooms, it would be more easily done, though still fiddly) and the returns may not be worth the amount of work needed. As @quartz and @saggittarius have mentioned, it’s OK to have the monster sound closer or further away depending on where the player is or what they’re doing, etc, and then have it burst in or force the player to hide at a dramatic moment. There’s the possibility of using a variable to track monster alertness based on player location or how loud they’re being, and have it get closer based on that.
*create player 1
*create monster 9
#Move to next room.
*set player +1
#Stay in current room.
*if (player != 1)
#Go to previous room.
*set player -1
*set monster -1
*if (player = monster)
"AHH a monster!"
"Phew, no monster here."
This is a simple way of doing it for a 9 room layout and the player starting in room 1 and the monster in room 9.
It could be modified to allow for different options (ie maybe a room has 3 doors.
I assume the “it does not move randomly” simply means the must-move-to-adjacent-room thing, and not that it’s actively tracking mc? I don’t see why a complex algorithm would be needed dor that. You’ll just need to first design the floorplan, and then assign numbers to the rooms, and then you’ll be able to see which rooms are connected. (Besides, you’ll have to know that already for the MC, no?) Then you’ll just need to write if-clauses for all rooms.
That’s what I was thinking. I haven’t started experiments yet but I was considering something like…
Monsters starts in X room so we assign X room a value (we’ll say 5 just for easy numbers)
Player position can be easily tracked (Monster variable = player variable means no more dialogue hints or environmental hints, que meet the monster scene and get nommed) and we’ll say they start in Y (1 for easy numbers)
When X = Y, player and monster are in the same room
Monster boyo needs to move between adjacent rooms but not be able to pass through walls. THIS is the part that I’m a little stuck on. But I may have a work around but it’s a bit… icky.
Let’s say rooms 3, 4 and 5 are all connected since they are, in our imaginary map, different sizes. We could do 3 = 1, 4 = 2 and 5 = 3, use *rand dice 3 and *if 1 then our mob moves into room 3, 2 for room 4 and 3 for room 5.
It’s a bit messy, but also random without being too random. It’s also just a lot of work that there may be a better solution for.