How can i create a float array on LL?
How can i create a float array on LL?
I know, it’s the stupidest question i ever made here… But I can’t find out a way!
I tried different classic java syntaxes, but it always shows up “Syntax Error”
]]>« A little bit update for official scripts [script_change_homescreen] (Previous Post)
(Next Post) Hey guys lightning launcher is THE BEST! »
< ![CDATA[
You can do something like that :
var tab = [0.5, 1.5, 2.5, 3.75];
alert(“tab length = ” + tab.length); // show 4
alert(tab[2]); //show 2.5
]]>
< ![CDATA[
Benoît de Chezelles I’ll try
]]>
< ![CDATA[
ok it seems to work, but i need a blank array for my purposes (HSV)
]]>
< ![CDATA[
Lukas Morawietz , TrianguloY ?
]]>
< ![CDATA[
Simone Boccuzzi its JavaScript not Java. var arr = new Array(); or var arr = []; should work fine. You can then add values with arr.push(value);.
]]>
< ![CDATA[
James Coyle oh, it’s right xD
I tried and your method works well, but i have another little problem:
I must use a blank float array with lenght 3
so i used this: new Array(3);
but it is not defined as float so it doesn’t work with the method colorToHSV(color, float array).
How can i do?
]]>
< ![CDATA[
Maybe just : var arr = [ 0.0, 0.0, 0.0 ];
(didn’t tried)
]]>
< ![CDATA[
Benoît de Chezelles i already tried, but it must be a blank float array
]]>
< ![CDATA[
Simone Boccuzzi That isn’t possible AFAIK. Do you have a link to the documentation of that method?
]]>
< ![CDATA[
Simone Boccuzzi I tried any research possible, & I didn’t found any possible way to do this with our javascript’s java wrapper…
]]>
< 
]]>
< ![CDATA[
There is a way. Lukas Morawietz asked it and Pierre Hébert provided the solution.
Unfortunately it was long time ago and don’t have the time to search for it, sorry.
You need to create a java array binding its class and
using ‘new’]]>
< ![CDATA[
TrianguloY I tried to search for a way via a new array, etc, like you say, but I didn’t found anything..
]]>
< ![CDATA[
(16-october-2014 Lukas post)
Didn’t tested, but try this:
LL.bindClass(“java.lang.reflect.Array”);
LL.bindClass(“java.lang.Float”);
var a = Array.newInstance(Float.TYPE, 5);//5 is the length of the array
]]>
< 
Yesterday I was so afflicted that I tried to do something crazy…
I completely revamped the “colorToHSV()” android method to make it works perfectly with LL java wrapper (finally my math skills have been useful).
I think I will share it later here by the way. (maybe)
TrianguloY I tried your way and it works the same, I guess that someone have to put this on script.api to avoid future problem like this one.
I thank you all for your patience!!
]]>
< ![CDATA[
Rhino is pretty intelligent with choosing the correct method. But an empty javascript Array has no type, so it is impossible to detect the correct method. You have to tell it which method to use:
Color[“HSVToColor(float[])”](new Array(3));
]]>
< ![CDATA[
Lukas Morawietz does this works???
]]>
< ![CDATA[
Yes.
]]>
< ![CDATA[
How? Why?
]]>
< ![CDATA[
What’s the difference with Color.HSVToColor(new Array(3));
]]>
< ![CDATA[
the difference is the “float[]”. It tells Rhino which specific method is targeted and as a result which conversion from javascript to Java should be used.
Color.HSVToColor(new Array(3)) ends up as the following java call : Color.HSVToColor(java.lang.Object[3]);
which is obviously not a legal call.
]]>
< ![CDATA[
Oooh thanks that’s great!
What’s Rhino? The java to javascript engine?
]]>
< ![CDATA[
Benoît de Chezelles
exactly.
]]>