# Random letters with password ones

I am creating a rebus game in which the player has to choose individual letters and arrange them into a password based on the picture.

Problem: I’m trying to generate 20 random letters among which are those to complete the correct answer. The letters should add up to the next free field for the answer.

use random text varible

And what is that? Maybe you could explain what you mean here?

@Marcin, can the extra random letters that make up the puzzle answer occur more than once? So say for example the answer was rebus, could the other random letters be an ‘r’, ‘e’, ‘b’, ‘u’ or ‘s’?

One approach:

Pull your password letters out of array A and put them in array B.

Now pull x random letters out of array A to complete the 20.
Now you have lists containing the password letters, the active game pool of letters, and discarded letters, which should be enough for your game logic.

@MrMen Yes, absolutely. I created another topic with different problem, but I can show you here with the same screenshot how I solved it (its still not how it should be):

@per Here I’m using extension “Choose::RandomString”, but also I’m choosing by hand letters which are right to resolve the rebus…

Hey Marcin,

Because you’re choosing letters randomly for each text, some letters wouldn’t be chosen at all, even the ones required for the password.

I’ll give you a solution that does this dynamically, and you can build upon it.

Let’s say you have a level where the password is “DOOR”.

Declare these variables:

Event:

The event runs like this:

1. Repeat 4 times (number of characters in the password, in this case it’s 4, stored in the variable “Length”), extracting each letter from the password and adding them as children to the array “Letters”.
2. Repeat 16 times (20 - 4) and add random letters to the array.
3. Shuffle the array so that the password is not in the first 4 letters (Install the ArrayTools extension to get this action)
4. Repeat for each text object and set them to the children of the “Letters” array.

So for each level you’ll only need to change the “Password” variable and the rest is done automatically.

Edit: I saw your other topic and I didn’t notice you changed the event in this screenshot. The solution I shared does this automatically so you don’t have to do do this manually for every level.

1 Like

@insein First of all - absolutely thank you for your 1:1 help!

Perhaps this is a silly question - but do you have an add-on or a different version of the engine? Because, despite trying to find it in the engine as well as in the docs, I am not able to create “Declare Lenght/Counter as Number with 0”…

He is using some local variables which he called Length and Counter. You can bring up the local variable menu by selecting an event and when it is highlighted hit shift-L or you can also highlight an event (it can be empty) and clicking the circle with the fat = sign inside it in the top right toolbar.

1 Like

No problem!

As Luck-j mentioned, these are local variables and were newly added to GDevelop in the recent updates. So make sure you are on the latest version.

You can also bring them up the same way you add other events like repeat and for each object events. Right-click > add > local variable.

If you’re not familiar with the new variables system, then I recommend checking this video tutorial.

1 Like