Player choices changing chances

chellkafka
Basically, I was wondering if I could implement a system where the player would explore one environment with things 99% of the time and the remaining 1% a different location with different things, but if the player does certain things the probabilities shift to 98% : 2%, 97% : 3%, etc.

For example, the player starts off in a room. 99% chance that it's a regular room and 1% chance it's a weird one. And that should be with every room. Now if the player for example reads a Nietzsche quote or something, the likelihood of becoming the weird room when the player enters the next room should then be 2%. And then when the player reads another quote or something the chance should rise again, to 3% and so on.
Is that possible with quest? And how?
Any ideas?

HegemonKhan
first, you need to create the different rooms:

(You should be able to do this hopefully)

second, you need a (local:room) counter for your event in~for that room:

room_0.nietsch_read_quantity_integer = 0

room_0.nietsch_read_quantity_integer = game.nietsch_read_quantity_integer + 1

third, you need a (local:room) Turnscript:

if (game.nietsch_read_quantity_integer = 0) {
(see below for script choices)
} else if (game.nietsch_read_quantity_integer = 1) {
(see below for script choices)
} // etc etc etc

'probability' scripts and rest of scripts:

GetRandomInt (min_value,max_value)

or

RandomChance (percentage value:0 to 100)
// it's a boolean, using a percentage, if (100 ---> 100% of being true = true), then do script1, else if (...), else (...)

if (RandomChance (50) = true)
50% of the time: if (true = true), then will DO script1
50% of the time: if (false = true), then will NOT do script1

if (RandomChance (50) = false)
50% of the time: if (true=false), then will NOT do script1
50% of the time: if (false = false), then will DO script1

if (RandomChance(100) = true)
100% of the time: if (true = true), then will DO script1, but this is 100%, so this will ALWAYS happen
0% of the time: if (false = true), then will NOT do script1

if (RandomChance(0) = true)
0% of time: if (true = true), then will DO script1, but it's 0%, so this will NEVER happen
100% of time: if (false = true), then will NOT do script 1, but it's 100%, so this will NEVER do script1

