An archive of community.esquilo.io as of Saturday January 26, 2019.

# Blob string initialization expects integer or float?

mdoan7

I want to initialize a blob(200) using a string. I keep getting this error:
%%Runtime error [parameter 1 has an invalid type 'string' ; expected: 'integer|float']

I thought perhaps it was the length of my string (for 200 entries)... so I tried the shorter example described in docs and get the same error. Am I missing something?

local buffer = blob(3);
buffer.puts("\x12\x34\x56");

On a related note, if this works as intended, is there a method of putting line breaks in the code so I don't have to scroll all the way to the right to see the full init string?
Thanks.

Scott_Shumate

After writing the documentation, we changed the name of that method from puts() to writestr() for more consistency in the libraries. We'll update the docs accordingly. Try this:

local buffer = blob(3);
buffer.writestr("\x12\x34\x56");

To break a long string, you can use the concatenation operator:

local buffer = blob(100);
buffer.writestr("A really long string " +
"that I want to break.");

Or you can use two calls since blobs are streams and remember their write position:

local buffer = blob(100);
buffer.writestr("A really long string ");
buffer.writestr("written in two parts.");
mdoan7

@Scott_Shumate Awesome. That worked perfectly. Thanks for the quick response. Now I have a soft S-curve servo movement and other goodies in return shortly.