Simple entityByName function
Posted: Wed Dec 20, 2017 11:51 am
Hi, bros!
There are scene.entityByID and scene.entityByGeomID functions helps to access some object's but it's really complicated to use with not-linked via hinge or fixate objects.
So I write simple funtion scene.my.entityByName(name), and it's very easy to use:
1) Just copy code to console and press enter
2) add _name to any geom or entity and call scene.my.entityRegName(e.this) in onSpawn event.
3) use scene.my.entityByName(name) in any script!
There are scene.entityByID and scene.entityByGeomID functions helps to access some object's but it's really complicated to use with not-linked via hinge or fixate objects.
So I write simple funtion scene.my.entityByName(name), and it's very easy to use:
1) Just copy code to console and press enter
2) add _name to any geom or entity and call scene.my.entityRegName(e.this) in onSpawn event.
3) use scene.my.entityByName(name) in any script!
- Code: Select all
scene.my.xFor = (n1, n2, code) => {
n2 > n1 ? {
m := (n1 + n2) / 2;
scene.my.xFor(n1, m, code);
scene.my.xFor(m + 1, n2, code)
} : {code(n1)}
};
scene.my.entityList := [];
scene.my.entityRegName := (e) => {
string.length(scene.my.entityList) > 0 ? {
updated := false;
newList := [];
scene.my.xfor(0, string.length(scene.my.entityList)-1, (i)=>{
scene.my.entityList(i)(0) == e._name ? {
newList = newList ++ [[e._name, e.entityID]];
updated = true
}:{
newList = newList ++ [scene.my.entityList(i)]
}
});
updated ? {} : {newList = newList ++ [[e._name, e.entityID]]};
scene.my.entityList = newList
}:{scene.my.entityList = [[e._name, e.entityID]]};
};
scene.my.entityByName := (name) => {
string.length(scene.my.entityList) > 0 ? {
index := -1;
scene.my.xfor(0, string.length(scene.my.entityList)-1, (i)=>{
scene.my.entityList(i)(0) == name ? {index = i}:{}
});
index < 0 ? undefined : {scene.entityByID(scene.my.entityList(index)(1))}
} : undefined
};