if (RandomChance(100) = false)
100% of the time: if (true = false), then will NOT do script1, but it's 100%, so this will NEVER do script1
0% of the time: if (false = false, then will DO script 1, but it's 0%, so this will NEVER happen

if (RandomChance(0) = false)
0% of the time: if (true = false), then will NOT do script1, but it's 0%, so this will NEVER happen
100% of the time: if (false = false), then will DO script1, but it's 100%, so will this ALWAYS DO script1

hopefully, you understand this now, and thus will understand:
if (RandomChance(75) = true)
if (RandomChance(25) = true)
if (RandomChance(75) = false)
if (RandomChance(25) = true)

// -------------------------

// so, in full:

if (game.nietsch_read_quantity_integer = 0) {
if (GetRandomInt(0,0 = 0) {
player.parent=room_0
}
} else if (game.nietsch_read_quantity_integer = 1) {
if (GetRandomInt(0,1) = 0) {
player.parent=room_0
} else if (GetRandomInt(0,1) = 1) {
player.parent=room_1
}
} // etc etc etc

// OR

if (game.nietsch_read_quantity_integer = 0) {
if (RandomChance (100) = true) {
player.parent=room_0
}
} else if (game.nietsch_read_quantity_integer = 1) {
if (RandomChance(90) = true) {
player.parent=room_0
} else {
player.parent=room_1
}
} else if (game.nietsch_read_quantity_integer = 2) {
if (RandomChance(50) = true) {
player.parent=room_0
} else if (RandomChance(90) = true) {
player.parent=room_1
} else {
player.parent=room_2
} // etc etc etc

jaynabonne
I think if you go the "if/else" route, you'll just slowly go mad with all the possible cases. It might be cleaner just to have a probability attribute that you start off at 99 and then decrement for each event that occurs. That allows you to add events without having to know about all of them in one bit of script (for example). They call that having "loosely coupled" code...

player.weird_room_probability = player.weird_room_probability-1

Then you'd just have:

if (RandomChance(player.weird_room_probability) {
// normal room
} else {
// weird room
}

which you want whenever the player enters a new room. Fortunately, Quest has a new feature which makes that easy (easier than tracking it, for example, in a turn script): the game object can have a "roomenter" script attribute, which will be called every time the player enters a new room. I just learned that one recently, thanks to Pertex... :)

You might need to modify the above depending on how you implement the "weird room" case. If it means moving the player to some weird room, then you need to be careful since you're trying to actually divert the moving-from-room-to-room process which means you need to catch things *before* they have entered the new room and also not have it kick again when you're moving them. I'd have to think about that a bit, but perhaps if you need more, if you could explain what makes a room weird, that would help.

chellkafka
Well, I thought that I would implement it this way:

I have the command "go through door"

if randomchance 99% then move Player to regular room
else move Player to weird room


a weird room would simply be a completely different room.

I'm confused by this:

player.weird_room_probability = player.weird_room_probability-1


What does that mean exactly? shouldn't there be two variables?

HegemonKhan
Jay's saying with this that you'll count down (it's a subtraction math expression) from 100 to 0, which is then used for your value in RandomChance(value), to just show how it works:

player.probability = 100

if (RandomChance(player.probability) = true) {
player.parent=normal_room
} else {
player.parent=weird_room
}

player.probability = player.probability - 1

player.proability = 99

if (RandomChance(player.probability) = true) {
player.parent=normal_room
} else {
player.parent=weird_room
}

etc etc etc

jaynabonne
Ah, ok. So if you have a special command, then you'd just check the random chance there. Something like:

  <command>
<pattern>go through door</pattern>
<script>
if (RandomChance(player.probability)) {
player.parent=some_sort_of_normal_room
} else {
player.parent=weird_room
}
</script>
</command>

The line:

player.probability = player.probability - 1

is what you have wherever the special events are. To use your example, if they read the Nietzsche quote, then you'd decrement the probability. If they did something else that would increase the chance of the weird room, you decrement the probability. That's what I meant by "loosely coupled". You just add that line wherever something novel has happened that you want to increase your chances of the weird room. You don't need to know about it in your "go through door" command. The probability just gets decremented wherever it needs to be.

Now, the above code has this "some sort of normal room" thing. I don't think you want to have just two rooms, one normal and one weird. To be honest, I have no idea - maybe you do. But I would think you'd have a normal room to go to *from that room*, otherwise the weird one. If so, and if you're using a command to exit, then you're not using normal exits, so you'll have to manage the room links yourself.

One way to do it is to assign a "nextroom" attribute to each room. It would be of type "object". There you'd specify the next normal room to go to. Then the code above would be:

  <command>
<pattern>go through door</pattern>
<script>
if (RandomChance(player.probability)) {
player.parent=player.parent.nextroom
} else {
player.parent=weird_room
}
</script>
</command>

I hope this is helping!

chellkafka
Ah, ok, I think I got the hang of it. I did not know that
player.probability = player.probability - 1
means "Set variable to ..." I usually work in Editor mode.
Thanks for the help.

HegemonKhan
ah, that was your confusion, hehe.

yes, any of the 4 computational math coding expressions:

Addition:

Object.Attribute = Object.Attribute + Value

Subtraction:

Object.Attribute = Object.Attribute - Value

Multiplication:

Object.Attribute = Object.Attribute * Value

Division:

Object.Attribute = Object.Attribute / Value

are done in the GUI~Editor, via:

run as script -> add a script -> variables -> set a variable or attribute

---------

the two most powerful scripts, using them together especially, enabling you to do 90% of whatever~anything that you want to do:

GUI~Editor:
1. 'set a variable or attribute' Script <---> Code form: Object.Attribute = Value_or_Expression
2. 'if [Expression]' Script

1+2. Code form: if (Object.Attribute = Value_or_Expression) { scripts } else if (Object.Attribute = Value_or_Expression) { scripts } else { scripts ]

Darkweaver
Man, Quest really does seem almost limitless in what it can do for IF games. Pretty impressed when I hear all the things it can do.

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums