The issue here is that it only selects one of the strings and keeps it as long as the server is running, not cycling between any others. A common solution I saw was this index stuff, but it didn’t solve my issue. Is it because it’s in a module script?
Here’s the code in the module:
local secrets = {
"There's a vent somewhere around here that leads to some ruins of a forgotten era... at least that's what I've heard!",
"I heard from a certain someone that there's a hatch in the roof of a certain room... dunno where it goes, but I bet it's something cool.",
"You might've noticed some buttons around the lobby. I think there's 8 of them. Pressing them all might do something!",
"I heard there's a graveyard somewhere nearby, but I don't know if the door leading outside can be opened, so I can't get to it.",
"Far in the distance, I can see a large concrete building littered with alarms. I don't know what it is.",
}
local lastSecret = 0
function secrets.selectSecret()
local newIndex
while not newIndex or newIndex == lastSecret do
newIndex = math.random(1,#secrets)
end
lastSecret = newIndex
return secrets[newIndex]
end
return secrets
I thought my explanation of the issue was pretty obvious. Yes, the function only selects one string from the table at random but does not select a random one every time the function is called.
I don’t understand what you mean here. You want me to print lastSecret and newIndex and do whatever lastSecret==newIndex is but how would that help my case? If I’m missing something please forgive me, scripting is not my forte
This is purely for debugging, you will remove it when we are done. Newindex==lastindex returns what you are checking in the while loop, whether or not they are equal to eachother.
Also, can i see the use scenario for this? You are calling the function everytime and not using a static variable for every message right? Just making sure.
Could you run the dialogue 3 times? I am trying to see if it’s selecting the same thing which means there’s a problem with your conditions or if it isn’t selecting a new one at all.
weird, not sure why it’s not working for me. I’m calling this function inside another module, which is the dialogue module, and I’m using that module for another local script which is the main dialogue manager. I dunno if it’s the way they’re ran or if it’s just a me issue.
the selectSecret function is correctly designed to select a random secret from the secrets table, but it’s always generating a new random index without considering the history of previously selected secrets.
this should do.
local secrets = {
"There's a vent somewhere around here that leads to some ruins of a forgotten era... at least that's what I've heard!",
"I heard from a certain someone that there's a hatch in the roof of a certain room... dunno where it goes, but I bet it's something cool.",
"You might've noticed some buttons around the lobby. I think there's 8 of them. Pressing them all might do something!",
"I heard there's a graveyard somewhere nearby, but I don't know if the door leading outside can be opened, so I can't get to it.",
"Far in the distance, I can see a large concrete building littered with alarms. I don't know what it is.",
}
local lastSecret = 0
function secrets.selectSecret()
lastSecret = (lastSecret % #secrets) + 1
return secrets[lastSecret]
end
return secrets
local secretModule = require(script.secretsModule)
while task.wait(2) do
print(secretModule.selectSecret())
end
Well that’s what they want, randomly generated secrets, not programmatically calculated ones. The issue is it gives them a non-randomly selected secret.
Didn’t work, it’s just the same issue. No errors or any unexpected behaviours aside from the one(s) already present. Also, this isn’t what I’m looking for and does not select strings randomly like I want it to, it’s just a regular cycle
I know how to operate module scripts, enough to know that this should work. I’m not sure why it doesn’t.
The main local script (manager) is over 300 lines long and the dialogue module is over 1200 lines long, sending it all would be way too much
Why are your local scripts that long? A dialogue script should be at most ~300 lines. Well anyway, this is probably a bug with how you’re handling the responses. You are not taking in a new response each time. I’m not sure how to help you without further context.