FANDOM


You can use randomness to allow for different actions in a given map, such as spawning a guard with a KF7 or an RCP90 instead, or spawning Dr. Doak in a different location each time, etc.

You can put these randomness blocks in anything, 04XX or 10XX blocks, but it is recommended generally to put them in 10XX blocks, because if a guard dies, so does his 04XX block with him, and it stops executing.

Lets just do a simple randomness block where it displays different text on the screen depending on the random number. Note that text can ONLY be displayed if the text is currently loaded for the level. You cannot load Runway’s text on Bunkers, or vice-versa. Some text is always loaded such as LTitleE and LMiscE.

The main important commands are 33 (seed random byte), and 34, a return value loop function for whether the seeded random byte is < a certain value. Note, you could alternatively use 35, a return value function to check whether random value is > a value, but it’s easier to stick with one or the other.

Basically, what is done is a random byte is generated, and then it is checked whether it is below a value. In this example, there are four checks, to see whether it’s below 0x40, 0x80, 0xC0, and then the else clause (above 0xC0).

It looks like in C code:

if (randomValue < 0x40)
{
DisplayText(0x9C38);
}
else if (randomValue < 0x80)
{
DisplayText(0x9C28);
}
else if (randomValue < 0xC0)
{
DisplayText(0x9C33);
}
else
{
DisplayText(0x9C07);
}
//go on now at 0210, in this example we just exit by 05FD0001
Block: 1000

Random1


The basic gist is the following sequence:

33 Seed Random Byte (to start the process off)
344001 ; Check if value is < 0x40, if so goto 0201, else continue
0002; If not < 0x40, goto 0202
0201 ;was < 0x40
C39C38 ; display text
0010 ;goto end, we found our match
0202 ; // do next check
348003 ; check if was < 0x80

0210 ;we’re finished checking

As a final note, remember that the last two checks actually both are endings, because if you check whether it’s < 0xC0, that’s one clause, and if it doesn’t fit there, then it’s above 0xC0 and another ending.

In this example, in Runway if done there, it will randomly display one message when you start the level. NOTE: Had you not done the 05FD0001 at the end, it would constantly be showing random text messages forever.

Random2

Random3

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.