Advertisement
Slowstone72

Sliding Name for Multiplayer Piano

Dec 1st, 2024 (edited)
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* "Sliding Name for Multiplayer Piano"
  2. 2022.05.12 - 2024.12.06
  3.  
  4. Callum Fisher <cf.fisher.bham@gmail.com>
  5.  
  6. This is free and unencumbered software released into the public domain.
  7.  
  8. Anyone is free to copy, modify, publish, use, compile, sell, or
  9. distribute this software, either in source code form or as a compiled
  10. binary, for any purpose, commercial or non-commercial, and by any
  11. means.
  12.  
  13. In jurisdictions that recognize copyright laws, the author or authors
  14. of this software dedicate any and all copyright interest in the
  15. software to the public domain. We make this dedication for the benefit
  16. of the public at large and to the detriment of our heirs and
  17. successors. We intend this dedication to be an overt act of
  18. relinquishment in perpetuity of all present and future rights to this
  19. software under copyright law.
  20.  
  21. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  24. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  25. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  26. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  27. OTHER DEALINGS IN THE SOFTWARE.
  28.  
  29. For more information, please refer to <https://unlicense.org/> */
  30.  
  31. let updateInterval = 5000; // how many milliseconds before the slide advances
  32. let sliding = false;
  33. let slide = ["Hello"];
  34.  
  35. setInterval(() => {
  36.     if (!sliding) {
  37.         sliding = true;
  38.         let i = -1;
  39.         let interval = setInterval(() => {
  40.             i ++;
  41.             MPP.client.sendArray([{ m: 'userset', set: { name: `${slide[i]}`  } }]);
  42.             if (i >= slide.length - 1) {
  43.                 clearInterval(interval);
  44.                 sliding = false;
  45.             }
  46.         }, updateInterval);
  47.     }
  48. }, 10000);
  49.  
  50. const createSlide = txt => {
  51.     return new Promise((resolve, reject) => {
  52.         let i1 = -2;
  53.         let i2 = 22;
  54.         let arr = [];
  55.         let int = setInterval(() => {
  56.             i1 ++;
  57.             i2 ++;
  58.             arr.push(txt.substring(i1, i2));
  59.             if (i2 >= txt.length) {
  60.                 clearInterval(int);
  61.                 resolve(arr);
  62.             }
  63.         }, 0);
  64.     });
  65. }
  66.  
  67. const setSlide = txt => {
  68.     createSlide(txt).then(output => {
  69.         slide = output;
  70.     });
  71. }
  72.  
  73. // Example:
  74.  
  75. setSlide(`This is a super duper sliding name. Wow! What do you think, huh? Incredible, right?
  76. Okay, see you later.`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement