EntityBygeomId(id) = dead?

About advanced scenes, and the Thyme scripting language used in Algodoo.

EntityBygeomId(id) = dead?

Postby FRA32 » Mon Dec 21, 2015 8:11 pm

To enhance some AI code of DugRel's drones even further, I need to counter an annoying issue which basically turns my drones off:

If the drone has the ID of an target, but the target is dead and it doesnt know what to do anymore...

I need a 100% garuanteed way of making the drone notice if it can't find an entity by that ID anymore, or that the entity is out of range(which is the easy part that I already know). If they try to get the position of an non-existend object, they just fly around, shooting into thin air, without beeing able to rotate to any known enemy
FRA32
 
Posts: 229
Joined: Wed Dec 03, 2014 9:51 pm

Re: EntityBygeomId(id) = dead?

Postby T'wind_ » Mon Dec 21, 2015 9:01 pm

This code works but it will throw an error in the console each time you execute it. :?
Code: Select all
scene.entityBygeomId(id) ? {} : {
<code here>
}
User avatar
T'wind_
 
Posts: 86
Joined: Wed Jul 08, 2015 5:33 pm
Location: Western Europe

Re: EntityBygeomId(id) = dead?

Postby Kilinich » Mon Dec 21, 2015 10:01 pm

I think more elegant way is to tell target notify drone of it's death)
For example put some onDie code in it from turret code with call back.
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: EntityBygeomId(id) = dead?

Postby FRA32 » Tue Dec 22, 2015 12:29 am

The problem is that the drones do a 1-way-data-transmission, meaning that 1 drone owns the id of the other, but the other may not own the id of the first drone.

Also, I didnt know scene.entitybygeomid returns a boolean. Gotta try it out
FRA32
 
Posts: 229
Joined: Wed Dec 03, 2014 9:51 pm

Re: EntityBygeomId(id) = dead?

Postby T'wind_ » Tue Dec 22, 2015 9:22 am

FRA32 wrote:The problem is that the drones do a 1-way-data-transmission, meaning that 1 drone owns the id of the other, but the other may not own the id of the first drone.

Also, I didnt know scene.entitybygeomid returns a boolean. Gotta try it out

scene.entityBygeomid doesn't return a boolean, it can't be used in boolean operations.
User avatar
T'wind_
 
Posts: 86
Joined: Wed Jul 08, 2015 5:33 pm
Location: Western Europe

Re: EntityBygeomId(id) = dead?

Postby FRA32 » Tue Dec 22, 2015 1:16 pm

If it doesnt return a boolean, why can you use it in an if statement then?

<boolean> ? {C1} : {C2}

scene.entitybygeomid(id) ? {} : {<discard id>}
FRA32
 
Posts: 229
Joined: Wed Dec 03, 2014 9:51 pm

Re: EntityBygeomId(id) = dead?

Postby electronicboy » Tue Dec 22, 2015 2:35 pm

It will return an object, I've not tried this nor can I comment on the accuracy of what I say, but I think it's one of those if the if condition returns null/nothing it will be considered false, but if it returns something it will be seen as true. The magic of computers is that sometimes you can get them to do crazy stuff.
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: EntityBygeomId(id) = dead?

Postby T'wind_ » Tue Dec 22, 2015 5:55 pm

If it returns nothing it will be considered false, but if it returns something and if it's not a boolean it won't be seen as true, nothing will happen.
User avatar
T'wind_
 
Posts: 86
Joined: Wed Jul 08, 2015 5:33 pm
Location: Western Europe

Re: EntityBygeomId(id) = dead?

Postby Kilinich » Tue Dec 22, 2015 10:00 pm

Here it is a safe way:

Code: Select all
scene.my.entityExists = (ID) => {
  {probe := Scene.entityByID(ID); probe} != undefined
}
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: EntityBygeomId(id) = dead?

Postby T'wind_ » Wed Dec 23, 2015 12:13 am

Kilinich wrote:
Code: Select all
scene.my.entityExists = (ID) => {
  {probe := Scene.entityByID(ID); probe} != undefined
}


That's a more legit way to do it, but it still fills the console with errors.
User avatar
T'wind_
 
Posts: 86
Joined: Wed Jul 08, 2015 5:33 pm
Location: Western Europe

Re: EntityBygeomId(id) = dead?

Postby FRA32 » Wed Dec 23, 2015 6:28 pm

So, in short: If the reference is undefined then return false?

This is actually somehow the way I tried it, but the code seems to skip something, causing it to malfunciton. Yet thanks for the answers, since now I own a garuantee that it works.
FRA32
 
Posts: 229
Joined: Wed Dec 03, 2014 9:51 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 9 guests