Simple entityByName function
2 posts • Page 1 of 1
Simple entityByName function
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
};
Dream of Algodoo as game development engine...
-
Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Simple entityByName function
Hello,
Thank you for the post
"Simple entityByName function"
I'm sure it will be very helpful to me except for one thing. Step 2. For some reason when I try to add _name to the script menu of the entity, it does not appear in the list. This seams to be a recent problem. I have been able to add _name in the past, but not now. Any ideas why?
Dave
Thank you for the post
"Simple entityByName function"
I'm sure it will be very helpful to me except for one thing. Step 2. For some reason when I try to add _name to the script menu of the entity, it does not appear in the list. This seams to be a recent problem. I have been able to add _name in the past, but not now. Any ideas why?
Dave
- eeieeio
- Posts: 25
- Joined: Thu Nov 30, 2017 7:02 pm
2 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 4 guests