onCollide of killer item?

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

onCollide of killer item?

Postby spook1 » Wed Sep 16, 2009 5:06 pm

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
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?

Postby Sniperkasa » Wed Sep 16, 2009 6:08 pm

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..
If you have a question, have a dollar and call somebody that cares.
No really just PM me if you have a problem :)
User avatar
Sniperkasa
 
Posts: 493
Joined: Tue Sep 01, 2009 5:34 pm
Location: The bottom of a lake.

Re: onCollide of killer item?

Postby spook1 » Wed Sep 16, 2009 11:23 pm

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?
spook1
 
Posts: 20
Joined: Thu Sep 10, 2009 12:06 am

Re: onCollide of killer item?

Postby Versieon » Wed Sep 16, 2009 11:34 pm

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!!
User avatar
Versieon
 
Posts: 375
Joined: Tue Sep 01, 2009 4:45 pm

Re: onCollide of killer item?

Postby Ian151 » Thu Sep 17, 2009 12:41 am

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
"THE BEST 2 PLAYER SCENE EVER MADE!!!" - ianno
http://www.algodoo.com/algobox/details.php?id=24204
Image
User avatar
Ian151
 
Posts: 47
Joined: Tue Sep 01, 2009 12:02 am

Re: onCollide of killer item?

Postby spook1 » Sat Oct 10, 2009 3:44 pm

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....
spook1
 
Posts: 20
Joined: Thu Sep 10, 2009 12:06 am

Re: onCollide of killer item?

Postby Versieon » Sat Oct 10, 2009 4:34 pm

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.
User avatar
Versieon
 
Posts: 375
Joined: Tue Sep 01, 2009 4:45 pm

Re: onCollide of killer item?

Postby Rhett97 » Sat Oct 10, 2009 10:23 pm

Idk if this is your problem but i figured ut that...

(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.
User avatar
Rhett97
 
Posts: 522
Joined: Mon Aug 31, 2009 10:32 pm

Re: onCollide of killer item?

Postby spook1 » Sat Oct 10, 2009 11:55 pm

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)
spook1
 
Posts: 20
Joined: Thu Sep 10, 2009 12:06 am

Re: onCollide of killer item?

Postby Versieon » Sun Oct 11, 2009 12:02 am

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.
User avatar
Versieon
 
Posts: 375
Joined: Tue Sep 01, 2009 4:45 pm

Re: onCollide of killer item?

Postby spook1 » Sun Oct 11, 2009 8:57 am

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
spook1
 
Posts: 20
Joined: Thu Sep 10, 2009 12:06 am

Re: onCollide of killer item?

Postby gradyfitz » Sun Oct 11, 2009 2:00 pm

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
Mechanisms: 18 Mechanisms.
Thyme: Tutorial - Variables/Commands List.
Thymechanic
gradyfitz
 
Posts: 174
Joined: Tue Sep 01, 2009 8:33 am
Location: Victoria, Australia

Re: onCollide of killer item?

Postby spook1 » Sun Oct 11, 2009 6:40 pm

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
spook1
 
Posts: 20
Joined: Thu Sep 10, 2009 12:06 am

Re: onCollide of killer item?

Postby Versieon » Sun Oct 11, 2009 7:08 pm

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.
User avatar
Versieon
 
Posts: 375
Joined: Tue Sep 01, 2009 4:45 pm

Re: onCollide of killer item?

Postby spook1 » Sun Oct 11, 2009 10:05 pm

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
spook1
 
Posts: 20
Joined: Thu Sep 10, 2009 12:06 am

Re: onCollide of killer item?

Postby Ian151 » Sun Oct 11, 2009 10:29 pm

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.
"THE BEST 2 PLAYER SCENE EVER MADE!!!" - ianno
http://www.algodoo.com/algobox/details.php?id=24204
Image
User avatar
Ian151
 
Posts: 47
Joined: Tue Sep 01, 2009 12:02 am

Re: onCollide of killer item?

Postby spook1 » Sun Oct 11, 2009 10:47 pm

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
spook1
 
Posts: 20
Joined: Thu Sep 10, 2009 12:06 am

Re: onCollide of killer item?

Postby Versieon » Mon Oct 12, 2009 4:18 am

Here, I can't explain it well enough with just words.

Rating: rated 5
Filesize: 9.33 kB
Comments: 0
Ratings: 1
download
User avatar
Versieon
 
Posts: 375
Joined: Tue Sep 01, 2009 4:45 pm

Re: onCollide of killer item?

Postby spook1 » Mon Oct 12, 2009 10:26 am

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
spook1
 
Posts: 20
Joined: Thu Sep 10, 2009 12:06 am


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 3 guests

cron