That was stupid of me to have shadowed Kawa's number->string. I should probably change that.
--
I've created a few convert unit blocks including:
--
I've created a few convert unit blocks including:
Dec to Hex
Hex to Dec
Dec to Binary
Binary to Dec
I had almost finished them but hit the stumble block with the number->string not working. Now that this is sort would you like me put a proposal to add these blocks to MIT AI as I've seen a number of request previously on the forum for conversion blocks before.
--
Sure, file it as an issue on Github. Label it as needing comments. Do you want to assign it to yourself?
You might want to make these all a single block, with a dropdown selector, and have fun playing with block mutators.
See the text split blocks for an example.
--
I have filed an issue https://github.com/mit-cml/appinventor-sources/issues/162 I was able to assign it to myself as I don't have permissions to do this or add labels on Github.
below is a screenshot of the blocks convert blocks I added
I had already added the blocks in on the weekend a long with a few other math blocks which work out distances and new coordintes (Useful for games but for another discussion)
I've created a small app which I'll post when I get home from work. The app demonstrates the convert blocks in use. Will also upload mi AI version to my Appspot so other people can try out these blocks
--
On the last post I made a typo (Typo is in red)
I have filed an issue https://github.com/mit-cml/appinventor-sources/issues/162 I wasn't able to assign it to myself as I don't have permissions to do this or add labels on Github.
--
OK. I'll take care of it. As I said, I'm not sure I want to add all those individual blocks. But we'll see.
I'll put the issue on Gihub later today.
In the meantime, look at how the text split blocks work.
--
It is same as the textsplitter it is one block called convert with a dropdown box for the 4 conversions types
dec to hex
hex to dec
dec to binary
binary to dec
--
Right. Take a look at how that block is coded. There are some tricky parts having to so with the mutators and the DOM.
--
Attached is a sample app I created from the mod to AI to convert dec>hex and dec>binary this works fine.
When I tested the hex>dec and binary>dec I didn't think about checking for valid hex input is 0123456789ABCDEF and binary input of 0 or 1 so may need to do a bit more work on these in the code to be able to keep them in the same dropdown list as dec>hex and dec>binary.
The one good thing though is I have achieved what I wanted so far which was to be able to convert decimal to Hexdecimal easily which I really needed to control some robots I have
--
Sounds like a good start.
But what are the specs for this? Is the result of dec>hex a number or a string?
--
It's a string also the dec>binary is as well
--
The component in now fully working as one block with 4 mutators as shown below
I have attach a new sample app that allows you convert to the different units using the maths block I have written. Below is a screenshot showing all the blocks to create the app.
I can do this in another more long winded way in scheme shownin my example code below which replace 1-9 and A-F with "" from the input and check the length = 0, but I was hoping to do this with 1 line of code using regular expression code instead. Any ideas?
I have attach a new sample app that allows you convert to the different units using the maths block I have written. Below is a screenshot showing all the blocks to create the app.
--
Looks good. Please submit a pull request. (including unit tests)
--
Haven't done any unit testing yet as this is new to me. Might take me a while to get my head around as the only javascript I have ever written is in AI Source code.
Will look at the link appinventor\blocklyeditor\tests\README you mentioned and read up on it.
I ran the ant BlocklyTest and looked at the report it produced. (Note: I ran the ant BlocklyTest on a fresh unmodified version of the latest AI Source) Seemed a bit foreign to me and noticed when I looked at he report it had a lot of fails? Is this normal and correct or are the tests code not written to the current AI Source code or maybe I missed something when I ran the ant BlocklyTest. I have attach a report.zip file for unit test report I ran.
Previously when testing my AI code all I have done is created small project and made sure the new components and blocks I have created work as expected and I try to test them to breaking point. As a self taught programmer I have never heard of unit testing so will need to do some reading up on this and will probably have lots of questions about unit testing and what things to test for in App Inventor when doing it.
--
You should not get any failures from the tests. Do you have phantomjs installed?
Take another look at
appinventor\blocklyeditor\tests\README
Note that you can create these unit tests using the same pattern and the other generator tests. All you need to do is to define four variables and edit the .java file to run your additional test.
Let me know if you are still having problems.
--
I have merged my code with the latest AI source code. I have also added the internationalization for english in the file appinventor\blocklyeditor\src\msg\en\_messages.js as shown below
Blockly.Msg.LANG_MATH_CONVERT_UNITS_TITLE_CONVERT = 'convert unit';
Blockly.Msg.LANG_MATH_CONVERT_UNITS_OP_DEC_TO_HEX = 'dec to hex'; Blockly.Msg.LANG_MATH_CONVERT_UNITS_OP_HEX_TO_DEC = 'hex to dec'; Blockly.Msg.LANG_MATH_CONVERT_UNITS_OP_DEC_TO_BIN = 'dec to binary'; Blockly.Msg.LANG_MATH_CONVERT_UNITS_OP_BIN_TO_DEC = 'binary to dec'; Blockly.Msg.LANG_MATH_CONVERT_UNITS_TOOLTIP_DEC_TO_HEX = 'Returns the conversion from decimal to hexdecimal'; Blockly.Msg.LANG_MATH_CONVERT_UNITS_TOOLTIP_HEX_TO_DEC = 'Returns the conversion from hexdecimal to decimal'; Blockly.Msg.LANG_MATH_CONVERT_UNITS_TOOLTIP_DEC_TO_BIN = 'Returns the conversion from decimal to binary'; Blockly.Msg.LANG_MATH_CONVERT_UNITS_TOOLTIP_BIN_TO_DEC = 'Returns the conversion from binary to decimal'; Blockly.Msg.LANG_MATH_CONVERT_UNITS_HELPURL_DEC_TO_HEX = 'Returns the conversion from decimal to hexdecimal'; Blockly.Msg.LANG_MATH_CONVERT_UNITS_HELPURL_HEX_TO_DEC = 'Returns the conversion from hexdecimal to decimal'; Blockly.Msg.LANG_MATH_CONVERT_UNITS_HELPURL_DEC_TO_BIN = 'Returns the conversion from decimal to binary'; Blockly.Msg.LANG_MATH_CONVERT_UNITS_HELPURL_BIN_TO_DEC = 'Returns the conversion from binary to decimal';
For the other 3 translation folders :
⦁ appinventor\blocklyeditor\src\ msg\es_es
⦁ appinventor\blocklyeditor\src\ msg\zh_cn
⦁ appinventor\blocklyeditor\src\ msg\zh_tw
⦁ appinventor\blocklyeditor\src\
⦁ appinventor\blocklyeditor\src\
⦁ appinventor\blocklyeditor\src\
I won't be able to translate these myself as I speak english. Shall I add the same message code and let MIT sort the to translate out or not add them to the other languages?
--
I am trying to add a validation check on the for the input e.g
Hex can include the following character 0-9,A-F
I found some documentation of the net to do this in scheme http://srfi.schemers.org/srfi-115/srfi-115.html#proc-rx
(regexp-matches '(* (/ "0123456789ABCDEF")) "1F") is true
(regexp-matches '(* (/ "0123456789ABCDEF")) "THIS") is false
I added this to my runtime.scm code and I get the error :
"unbound location regexp-matches"
So I think the regular expression are not supported in scheme?
I can do this in another more long winded way in scheme shownin my example code below which replace 1-9 and A-F with "" from the input and check the length = 0, but I was hoping to do this with 1 line of code using regular expression code instead. Any ideas?
(let ( ($hexinput "FA1") ) (set-and-coerce-property! 'Screen1 'Title (if (call-yail-primitive yail-equal? (*list-for-runtime* 0 (call-yail-primitive string-length (*list-for-runtime* (call-yail-primitivestring-replace-all (*list-for-runtime* (call-yail-primitive string-replace-all (*list-for-runtime* (call-yail-primitive string-replace-all (*list-for-runtime* (call-yail-primitive string-replace-all (*list-for-runtime* (call-yail-primitive string-replace-all (*list-for-runtime* (call-yail-primitive string-replace-all (*list-for-runtime* (call-yail-primitive string-replace-all (*list-for-runtime* (call-yail-primitivestring-replace-all (*list-for-runtime* (call-yail-primitive string-replace-all (*list-for-runtime* (call-yail-primitive string-replace-all (*list-for-runtime* (call-yail-primitive string-replace-all (*list-for-runtime* (call-yail-primitive string-replace-all (*list-for-runtime* (call-yail-primitive string-replace-all (*list-for-runtime* (call-yail-primitive string-replace-all (*list-for-runtime* (call-yail-primitivestring-replace-all (*list-for-runtime* (call-yail-primitive string-replace-all (*list-for-runtime*(lexical-value $hexinput) "1" "") '(text text text) "replace all") "2" "") '(text text text) "replace all")"3" "") '(text text text) "replace all") "4" "") '(text text text) "replace all") "5" "") '(text text text) "replace all") "6" "") '(text text text) "replace all") "7" "") '(text text text) "replace all") "8" "") '(text text text) "replace all") "9" "") '(text text text) "replace all") "0" "") '(text text text)"replace all") "A" "") '(text text text) "replace all") "B" "") '(text text text) "replace all") "C" "")'(text text text) "replace all") "D" "") '(text text text) "replace all") "E" "") '(text text text) "replace all") "F" "") '(text text text) "replace all")) '(text) "length")) '(any any) "=") "HEX" "NOT HEX") 'text) )
--
You need to look at the Kawa documentaion:
--
I have now worked it out and am validating binary decimal and hex inputs
Almost done. Unit tesing next
--
댓글 없음:
댓글 쓰기