Scope of local variables problem and passing of pointers to arrays to procedures

Below a code segment and an error message. The error message is generated when executing the statement : Add items to list Samplebuffer Item val. This was determined by disabling this instruction , resulting in no error message (or, rather, a different error generated lower down as an artifact). Samplebuffer is declared as a local array, and I wish to add values to this array. It looks like ai2 does not recognise the reference to Samlebuffer. It sees the correct index to the array (1). Is Samplebuffer out of scope? I cannot see any reason to be out of scope. Any other obvious other reason for this strange behaviour?

Second question. I wish to transfer to this procedure a pointer to the Samplebuffer array. This will greatly facilitate the efficiency of the code. I tried passing the name of an array as a parameter to a function and then accessing specific (indexed) values in the array but no success.

Any comments would be greatly appreciated.

Kind regards, willem

AI2 lists are linked lists, so their list lengths can vary dynamically .

There is a Length of List block that is very handy for checking that, before attempting the selection of list items.

You initialized a list somewhere with a blank text.

Do you save lists in TinyDB, using empty text as default returns?

Export and upload your aia if you can't find the source of the error.

The error is generated by a “select list item” block

As said by @ABG you are using the “select list item” on an empty string ( and not a list ).

lst should be set to the create empty list block

The error suggests RxPacket is empty, Test RxPacket alone, whether its empty list filling actually or not.

@TIMAI2 lst is set to an empty string only to reproduce the error.

As far as I know there is no timeout in the bluetooth ReceiveUnsignedBytes so you should check for bytes availability ( at least before calling readmeteoData ) or your app may freeze ( for example the ReceiveUnsignedBytes you call should return only after 21 bytes are received ) .

I could be wrong, but it does not seem the error is caused by the blocks you posted.

1 Like