Problem with an 'if/then statement
4 posts • Page 1 of 1
Problem with an 'if/then statement
Hi,
I want to increment a count of all circles with texture "nickel.png" that collide with a box. Only random circles have that texture. Here is what I have done which doesn't work:
I set a variable scene.my.nickelcount = 0 in the console
I created a box and set onCollide (e)=>e.other.texture = "nickel.png? {scene.my.nickelcount = scene.my.nickelcount + 1}: {}
I created a box with text set to {scene.my.nickelcount}
Thyme rejects the onCollide code above.
Any help would be appreciated.
EEIEEIO
Dave
I want to increment a count of all circles with texture "nickel.png" that collide with a box. Only random circles have that texture. Here is what I have done which doesn't work:
I set a variable scene.my.nickelcount = 0 in the console
I created a box and set onCollide (e)=>e.other.texture = "nickel.png? {scene.my.nickelcount = scene.my.nickelcount + 1}: {}
I created a box with text set to {scene.my.nickelcount}
Thyme rejects the onCollide code above.
Any help would be appreciated.
EEIEEIO
Dave
- eeieeio
- Posts: 25
- Joined: Thu Nov 30, 2017 7:02 pm
Re: Problem with an 'if/then statement
Should be:
And I must warn you - there could be multiple collisions and onCollide calls per one coin so you might need to handle this.
- Code: Select all
onCollide = (e) => {e.other.texture == "nickel.png" ? {scene.my.nickelcount = scene.my.nickelcount + 1} : {}}
And I must warn you - there could be multiple collisions and onCollide calls per one coin so you might need to handle this.
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: Problem with an 'if/then statement
eeieeio -- It appears that you are not using "=" (equal sign) correctly. Here are examples of its usage in scripts:
Use "=" by itself in order to store something into a variable. "something" can be a numeric value, it can be a Boolean operator (such as true or false), or it can be "text". The right side of the equation gets stored into the left side. For example: scene.my.var = 3.14, or scene.my.var = false, or scene.my.var = "This is text".
Use "==" for testing a variable in order to check its value, and to make a decision based on the result of that test. For example:
scene.my.var == 3.14 ? {scene.my.var = 0}:{scene.my.var = scene.my.var * 2} ; In this example, you are testing the variable named "scene.my.var" to determine if the value stored in it is 3.14. If the value IS 3.14, then set scene.my.var to 0. If scene.my.var is NOT 3.14, then multiply the value in that variable times 2.
Here is a List of Tutorials which you will find helpful.
The code in the previous comment by kilinich is an example of a script that should work for what you are trying to do.
Let us know if you have any other questions....
Xray
Use "=" by itself in order to store something into a variable. "something" can be a numeric value, it can be a Boolean operator (such as true or false), or it can be "text". The right side of the equation gets stored into the left side. For example: scene.my.var = 3.14, or scene.my.var = false, or scene.my.var = "This is text".
Use "==" for testing a variable in order to check its value, and to make a decision based on the result of that test. For example:
scene.my.var == 3.14 ? {scene.my.var = 0}:{scene.my.var = scene.my.var * 2} ; In this example, you are testing the variable named "scene.my.var" to determine if the value stored in it is 3.14. If the value IS 3.14, then set scene.my.var to 0. If scene.my.var is NOT 3.14, then multiply the value in that variable times 2.
Here is a List of Tutorials which you will find helpful.
The code in the previous comment by kilinich is an example of a script that should work for what you are trying to do.
Let us know if you have any other questions....
Xray
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Problem with an 'if/then statement
Thank you Xray, that helped a lot
- eeieeio
- Posts: 25
- Joined: Thu Nov 30, 2017 7:02 pm
4 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 15 guests