Page 1 of 1

onCollide of killer item?

PostPosted: Wed Sep 16, 2009 5:06 pm
by spook1
I have a killer item, and every time it hits a "victim" item I want to add a point to the total score.

In the F11 screen I state:
Code: Select all
Scene.my.score=0



I have a score box, stating:

Code: Select all
text  {"Score =" + Scene.my.score + " points"}


The victim items has the script:

Code: Select all
(e)=>{Scene.my.score =Scene.my.score+1}


This seems not to work, when I place the script (e)=>{Scene.my.score =Scene.my.score+1} in the killer object the score goes skyhigh because it bounces a lot of Immortal items as well.

Question: How can I detect a collision when my script-item is killed?

Thansk in advance for youtr intersst in my littel problem

Martijn

Re: onCollide of killer item?

PostPosted: Wed Sep 16, 2009 6:08 pm
by Sniperkasa
You could use an if statement..
{e.other.(an state, ex. friction) == (how much) ? {if its true, do this}: {if not, do this};
no ( )' s are typed in.
example = {e.other.density == 2 ? {e.other.liquify} : {e.other.color = [1.0,0.0,0.0,1.0]}}
That will liquify any object with the density 2, and make the color to red if it is'nt density 2.
Hope it helps..

Re: onCollide of killer item?

PostPosted: Wed Sep 16, 2009 11:23 pm
by spook1
Sorry, I do not understand.

can I ask in the if-statement something lik:

Code: Select all
if e.other.killed : scenem.my.score = scene.my.score +1?

Re: onCollide of killer item?

PostPosted: Wed Sep 16, 2009 11:34 pm
by Versieon
what he is saying is that you cant have the code in the killed object because it won't execute, so instead have it in the killer. The way to make it not add on a lot of points for every time the killer hits something that isn't killable is to have all the killable objects have, for example, a certain controllerAcc value, say 5. Then, use an if statement to say if controllerAcc is 5, kill that object and add one to score, if its not 5, as all the non killable objects would be, don't do anything

Code: Select all
{e.other.controllerAcc == 5} ? {e.other.density = NaN; scene.my.score = scene.my.score + 1} : {}


then just set all the killable objects to have a controllerAcc of 5!!

Re: onCollide of killer item?

PostPosted: Thu Sep 17, 2009 12:41 am
by Ian151
yep he is right and in that case you wouldn't even need the killer to be considered a killer because as long as it matches or fits the variable inside the object, like Controlleracc, then it will work. If you don't know how if statements work in thyme, look here too.

http://www.algodoo.com/forum/viewtopic.php?f=13&t=411

Re: onCollide of killer item?

PostPosted: Sat Oct 10, 2009 3:44 pm
by spook1
OK, so I understand tyhat I can create a code to kill another object, if it has a certain value.

Can I add a property to the instances I want to make killable?
Could I add a boolean property .KillableWall to an object and state something like:

E.g.: {e.other.KillableWall == True} ? {e.other.density = NaN; scene.my.score = scene.my.score + 1} : {}

To make the wall disappear when it is hit?

In the example above you stae: controllerAcc == 5, this is the acceleration right? My walls do not accelerate....

Re: onCollide of killer item?

PostPosted: Sat Oct 10, 2009 4:34 pm
by Versieon
You can add a property to the other geom, just like you said.

And controllerAcc is not acceleration, it is how fast something would accelerate if you were using the geometry controller. As i assume you are not useing that, the value in controllerAcc can be used as a placeholder for a number, like 5, and then you can use that number for your own purposes.

Re: onCollide of killer item?

PostPosted: Sat Oct 10, 2009 10:23 pm
by Rhett97
Idk if this is your problem but i figured ut that...

(e)=<{Scene.my.Scrore = 0;Scene.my.Score +1} that might work idk

Re: onCollide of killer item?

PostPosted: Sat Oct 10, 2009 11:55 pm
by spook1
Thanks for informing me about the acc use as placeholder.

I am also interested in adding a property.
What does this cryptic sentence mean: "You can add a property to the other geom"?

I intend to check if a certain level was completed, and then add one to the level property and amke appropriate changes in teh scene (e.g. turn off gravity, add air friction etc)

Re: onCollide of killer item?

PostPosted: Sun Oct 11, 2009 12:02 am
by Versieon
spook1 wrote:What does this cryptic sentence mean: "You can add a property to the other geom"?

What i ment is you had it right when you said how to add a property to another object. All you have to do is say "e.other.property = 1" and when it collides with something, it will create the variable "property" in the other object, and set it to 1.

Re: onCollide of killer item?

PostPosted: Sun Oct 11, 2009 8:57 am
by spook1
OK, I see.
Thanks a lot for this Just In Time crash course of thyme scripting.
I learn all the basiscs that are not in the tutorials I found.

In the wall object, I selected script menu and added on the empty line below: KillableWall =0
So I added the property KillableWall.

In the onCollide method I added:
(e)=>{e.other.KillableWall == true} ? {e.other.density = NaN} : {}}

