Post by pzelchenko on Apr 6, 2022 6:51:35 GMT
Wie gehts, Gijsbert! I just spent five hours isolating a tiny problem with some code. We're working on an experiment with an elaborate display of 9 column x 4 row target-distractor arrays (see bottom). It's a single static display, so there's no need to change any object locations. Instead of having 36 little bitmaps which might cause loading and display problems, for now we are displaying it as a single image. To get 36 mouse click zones, we need to first display 36 (white) rectangles underneath and then superimpose the large image over them all as the 37th image. Then we do -readmouse l @1 5000 range 1 36- only, to allow mouse clicking only on the small rectangles beneath. I'm not sure if there's a better way to do this, but this works quite well.
I was trying to come up with an elegant way to store coordinates for the 36 boxes, but I couldn't find anything really compact (e.g., two nested -while- loops didn't seem to work). So I decided to populate two && arrays:
block training
# initialize two 36-cell (9 column x 4 row) arrays for target/distractor cells (x,y) positions
# x=col array ---1 ---2 ---3 ---4 ---5 ---6 ---7 ---8 ---9
set &&rectx0 46 137 228 450 541 632 840 931 1022
set &&rectx &&rectx0 times 4 # 4 such rows -- note that -set &&rectx &&rectx times 4- does not work
# y=row array
set &&recty 46 times 9 # each row of 9 objects has the same y position
set &&recty2 225 times 9
set &&recty3 404 times 9
set &&recty4 583 times 9
set &&recty append &&recty2
set &&recty append &&recty3
set &&recty append &&recty4
tasklist
present 24 all_before_repeat
end
This code is not ideal, but it happens to work. In the task section, I simply refer to &&rectx[] and &&recty[]. But at one point I accidentally introduced a typo: -set &&recty append &&rrecty- (instead of append &&recty2). The typo was hard to spot. The compiler not only didn't ever complain that &&rrecty hadn't ever been initialized, it compiled -- but during execution it simply hung in the block code with no indication of what was happening. If it had only added a null array, at least the problem would have been easier to troubelshoot, but in this case something deeper went wrong. In addition, the server was very sluggish at the time, so my commenting out this code (repeated times) and recompiling happened to end up giving almost identical behavior. (Or maybe the faulty code was making the server freak out.) Finally, I isolated the problem of the typo.
Would it be possible to check this token for an initialized array and make it a compile-time error? Related things that I encountered during this work:
- Can you think of any clean syntax that would make this tighter? Either a totally different approach that doesn't use && arrays, or perhaps some kind of syntax like -set &&recty append 225 times 9-? How hard would that be to implement? And, are there other good use cases for it?
- Similarly, -set &&rectx 46 137 228 450 541 632 840 931 1022 times 4- would be appropriate in this kind of context, and probably not too painful to implement.
- I'd like to put the array -set- code in the -options- section, but when I tried that it didn't seem to work. I'm not sure if I did something else wrong, but I believe the documentation says that this is possible, and it might make more sense for a global array of quasi-constants not to be initialized inside a block.
- Is nested -while- not implemented? I haven't seen any documentation supporting it. Or maybe I did something wrong? Possibly the above feature proposals might be easier to implement in the short run, but they are somewhat limited in their power.
- Note that -set &&rectx &&rectx times 4- does not work. I can imagine this might be hard to implement. It's a minor thing. But possibly at least make a note of it in documentation?