ArrowKeySequence v3.0.1

This bundle is marked as approved. It works and satisfies the submission rules.

Info

This code allows you to create an ArrowKeySequence which can be solved by a user.
An ArrowKeySequence is for example: { [⟶] [⟶] [↑] }. ( RIGHT, RIGHT, UP)
Now, when the user puhses these arrow keys in correct order, it can be seen as solved.

Examples:
1. It can be used as kind of a puzzle.
2. It can act as opening mechanism for treasure chests like in the RPG Gothic.
3. It can be a secret cheat seqeunce wich activates something hidden.

Actually I was mostly inspired by the usage for chests like in Gothic,
but I tried to make a more universal purpose out of it.

Check out the 4 demonstrations in map to see what you can do.

Special

What makes it kind of special I think is that a user is allowed to have parallel running sequences, even of the same type.
What does this mean?

4th element was wrong and the user has to start with the very first element again.

2.) Allow parallel sequences:

[⟵]

[⟶]

[⟵]

[⟶]

[⟵]

[⟶]

[ ? ]

[ ? ]

It turns out he still can solve the sequence with only 2 new attempts,
even the [⟶] arrow key was wrong for the initial started sequence.
So if "[ ? ] [ ? ]" will turn into "[⟵] [↑]", the user solves this sequence type.

This code allows you to create an ArrowKeySequence which can be solved by a user.
An ArrowKeySequence is for example: "ArrowUp, ArrowDown, ArrowLeft".
Now, when the user puhses these arrow keys in correct order, it can be seen as solved.

It can be used as kind of a puzzle, or it can also act as
opening mechanism for treasure chests like in the RPG Gothic.

*/

//! novjass

//API

/* At first you need to create at least one
ArrowKeySequence that a user can try to solve.
You need knowledge of the Vector library to create a vector.
You can look in Sequence Demo for an example.

You also have to register a boolexpr as code,
that will run, whenever a user tries to solve a sequence.*/

For safety the destructor is wrapped into the API function DestroySequence. (see later)

// The registered code will fire whenever a user presses a key while he is about to// solve a sequence. Within the code function you have access to:

boolean IsSequenceSolved // Is sequence completedboolean IsKeyCorrect // If current input was correctinteger CurrentSequenceVectorPosition // Current position in sequenceinteger ArrowKeyInteger // Read ArrowKeyEvent for info which key it is.player ArrowKeyUser // User who pressed the arrow key

function EndSequence takesnothingreturnsnothing// The current running sequence will end for the user.

function EndSequenceAll takes ArrowKeySequence keySequence,player p returnsnothing// Will end ALL sequences of a type for the user "p".

function DestroySequence takes ArrowKeySequence keySequence returnsnothing// Will end ALL sequences of the type for all players.// Will completly destroy the sequence so it can't be used anymore. (deallocate)

// Use follwing function to start.

function StartPlayerSequence takesplayer p, ArrowKeySequence id,integer pos returnsnothing// whichPlayer// whichSequence// startPosition (All vectors start with "0". So "0" is the common start value.// But in case you want, you can manipulate it to your needs.

// It is recommended to read the demo examples.// That was it. Have fun!

// When a sequence per pe gets destroyed then// we to run though all player sequences and// remove the destroyed sequence type.function DestroySequence takes ArrowKeySequence keySequence returnsnothinglocalinteger i =0loopexitwhen(i >11)call EndSequenceAll(keySequence,Player(i))set i = i +1endloopcall keySequence.destroy()endfunction

23:56, 18th Jan 2016
BPower:
Very cool system, which could turn out to be useful for some map makers. Puzzle can always spice up games or make you turn frustrated.
I was playing the demo map for quite some time. It's cool. Check it out.

Looks like a neat thing, and would be cool for things like God-of-War sequences. Only one minor improvement from what I can see - the struct should all be normal methods which takes the player ID as the "this". The ArrowKey module provides you with static [] operators for taking a player and converting it to an ID, so your function wrappers can still take players but the struct would take the integer ID.

Also, the struct already namespaces you to PlayerSequence, so its public methods should just be "start" and "end".