An endless runner follows a pattern? (SOLVED)

In the endless runner in the tutorial the start always start with a pattern:
2 in the air("middle) and then another 1 in the ground, but in the code it randomize the height so why does it follows this pattern?

I know it has only 3 numbers to randomize, but why its still a pattern?
Like every time you start the game the start follows this pattern again and again

The first three heights are hard coded, an afterwards, it uses math.random to generate new heights.

Randomisation functions generally need to have a seed set at the init, in order to ensure that the sequence appears random. If you initialise with the same seed every time, you will get the same sequence again. A common thing is to set the seed to be dependent on something external, e.g. the current time of the computer:


man lua is so different from languages such as C++ and c# :sweat:

This is how pretty much all standard random number generators work, regardless of language. The defaults may differ a bit. For instance C#:

”The Random(Int32) constructor uses an explicit seed value that you supply.

The Random() constructor uses the system clock to provide a seed value.”


I meant that you need to add the randomseed function and you cant just:
“Random rnd = new Random(int)”

Well, in C/C++ you need to do it too:

time_t t;
srand((unsigned) time(&t));
int r = rand();

@britzl what is the different between Solved and SOLVED?(In the topic title lol)

I have a question it is not related to the topic(I want to avoid spaming the forums)
Will you support more languages? and if not will you let people access to the API and use it with other languages?

Nothing really. I changed it from (Solved) to (SOLVED) for consistency since we usually marked topics where an accepted answer has been provided as (SOLVED). It’s a manual process and has no real impact, but it gives us a hint sometimes if a question has been answered or not.


No, not likely. Lua is the supported language for writing game code in. Lua is a popular scripting language with very good performance.

You can also move game logic to a native extension for even better performance. In theory you could move all game logic to C/C++ and only use script files to call your game logic in the extension.

There are examples of 3rd party solutions for writing game code in one language and then as a pre-build step it gets translated into Lua and the Defold API. Examples:


Lua is pretty tightly integrated with the engine so it would require a lot of work to change the language.