Кодирование и декодирование облачных данных

Материал из Letopisi.Ru — «Время вернуться домой»
Перейти к: навигация, поиск

Кодирование облачных переменных - процесс перекодировки списка или строки в цифровой формат облачных пероеменных.


Содержание

 [убрать

Быстрый способ

Необходимые переменные и списки

Метод требует следующих переменных:

  • z
  • i
  • i2
  • i3
  • ☁ data
  • C

Кроме того, потребуется список "users". В этом примере проект будет запоминать участников, которые посетили этот проект, но этот список можно потом поменять на другой.

Кодирование

The encoding process takes each item in a list, separates them with a particular number, and converts each letter into a number with a fixed amount of digits.

В процесс кодирования каждый элемент списка разделяется числом разделителем, а каждая буква конвертируется в число из определенного числа цифр. В качестве разделителя используется код 00. При кодировании каждая буква каждого элемента списка добавляется как число. Число представляет букву в переменной z, которая содержит все все возможные буквы. Например, буква b находится в переменной z на позиции 12 и код представляющий b 12, соответственно для буквы e код 15


whenclickedsetzto0123456789abcdefghijklmnopqrstuvwxyz?defineencodesetito0setCtorepeatlengthofuserschangeiby1seti2to0repeatlengthofitemiofuserschangei2by1seti3to0repeatuntilletteri2ofitemiofusers=letteri3ofzornoti3<lengthofzchangei3by1если буква не входит в переменную "z" то цикл не завершится, поэтому условия, что все завершается после проверки последней буквы в переменной z iflengthofi3<lengthoflengthofzthenrepeatuntilnotlengthofi3<lengthoflengthofzseti3tojoin0i3 Если число цифр в i3 меньше максимального, то добавляется нужное число нулей setCtojoinCi3repeatlengthoflengthofzsetCtojoinC0set☁ datatoC

Декодирование

Декодирование берет данные в цифрах и превращает их в буквы

definedecodesetito0seti3tosetCtodata чтобы не слишком часто обращаться к облачным даннымdeleteallofusersifnotlengthofCmodlengthoflengthofz=0thenrepeatuntillengthofCmodlengthoflengthofz=0setCtojoin0CrepeatlengthofC/lengthoflengthofzseti2torepeatlengthoflengthofzseti2tojoini2letteri+lengthofi2ofCifi2=0thenaddi3tousersseti3toelseseti3tojoini3letteri2ofz 000 = 0 is true, so no matter how long the 0 is it'll be true herechangeibylengthoflengthofz

Углубленный метод

Необходимые переменные и списки

Большинство необходимых переменных задаются скриптом

defineCreateVarssetCharactersto� !"#$%&'()*+,-./:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~0123456789setp1to1This variable is the ID that will be given to the characterrepeatlengthofCharacterssetletterp1ofCharacterstojoinfloorofp1/10roundp1mod10This edited block creates a variable with the name of a specific character, with that character's 2 digit number ID inside the variablechangep1by1

Дополнительные переменные

  • Characters
  • p1
  • p2
  • p3
  • p4
  • ☁ data

Lists include:

  • CloudList
  • bypass
  • hold

Кодирование

The encoding process works in the same way as the above method, although this method uses a faster way of encoding characters to their 2 digit ID number that includes another edited block:

defineEncodedeleteallofbypasssetp1to1repeatlengthofCloudListsetp2to1setp3toitemp1ofCloudListsets a variable to the item of the cloud list we are currently encodingrepeatlengthofp3setp4tojoinletterp2ofp3ofSprite11This edited block is used to pull the data out of those variables you set with "Create Vars" replace Sprite1 with the sprite that ran the Create Vars custom blockaddletter1ofp4tobypassaddletter2ofp4tobypassAdds the 2 digit ID of the character to the listchangep2by1changes to the next character in the item of the cloud list so it can encode itadd0tobypassadd0tobypassThese 0s tell the decoder to make a new itemchangep1by1changes to the next item in the cloud list so it can encode itset☁ datatobypassThe bypass list is used to bypass the 10240 character limit of the join block, it also prevents cloud flooding (setting a cloud variable more than 3 times a second)

Decoding

The decoding script for this method will look very similar to the script for the easier version. Luckily, there are no edited blocks in this script!

defineDecodesetp1to1setp2to2deleteallofCloudListdeleteallofholdThis list collects the data for one item of the Cloudlist, it is then added to the CloudList and the process is repeatedrepeatlengthofdata/2setp3tojoinletterp1ofdataletterp2ofdataUses two variables (p1 and p2) for speed, since using another variable is faster than using (p1+1)changep1by2changep2by2ifp3=0thenaddholdtoCloudListadds decoded data to the cloud list in one itemdeleteallofholddeletes and repeatselseaddletterp3ofCharacterstoholdcollects decoded dataDoesn't need to be 00, because according to scratch, 00 = 0 even when they are read as stringsSince we encoded each character into a 2 digit number, they must be decoded in sets of 2 digits

See Also

Персональные инструменты
Инструменты