Hi Erel,
This is my first post on this forum. First I would like to thank you very much for building this whole thing. I am a freelance VBA developer - I hate Java, but I love Visual Basic, so in Basic4Android I feel right at home.
Also, I apologise in advance for the length of my post. I have a fairly simple problem, actually.
I am developing an interactive Android game where two devices are constantly sending simple textual messages back and forth via Bluetooth. I am not using InitializePrefix, and I am considering trying AsyncStreamsText, but it might be unnecessary.
Here is my situation: when both devices are in the menus part of the game, where the users have the opportunity to change various settings which affect the game; and I connect the devices to each other via Bluetooth (which I 'borrowed' from your Bluetooth chat example and I integrated it in my in-game menus), changing one setting on one device changes the same setting appropriately on the other device almost instantaneously. So the two-way communication works, and that's great. Then I hit the 'PLAY' button on either device, and both devices load the gameplay screen and start playing the game. So that's excellent.
However, once I start the actual game, which works in real-time, I am experiencing the exact issue which you described above as
You will need to track the state with a global variable until the communication is done.
and
AsyncStreams does work in the background. However when new data arrives it delegates it to the main thread. Your code runs in the main thread. Android doesn't allow you to pause the main thread. After several seconds it will show an "Application not responding" dialog.
You should store the current state in a global variable. It shouldn't be too difficult.
Namely, while the real-time part of my game is running, all of the text messages get queued up on both devices. When the real-time part is done running, the devices start reacting to the text messages from each other, and there are a lot of them because they got queued up on both sides. This was supposed to occur during the real-time gameplay, not after it.
Now, I understand that Android doesn't allow me to pause the main thread in order to execute the code which needs to run when new data arrives. That makes sense to me.
However, I did a test with ToastMessageShow - I put a ToastMessageShow at the beginning of the AStream_NewData event, and it never runs during the real-time portion of the gameplay.
So, my question is: how do I do this? How do I track the state with a global variable? I understand that in my main loop, at the end of each iteration of the loop I need to check that global variable, but how?
So 1) What exactly do I need to track the state of?, and 2) what do I put in the global variable?
I cannot read the Buffer as part of the loop in the main thread, because Buffer() is passed to the AStream_NewData event and I have no access to the Buffer outside of the AStream_NewData event - and the AStream_NewData event doesn't fire up during the main loop, but in queues up instead and fires all of them after the main loop is done.
Could you please give me some sample code where this is handled, so that the main loop checks the global variable at the end of each iteration, and I also needs to see what gets put into the global variable and when.
(offtopic) Also, I just wanted to make a small suggestion for future improvements. When using the Find & Replace string feature in Basic4Android, I want to do a 'Replace All' within one sub, so I select that entire sub and do the replace, and it works the way I want it to.
My question is - could you please add check boxes or radio buttons to the Find dialog box so that the user could specify whether they want to "Replace <this> with <that>" within the current sub, within the current module, or within the current project?
Thanks!