onCollide of killer item?
19 posts • Page 1 of 1
onCollide of killer item?
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:
I have a score box, stating:
The victim items has the script:
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
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
Last edited by spook1 on Sat Oct 10, 2009 11:52 pm, edited 1 time in total.
- spook1
- Posts: 20
- Joined: Thu Sep 10, 2009 12:06 am
Re: onCollide of killer item?
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..
{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..
If you have a question, have a dollar and call somebody that cares.
No really just PM me if you have a problem
No really just PM me if you have a problem
-
Sniperkasa - Posts: 493
- Joined: Tue Sep 01, 2009 5:34 pm
- Location: The bottom of a lake.
Re: onCollide of killer item?
Sorry, I do not understand.
can I ask in the if-statement something lik:
can I ask in the if-statement something lik:
- Code: Select all
if e.other.killed : scenem.my.score = scene.my.score +1?
- spook1
- Posts: 20
- Joined: Thu Sep 10, 2009 12:06 am
Re: onCollide of killer item?
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
then just set all the killable objects to have a controllerAcc of 5!!
- 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!!
-
Versieon - Posts: 375
- Joined: Tue Sep 01, 2009 4:45 pm
Re: onCollide of killer item?
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
http://www.algodoo.com/forum/viewtopic.php?f=13&t=411
-
Ian151 - Posts: 47
- Joined: Tue Sep 01, 2009 12:02 am
Re: onCollide of killer item?
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....
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....
- spook1
- Posts: 20
- Joined: Thu Sep 10, 2009 12:06 am
Re: onCollide of killer item?
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.
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.
-
Versieon - Posts: 375
- Joined: Tue Sep 01, 2009 4:45 pm
Re: onCollide of killer item?
Idk if this is your problem but i figured ut that...
(e)=<{Scene.my.Scrore = 0;Scene.my.Score +1} that might work idk
(e)=<{Scene.my.Scrore = 0;Scene.my.Score +1} that might work idk
Chronos wrote:There's nothing wrong with swearing. They're just words. People just think they have a bad meaning. What's the difference between shit and poo? Nothing. They're the same.
-
Rhett97 - Posts: 522
- Joined: Mon Aug 31, 2009 10:32 pm
Re: onCollide of killer item?
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)
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)
- spook1
- Posts: 20
- Joined: Thu Sep 10, 2009 12:06 am
Re: onCollide of killer item?
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.
-
Versieon - Posts: 375
- Joined: Tue Sep 01, 2009 4:45 pm
Re: onCollide of killer item?
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
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
- spook1
- Posts: 20
- Joined: Thu Sep 10, 2009 12:06 am
Re: onCollide of killer item?
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 .
/Grady
- gradyfitz
- Posts: 174
- Joined: Tue Sep 01, 2009 8:33 am
- Location: Victoria, Australia
Re: onCollide of killer item?
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
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
- spook1
- Posts: 20
- Joined: Thu Sep 10, 2009 12:06 am
Re: onCollide of killer item?
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.
(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.
-
Versieon - Posts: 375
- Joined: Tue Sep 01, 2009 4:45 pm
Re: onCollide of killer item?
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
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
- spook1
- Posts: 20
- Joined: Thu Sep 10, 2009 12:06 am
Re: onCollide of killer item?
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
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.
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.
-
Ian151 - Posts: 47
- Joined: Tue Sep 01, 2009 12:02 am
Re: onCollide of killer item?
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
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
- spook1
- Posts: 20
- Joined: Thu Sep 10, 2009 12:06 am
Re: onCollide of killer item?
Here, I can't explain it well enough with just words.
-
Versieon - Posts: 375
- Joined: Tue Sep 01, 2009 4:45 pm
Re: onCollide of killer item?
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
Thanks a lot.
Apparently i was stubborn in trying to get .killable to work.
I will build my game around this.
thanks angain,
martijn
- spook1
- Posts: 20
- Joined: Thu Sep 10, 2009 12:06 am
19 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 2 guests