Put comments in the scripts
I discovered that it is possible to easily metre comments in scripts with a notation that was not documented:
#{here I can put any text}#;
var y := year('Start date');
var m := month('Start date');
#{here again}#;
var d := day('Start date');
var t := for i from 0 to days('Start date', 'End date' + 1) do
{
year: year(date(y, m, d + i)),
month: month(date(y, m, d + i)),
day: day(date(y, m, d + i));
#{
*********** and I can use it to remove temporary one part of
my code to try another think *********
year: year(date(y, m, d + i)),
month: month(date(y, m, d + i)),
day: day(date(y, m, d + i))
********************************************************************************}#;
#{ --- usually, you could use quotation marks to transform a part
of the code into a comment. The defect is that it was not
possible to put in comment a string of character string.
With this new notation, any type of code can be commented ---
var s := " one string in comment ";
-------------------------------------------------------}#
}
end;
for y in unique(t.year) do
for m in unique(t[year = y].month) do
format(date(number(y), number(m), 1), "YYYY MM : ") + count(t[year = y and month = m]) + " days
"
end
end;
#{
The only flaw of this is that now we have
no excuse not to comment our code
}#
put #{ to begin comment block and finish by }#.
...
To be honest, I have to tell you that this is not a comment notation. It was intended to be used to put JavaScript code in Ninox Script, but it was never implemented. I found out that this notation has been there for at least a year (maybe since the beginning?)
If you don't want to use it to put comments, and you want to use it to write JavaScript, you have to initialize two functions with a simple code on the formula. This formula must be executed once after opening the database :
html("
<script>
queries.JS.prototype._compileSyncJS = function(e) {return `( () => {${this.code} } )()`}
queries.JS.prototype._compileAsyncJS = function(e) {return `(function(cb){cb(( () => {${this.code}})())})`}
</script>
")
Then you can use the JavaScript code anywhere in your Ninox script. For example, put this code behind a button and press it :
var r := #{return window.prompt("Let my know your name", "nobody")}#;
alert("hello " + r)
In line 1, the variable r is initialized with the result of the JavaScript prompt function which asks the user for a value.
On line 2, the result of the input is displayed using the alert function of Ninox.
18 replies
-
Jacques TUR said:
#{
The only flaw of this is that now we have
no excuse not to comment our code
}#Jacques does it again! Now I'm going to have to comment my code. Though I wonder if Ninox will implement the JavaScript feature in the future and then what will happen to our new comment code? Will Ninox try to run our comments and of course error out? Will Ninox report that all of our code with comments are now full of errors?
-
Jacques TUR
When I try the window.prompt code snippet, the prompt window doesn't display and r is null. I'm using the Mac version.
-
I continued to explore the use of #{}# to insert JavaScrip in Ninox. The results are here.
-
Here is how I have added comments a few times.
If anyone sees a reason this could be an issue I would appreciate the feedback. If there are no issues I also see this as a way to avoid Ninox changes as noted in earlier posts.
basically I use the Let command with TEXT identifier as follows. The only thing i have found so far is the last line cannot be a comment or i get void.
Format is as follows:
let z:=text(“…………..”);
I put whatever i want in place of the ……………
in the following example I was playing around with some code options and needed to comment some lines out and did this and it worked as far as commenting out the lines.
let z := text("let h := PlayersHandle.Handle;");
let z := text("let d := ((select Rounds where Players.Handle = h) order by today() - 'Date Played');");
let z := text("let c := cnt(d);");
let z := text("let e := (slice(d, min(0, c - 20), 20) order by Differential);");
let z := text("slice(e, min(0, 1), 8)");
select Rounds
Content aside
-
5
Likes
- 1 mth agoLast active
- 18Replies
- 1149Views
-
8
Following