Difference between revisions of "Threading Notes (Papyrus)"
added images for threads
imported>JBurgess |
imported>Qazaaq (added images for threads) |
||
Line 35: | Line 35: | ||
In the image below, the player is activating a lever. Because this a nice and cooperative player, he's only activated it once. The game sends Papyrus a notification of the activate event. Because our script contains an '''onActivate()''' Event, the game creates a '''"Thread"''', which you can think of as a set of instructions copied from our script. The game queues this thread up, and will process it momentarily. | In the image below, the player is activating a lever. Because this a nice and cooperative player, he's only activated it once. The game sends Papyrus a notification of the activate event. Because our script contains an '''onActivate()''' Event, the game creates a '''"Thread"''', which you can think of as a set of instructions copied from our script. The game queues this thread up, and will process it momentarily. | ||
[[ | [[File:PapyrusThreads01.jpg|700px]] | ||
Very soon - probably on the next frame - the game processes the thread. Let's pretend that the contents of our onActivate() event look like this: | Very soon - probably on the next frame - the game processes the thread. Let's pretend that the contents of our onActivate() event look like this: | ||
Line 48: | Line 47: | ||
The player activates the switch, which notifies Papyrus to create a thread containing those instructions - After five seconds, ten gold pieces are added to the player inventory. All is well. What happens with a less cooperative player, though? | The player activates the switch, which notifies Papyrus to create a thread containing those instructions - After five seconds, ten gold pieces are added to the player inventory. All is well. What happens with a less cooperative player, though? | ||
<br>[[ | <br>[[File:PapyrusThreads01.jpg|700px]]<br> | ||
Here the player has activated the lever several times in a short period of time. That's valid input, and our script is about to receive it. In comes the first activate event - thread is created and begins processing. Here comes the second activation - and another thread is created shortly after the first. This continues as long as the player spams activations on the lever. | Here the player has activated the lever several times in a short period of time. That's valid input, and our script is about to receive it. In comes the first activate event - thread is created and begins processing. Here comes the second activation - and another thread is created shortly after the first. This continues as long as the player spams activations on the lever. | ||
Line 54: | Line 53: | ||
This can get messy fast. We need a way to keep things organized. | This can get messy fast. We need a way to keep things organized. | ||
<br>[[ | <br>[[File:PapyrusThreads03.jpg|700px]]<br> | ||
The above example represents the script as we'd want to re-write it - blocking further activations after the first. There are several ways to get this result. This example will be solved using [[States_(Papyrus)|States]]. | The above example represents the script as we'd want to re-write it - blocking further activations after the first. There are several ways to get this result. This example will be solved using [[States_(Papyrus)|States]]. | ||