I’m coding a section of a game where the exact scene is determined randomly. When you go to the scene that directs you to those others, it randomly picks the next scene, checks if you’ve been there, and if you haven’t, sends you there. Random variables don’t come up again until you re-visit the scene where it picks the next one, and so on.
Various testers have reported a bug where they click to the stat screen, go back, and are in a different scene. There is literally nothing in my choicescript_stats except *if statements and text; no variables are set or called at all.
Try putting a *page_break or something after the subroutine (or whatever) that randomly selects your scene and the actual scene? That way, when you go to stats and back, the parser starts reading from the first line of the scene page, and doesn’t run the randomization again. What does your actual code look like?
That’s a known ‘bug’ with choicescript. I use it while playing to cheat at random dice rolls. (Both in Waywalkers and in Choice of Intrigues specifically.) Randomness generally goes in the face of the whole ‘choice’ part of choice of games.
Chwoka’s explained how to get around it. But I’d ask, do you really need to have a random scene-select? It makes it a lot more difficult for people to replay and achieve different results, or to fully explore the game.
Sorry, I’m not quite understanding where I need to put the page break.
I have a scene that sends you to one of several different scenes. The random variable is part of that first scene. If people clicked to the stat screen and back during the first scene, they wouldn’t have seen which scene was supposed to follow it, so it wouldn’t matter whether it got set to something else.
The different scenes, which are what get changed around from going to stats and back, do not have any random variable creation. At that point the variable pointing to the room is still set, but it isn’t used for anything. Why should changing that variable affect anything, when you haven’t been back to the scene where it sends you different places depending on that?
This is the relevant code from my disambiguation scene:
You…
*choice
#Choose a room.
*goto reroll
#(Some other choices leading to non-random scenes)
*label reroll
*rand room 1 10
*if ((room=1) and not (room_1_explored))
*goto_scene room_1
*if ((room=1) and (room_1_explored))
*goto reroll
There are then nine more pairs of these for rooms 2-10. The “explored true” variable gets set in each individual scene. The rooms just send you back to the beginning of that first scene with a goto_scene (scene_name) at the end of each.
@FairyGodFeather Thanks for the information, but I really want to do it this way. The choices come into play in different ways.
*choice
#Choose a room.
*goto reroll
#(Some other choices leading to non-random scenes)
*label reroll
*rand room 1 10
*page_break
*if ((room=1) and not (room_1_explored))
*goto_scene room_1
*if ((room=1) and (room_1_explored))
*goto reroll
Or this if you don’t want to add text.
*rand room 1 10
*choice
#Choose a room.
*goto reroll
#(Some other choices leading to non-random scenes)
*label reroll
*if ((room=1) and not (room_1_explored))
*goto_scene room_1
*if ((room=1) and (room_1_explored))
*goto reroll
It’s just a weird bug you can’t do anything about, except work around it.
But then if room = 1 and room_1_explored = true, you end up in an endless loop because *label reroll doesn’t actually reroll. And in the first one you’ll possibly end up with multiple “Next” buttons that just lead to seemingly blank pages if you keep rolling for rooms you’ve already explored. Which is why you gotta do it like this:
*label reroll
*rand room 1 10
*if ((room=1) and not (room_1_explored))
*page_break
*goto_scene room_1
*if ((room=1) and (room_1_explored))
*goto reroll
(Of course, a page break immediately after a choice is awkward, so either you write some prose for before the page break so it’s not, or you find a way to roll it before the choice…)
*label reroll
*rand room 1 10
*temp roomname
*if ((room=1) and not (room_1_explored))
*set roomname "room_1"
*if ((room=1) and (room_1_explored))
*goto reroll
*choice
#Choose a room.
*goto_scene {roomname}
#(Some other choices leading to non-random scenes)
That’s a fancy, but very useful trick that requires the very latest Choicescript update. And if you want it to only roll it once even IF you go to stats and back on the page where it actually rolls, although the player won’t notice because it’s Shroedinger’s room, you can make “roomname” a *create stat in the startup and keep it blank and put the whole randomizer underneath:
*if roomname = ""
(I haven’t tried it but I don’t think it’d work that way with a *temp? You can’t test a variable until it exists so you can’t use a != “” or = “” to gate the whole shebang, and I’m pretty sure *temp overwrites the old stuff that was in it to boot.)
I used almost exactly your solution. However, even with the new version of Choicescript, the *goto_scene {roomname} wasn’t working. (I also tried roomname and ${roomname} with no luck.)
So instead I did this:
*temp roomname "unknown"
*label reroll
*rand room 1 10
*if ((room=1) and not (room_1_explored))
*set roomname "room_1"
*if ((room=1) and (room_1_explored))
*goto reroll
(etc.)
*choice
#Choose a room.
*goto where_am_i_going
#(Other options)
*label where_am_i_going
*if roomname="room1"
*goto_scene room1
It said it couldn’t find the scene file. The temp variable roomname was set to match the title of each individual scene file, so if it filled it in correctly between the brackets, it should’ve gone there.
What I posted works, and fixes the randomizing bug (since it’s one step removed from the actual random number, which is only used for a second to set another variable.) Between @Chwoka and @Winterhawk’s suggestions, plus the workaround I posted for the curly braces, the code is behaving itself.
The problem seems to be that whenever you go to the Stats page and return to where you were, the rand routine executes again and therefore you get a different result and probably end up in a different scene.
As far as I can see, this behaviour renders the rand option useless, as you get a different result everytime you visit the page where the rand appears. If you can’t keep the first random result and it keeps changing, this is quite a bug I think.
It’s a known thing. I use it to cheat quite frequently, mostly because I do hate the rand command when playing. It steals away the importance of choices, and I don’t like the uncertainty of it.
I think there’s a work around, where you make the rand command roll on the previous page, or at least at a point where the player doesn’t realise rand has rolled.
It seems I am having this same bug but I am using it for a different purpose.
In my game, battle scenes uses a damage formula that has a rand variable so that the damage output is varied. Whenever i click the stat page then return back, the output keeps re-rolling. The order of the variables goes something like this.
choice for attack
_variable to be randomized
_damage formula
_health - damage