Split text block doesn't work because input isn't text

I'm transferring data from a Feather M0 by using:
ble.println(43#94#143);

I'm receiving that data in appinventor by using the "register for strings" and "when strings received" blocks.

Then I use the "split text at" block to get rid of the # symbol. The results I get are (as seen by the "do it" boxes below):

(43
94
143)

Because the first and third are not numbers, I get the error seen below. If I disable the first calculation that uses the results, the second, ie 94 works as it should but not the (43, or the 143).

When I look at the "stringValues", I get:
(43#94#143)

When I use "is a string...thing" on stringValues, false is returned.

It seemes it has something to do with the fact that the split block output is a list, but on the other hand, the input (stringValues) seems not to be a string.

What am I missing?

Thanks

Doug

You are doing a division like (43 ÷ 255. You have an extra open bracket. Try to get rid of that (.

Same for global blackWater. There is an extra close bracket ) in there.

In the Strings Received event, you receive a list of strings.
Code:

for each message in list strings
  set readings to split message at '#'
 set middle to select item 2 from readings
end for each

Thanks for the reply.

I couldn't figure out how to do that. I don't send the data with () so I don't know where they come from. Shouldn't the strings received block create strings without ()? How do I get rid of them?

See the previous post from @ABG.

Thanks for the reply.

I believe that's what I did but I'm not sure what you mean when you say "end for each". See picture of code.

This might help to explain what is going on:

image

You are getting back a list - a list of 1. You therefore need to get the first item of the list, which is your string. Then you can split the string to get the three numbers - in a list. (my list brackets are square because I have ShowListsAsJson ticked in screen properties)

There is a general rule in Ai2:

If a variable name ends in 's', it is plural, therefore it is a list.

Lists are not pieces of text.

If you try to treat a list like a piece of text, AI2 will rub your nose in it by wrapping the resultant text with () or [].

Thanks for your continued help

Yes, that's my problem. The code given by TIMAI2 does indeed work. But when I insert the real data from the StringsReceived block using stringValues, it adds in the () as if stringValues is not text and therefore no longer works.
Here's my code in the form of TIMAI2 :

When I look at the output of the feather by using Bluefruit Connect, it shows the proper format: 43#94#143

It looks like you are adding the list stringValues to a list multiData. so you now have:

((43#94#143))

a list of lists of lists

Yes. The result was the same as before, but once I removed the "add items to list" it worked perfectly.
here's my code now:

Thanks to TIMAI2 and to ABG!

Doug

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.