Randomizer?
Narzack
22 Feb 2021, 17:03I'm looking through all the scripts, and I don't see what I'm looking for. I'm just looking for a script that after a random number of turns, text is displayed. I can see triggers for set intervals, but that's not what I'm looking for.
mrangel
22 Feb 2021, 17:28Two ways to do this would be having a turnscript that runs every turn, doing something like:
if (RandomChance (20)) {
msg ("Some text is displayed!")
DisableTurnScript (this)
}
That would mean that once the turnscript is enabled, the event has a 20% chance of happening each turn.
Or you could do something like:
SetTurnTimeout (GetRandomInt (7,10)) {
msg ("Some text is displayed!")
}
to pick a random number between 7 and 10 turns
Narzack
22 Feb 2021, 17:40So that first one is the one that I'm looking for, that looks awesome. If I set that to trigger in a room, will it keep running even if the player leaves the room? So, like, you enter a room, it triggers that turnscript and that just keeps running globally until I turn it off?
mrangel
22 Feb 2021, 18:25I think a turnscript in the room will only run as long as the player remains there. But if the turnscript is global (created from the game's "Scripts" tab), you can have a script in the room that enables it and it will stay enabled until the message has appeared.
Narzack
22 Feb 2021, 18:27Awesome. Now, if I wanted to get really crazy and have the randomizer choose a random string, can it also do that? The idea is basically a set of text strings that I want to randomly trigger throughout the game until the player reaches a point and the triggers stop.
Narzack
22 Feb 2021, 18:34So, I'm trying to also use a time-based randomizer, and I know that my syntax is wrong.
SetTimeoutID (GetRandomInt (15,20) "RandSpooks") {
PrintCentered ("COLD")
}
Obviously I'm getting a parameter error, but what is the proper randomizer syntaxz for time?
mrangel
22 Feb 2021, 21:58I think you're missing a comma between the time and the name
mrangel
22 Feb 2021, 22:04Now, if I wanted to get really crazy and have the randomizer choose a random string, can it also do that?
The most common way to pick a random string is to use the text processor. You can put something like {random:red:green:blue}
in a message, and it will select one at random when it is displayed.
Or you can use PickOneString
, which picks a random string from a stringlist.
msg ("The random colour is {random:red:green:blue} this time.")
or
msg ("The random colour is " + PickOneString (Split ("red;green;blue")) + " this time.")
Narzack
23 Feb 2021, 20:00That's great, thanks so much for your help.