somehow this is changed by Algodoo into an expression I typed as my first trial.( I cannot save another expression anymore obviously..):

(e)=>{if({e.other.KillableWall = true})(?)({e.other.desity = 0})}

and that does not work...the .KillableWall object does not disappear...

can you give me one last hint?

Regards

martijn

Re: onCollide of killer item?

PostPosted: Sun Oct 11, 2009 2:00 pm
by gradyfitz
spook1 wrote:OK, I see.
Thanks a lot for this Just In Time crash course of thyme scripting.
I learn all the basiscs that are not in the tutorials I found.

In the wall object, I selected script menu and added on the empty line below: KillableWall =0
So I added the property KillableWall.

In the onCollide method I added:
(e)=>{e.other.KillableWall == true} ? {e.other.density = NaN} : {}}

somehow this is changed by Algodoo into an expression I typed as my first trial.( I cannot save another expression anymore obviously..):

(e)=>{if({e.other.KillableWall = true})(?)({e.other.desity = 0})}

and that does not work...the .KillableWall object does not disappear...

can you give me one last hint?

Regards

martijn

Something a very large number of people seem to do, is place <variable> == true, the thyme parser does not like this, this behaviour involves more computation than required as well, if <variable> is a boolean value (true/false), then it can be places directly into a statement (like Scene.my.BooleanVariable1 ? {print("true")} : {print(false}), if you want the opposite value (if true, then false, if false, then true), place an exclamation mark ("!") before the name of the variable.

As for whether object deletes or not, try e.other.density = NaN, and if it doesn't work, try e.other.density = 0, remember, the if structure works like this T/F Value ? if true : if false, it is an infixed operation, so you don't need any preceding identifier.

Hopefully this helps :D.
/Grady

Re: onCollide of killer item?

PostPosted: Sun Oct 11, 2009 6:40 pm
by spook1
thanks again for your elaborate answer.

I placed in the onCollide method: (e)=>{{e.other.Killable} ? {e.other.density = NaN} : {}}
in the "killer".

The wall has property Killable = true

Now when the ball bounces the wall twice, the second time the ball disappears..??

I cannot understand this thyme... :-(

Can anyone reflect on this strange behaviour?

Martijn

Re: onCollide of killer item?

PostPosted: Sun Oct 11, 2009 7:08 pm
by Versieon
I personaly, don't like boolean variables. Heres what i would put, and it should work.
(e)=>{{e.other.Killable == 1} ? {e.other.density = 0} : {}}
then put Killable = 1 in the wall.
This is just a fake boolean
Seems like algodoo dosn't like booleans very much, I've had other problems with the scipts not working correctly with boolean variables.

Re: onCollide of killer item?

PostPosted: Sun Oct 11, 2009 10:05 pm
by spook1
I am beginning to think I am making a very basic mistake here. the code does not result in a wall disappearing after the ball bouncing it.
The property killable appears in the list after I type it in the bottom input field. but after saving and opening the file it has disappeard.
Whe I remove the killable==1 part, still the other object is not removed after density =0 or NaN...
Do I have to make other killer / immortal settings?

Maybe you could see my mistake quickly in the original (4 kB file) at: http://www.drkoops.nl/killable_test.phz

Again, thank you for your ongoing interest in my questions,

Martijn

Re: onCollide of killer item?

PostPosted: Sun Oct 11, 2009 10:29 pm
by Ian151
Yeah, that always happens to me. What I did was I used Controlleracc as a variable.
If you want to make a new variable that can be saved within, then all you have is the variables within the object already, or you make something collide with the object right away. If you script something to collide with the object that you want to add a property to, THEN you can keep the variable. In this case, you have to create the variables with a collision the instant you start the simulation.

So

Code: Select all
(e)=>{e.other.killable = 1}


And you would put that in the object that will collide with the wall, or whatever you want that will be deleted on an appropriate collision.

That is my only guess... I don't know how else you would do this at the moment, other than using if statements to ask about what the properties are, so that you can perform an action.

Re: onCollide of killer item?

PostPosted: Sun Oct 11, 2009 10:47 pm
by spook1
If I underastdn you right, I should just use the killer option then.
if I am to set the property the moment I collide, means that the property killable is being set to everything I collide with.
There I loose the essential idea of "killable".

other idea's?

martijn

Re: onCollide of killer item?

PostPosted: Mon Oct 12, 2009 4:18 am
by Versieon
Here, I can't explain it well enough with just words.

Rating: rated 5
Filesize: 9.33 kB
Comments: 0
Ratings: 1
download

Re: onCollide of killer item?

PostPosted: Mon Oct 12, 2009 10:26 am
by spook1
Wow, this works great.
Thanks a lot.
Apparently i was stubborn in trying to get .killable to work.
I will build my game around this.

thanks angain,

martijn