Coding Meetups - social event, tutorials and videos
Pages: 1 2
Grahame Parish (436) 481 posts |
Many years ago on the Beeb I had a program that would take the output from one cassette recorder and send it out to another, allowing perfect tape copies of software. It was – of course – a good backup system for making safe copies of tapes that got used a lot, including protected stuff, like that motorracing game where the data blocks counted down instead of up. |
nemo (145) 2556 posts | |
Andrew McCarthy (3688) 605 posts |
Gavin, do you have any example Lua code to turn on/off the caps lock key? Or similar resources to point people at to help them on their RISC OS coding journey. BTW for anyone curious about Lua, the resources Gavin has put together are impressive; as observed on the ROD and some ROOL distros. There are also other code snippets needed, from displaying an image or draw file on the screen to networking and other areas. What we thought was important was to cover those things that are done differently in RISC OS. |
Colin McMurchie (8817) 21 posts |
Indulging my drive to completion (which usually fails me) I submit a further armbob program to manipulate CapsLock. Very simplistic I know, but this thread is aimed at developing people’s skills sets?
I am finding the risc os journey quite an adventure. Joyous and frustrating in equal measure. I do wish the documentation was a little less dense however. |
nemo (145) 2556 posts |
The documentation is dreadful, being mostly ‘Not even wrong’. And your updated OS_Byte MOSvar wrangling is spot-on! |
Gavin (560) 32 posts |
Following on from Nemo’s example, I thought I’d do something similar using the Ovation Pro Scrip Language. I’ve used a loop instead of the repeat to flash the CapsLock LED 8 times – it actually toggles the CapsLock status on then off 16 times, so leaves it in the state it was at the start. To try it out, copy the code and save it with a file type of &b24 (OvPScrpt). With Ovation Pro running, drag the file to the Ovation Pro icon bar icon. It may work by double-clicking the script file (doesn’t for me as I have StrongED set to intercept it and open the file for editing). Oh and you can get Ovation Pro from here:
|
Rick Murray (539) 13850 posts |
OP is also on Store. |
Gavin (560) 32 posts |
Thanks Rick, forgot to mention Store. |
nemo (145) 2556 posts |
Gavin generously gave
For those of us unfamiliar with this language, would I be right in guessing that |
Gavin Crawford (560) 34 posts |
Absolutely correct! My StongHelp manual for the OPro script language is available here: |
GavinWraith (26) 1563 posts |
I hope you do not mind another Gavin replying. There are one or two Gavins around. Here are some comments:This Lua program is intended to be run in a taskwindow. You can do this by dragging it onto the iconbar-icon of !TaskW which can be found in the RiscLua distribution, in !rlua.Utilities. Because in Lua a variable can only be used after it has been defined, Lua programs must be read backwards, i.e. bottom up. It is my habit to use comments for definitions that contain a ‘uses’ clause, referring to which prior definitions are used in it. This helps to make clear the dependencies in the program. Thus: Here ‘capslock’ is a table of functions, indexed by the commands “on”, “off” and “quit”. If no action is found corresponding to the input, then “sorry – what?\n” is printed and the while-loop continues. The expression ‘io.read “*l”’ reads a line of input. The ‘lower’ method converts a string to lowercase, so that the capslock state cannot affect the behaviour of the program. The expression ‘pcall (action)’ executes ‘action ( )’ in protected mode – a trope that is not actually necessary here but is included to demonstrate its possibility.Note that in the bit-twiddling operations | ( logical OR) and & (logical AND) and ~ (logical NOT) have been used. Note also that the variable ‘quit’ is used in two distinct environments: as a local variable of global scope and as an index in capslock. This may seem confusing to those who are not accustomed to programming languages like Lua which give tight control over namespaces, but abuse of language is a powerful (some even say, a necessary) feature that can give more clarity. Note also the use of the left-shift operator << in the definition of caps_mask. It is conventional in Lua to use the underscore symbol, _, for variables that are not used, as in in the definition of kbd.The first line defines the local variable ‘sys’ to have the value it has in the ‘riscos’ library. The ‘require’ function loads this library dynamically,without, in this instance, assigning it any name. Such a name is unnecessary here because no other values in the library are used in the program. This use of ‘in’ is not available in standard Lua, but is an innovation of RiscLua. |
Andrew McCarthy (3688) 605 posts |
Gavin, thank you for your contribution, it’s great! I also include everyone else whose input so far. It’s so valuable because creating examples helps explain some of the trickier areas of RISC OS. That means we are not only passing down and sharing knowledge but laying the foundation of understanding for those that follow. So, if you have a code snippet to share or are struggling with a RISC OS concept, come and join in. |
Andrew McCarthy (3688) 605 posts |
@Gavin Crawford. I’ve run the script and it worked. I saved the text selection to disc from the browser, changed the file type to OvPScrpt. Double-clicked the file and behold a flashing caps lock LED. :) @Colin McMurchie. As above, but changed file type to bob and double-click the file- it worked, a flashing caps lock key, Esc key to quit. :) Thanks again, Andrew |
Gavin Crawford (560) 34 posts |
@Andrew McCarthy I’ve edited the original post to remove the p. Glad the script worked for you. I use a wireless keyboard on my system and it doesn’t actually respond quick enough the the changes in the OS, but I used the traffic lights system that is part of !HID that shows the keyboard status LEDs (similar to @Nemo’s offering) |
Andrew McCarthy (3688) 605 posts |
Thank you, Gavin; it’s good to know we’ve helped each other. And you’ve highlighted that Ovation Pro has a powerful scripting language. I didn’t know that. :) I’ve only ever made good use of !TechWriter. The task for next week, find out what is wrong with my installation of Lua- I get a “stick” error message, something to investigate with another build. In the meantime, if anyone whose experienced cross-platform development has any code snippets that highlight the RISC OS way of doing things. Come and join in; it’s a bit of fun. |
Jeffrey Lee (213) 6048 posts |
The LEDs module is finished, but in the process I discovered a regression in RO5 to do with translation tables, which I thought I’d document here. This was introduced in 5.2x but I’ve only just noticed. Are you able to provide some sample code to showcase this problem?
If you’re going to make such claims then please provide evidence which supports them. |
Pages: 1 2