I am playing around with mobiaccess framework, but i am stuck when i try to cast an Object to Integer.
Is it possible to cast in mobiaccess?
I tried to below code but it does not work:
var i:Integer = (Integer) objectClass;
You can use the square bracket "[]" like this:
var i:Integer = [Integer] objectClass;
Related
I having a trouble with a code in MAYA 2020.
I want to create a new expression into a default value of a Arnold aiUserDataInt
I need the default value of a aiUserDataInt = attribute from a geometry that I crate name "ID"
so, my code looks like this:
string $Selected[] = `ls -selection`;
for ($node in $Selected)
aiUserDataInt1.default = $Selected.id;
but I have these error:
// Error: Line 2.37: Cannot cast data of type string[] to float. //
So, I suppose default value do not accept arrays
my question would be: is there a way to convert array into float?
or what am I doing wrong?
Thanks in advance
Unfortunately that's not how mel works. You can do:
string $Selected[] = `ls -selection`;
for ($node in $Selected)
{
int $id = getAttr($node + ".id");
setAttr("aiUserDataInt1.default", $id);
}
Didn't test it, but it should work like this. You get and set attributes with getAttr() and setAttr().
I have an Array of [Long, Q] and would like to make a binary search on it. I tried below :
import scala.collection.Searching._
class Q (val b:Double, val a:Double)
val myArray = Array(5L -> new Q(1,2), 6L-> new Q(6,9), 7L-> new Q(7,6))
val i = myArray.search(6L).insertionPoint
but had this error
No implicit Ordering defined for Any
Unspecified value parameter ord.
I understand that I need to specify an odering rule for this collection Array[(Long,Q)] but can't figure this out myself.
Please help
Signature of search is search[B >: A](elem: B)(implicit ord: Ordering[B]). You've got an array of type [Long, Q]. So in order for the compiler to infer Ordering correctly, you'd have to invoke search like that:
myArray.search(6L-> q/*Q(6,9)*/)(Ordering.by(_._1)) //ordering by the first value in a tuple.
and what you're doing is: myArray.search(6L). If I understand correctly what you're trying to do, it's probably to find both value and position in the array.
You could solve it by using two separate data structures:
keys could be stored in the array, like this:
val myArray = Array(5L, 6L, 7L).toList
myArray.search(6L).insertionPoint
and if you'd need values, you could use map which would work as a dictionary:
val dictionary = Map(
5L -> new Q(1,2),
6L-> new Q(6,9),
7L-> new Q(7,6)
)
EDIT:
Actually, I noticed something like that would work:
val dummy = new Q(0,0) //any instance of Q
myArray.search(6L-> dummy)(Ordering.by(_._1)).insertionPoint //1
It works since for lookup of the insertion point Ordering is used and no equality test is performed.
I tried this but got error !!!!
var lable : UILabel = [lable1, lable2, lable3]
// do stuff with label
In Swift, variable declarations follow this pattern:
var variable name: type = expression
You are saying that the type is a UILabel, while assigning it a list of UILabels.
Use [UILabel] as your type to fix your issue.
Two issues:
The type is UILabel (typo)
An array is indicated with a pair or square brackets []
However the compiler can infer the type (and the variable is most likely a constant)
let lables = [lable1, lable2, lable3]
if you want mutable :
var labels = [xyz1, xyz2, xyz2]
and if you want immutable
let labels = [xyz1, xyz2, xyz3]
Trying to get query results into an array. The example from the documentation shows this working...
let statement = try db.prepare(query)
var results = Array(statement)
...however when I try to compile this I get...
Ambiguous use of 'init'
... for the Array(statement)
If I change to this...
let statement = try db.prepare(query)
var results = Array<SQLite.Row>(statement)
I get this error...
Type of expression is ambiguous without more context
What can I do to make this work?
You need to iterate through the rows to put them into an array:
for statement in try db.prepare(query) {
yourArray.append(statement)
}
i get this error on:
cell.naamItem = VragenInformatie[indexPath.section][indexPath.row][0]
i have this in the same class:
var VragenInformatie: [[[String]]] = [[[]]]
and this is how the array looks like:
var VragenInformatie: [[[String]]] = [[["Spelletjeskamer",""],["Keuken",""],["Garage",""],["Binnenplaats",""],["Zitkamer",""],["Slaapkamer",""],["Studeerkamer",""],["Eetkamer",""],["Badkamer",""]],[["De Wit",""],["Pimpel",""],["Blaauw van Draet",""],["Roodhart",""],["Groenewoud",""],["Van Geelen",""]],[["Loden pijp",""],["Pistool",""],["Engelse sleutel",""],["Dolk",""],["Touw",""],["Kandelaar",""]]]
i don't really no what the problem is here neither do i know what subscript really means
could someone give some advise?
I bet your naamItem is a UILabel or something like that, and you forgot to append the '.text'. If my theory is true, your code should look something like this:
cell.naamItem.text = VragenInformatie[indexPath.section][indexPath.row][0]
In any other case where the naamItem is NOT an UILabel, UITextView or UITextField, you should make sure the naamItem is of type String.