ink icon indicating copy to clipboard operation
ink copied to clipboard

Does anyone know how to have a random knot come up in Ink?

Open Codexehow opened this issue 3 years ago • 2 comments

Sorry if this is the wrong place to ask.

I'm wanting to program a simple Oregon Trail type of game in Ink. But I can't find a simple way to have a central hub from which to select random events (knots).

The central gameplay loop is a knot that displays variables as you go (the camp/wagon, I guess). Then the player would select from random things to do and would have to make choices in those knots. Then they come back.

The issue I'm having is that I can't find a simple way to have random knots presented to the player.

I came across this code on a GetHub thread, but I can't make it work:

{

  • RANDOM (1, 3): -> a
  • RANDOM(1,2): -> b
  • else: -> c }

I'm not a programmer, so I can't do much :P.

Any help would be greatly appreciated. Particularly if there is a way to make images come up randomly too. That would be amazing. I know Ink was not designed with images in mind, but that would be swell.

Codexehow avatar May 03 '22 20:05 Codexehow

The idea is here, but you don't want to use the Random function like this.

VAR knotRandom = 0
~ knotRandom = RANDOM(1,6) // Here I put the value from the random into a variable. So it's fixed only once. The parameter says that I want a value between 1 and 6 (both included)

{
- knotRandom <= 3 : ->a //1, 2 and 3 goes here
- knotRandom > 3 && knotRandom <= 5: ->b // 4, 5 goes here
- else : ->c //the rest goes here so 6
}

=== a
A random
->DONE

=== b
B random
->DONE

=== c 
C random
->DONE

By affecting the random value to a variable, I fix it. Each time the function is called, it will generate a new random number so your condition was basically : is a number between 1 and 3 >0 ? Great, go to a is a number between 1 and 2 > 0? Great, go to b else go to c.

As the first condition was always true, it never changed.

Here we are first saying we want the number between 1 and 6 (so the else had the 1 out of 6 chance to happen.) Then we are comparing the value obtained with the different probability we want to have for each outcome.

Selsynn avatar May 03 '22 22:05 Selsynn

You can also just use a shuffle.

===MainKnot
{shuffle: 
- -> knot1
- -> knot2
- -> knot3
}

GreenCloversGames avatar May 04 '22 12:05 GreenCloversGames