Writing and reading geometry variables
22 posts • Page 1 of 1
Writing and reading geometry variables
I have two separate questions, and would appreciate help for either or both.
1. For my first question, here is what I am trying to do: I want to spawn a circle from an OnCollide script, and have the color of the spawned circle be taken from an array element with contains the color. For example: {color=scene.my.colorarray(17)}. The array element 17 contains the value: [1,1,0,1] which colors the circle yellow. That script works just fine. But I want to arrive at the desired array element by calculating the element index. For example, if the result of my calculation is 17, and it is in the variable N, then I could set the circle color by: {color=scene.my.colorarray(N)}. That works Okay too, but it's not exactly what I want because the color of the circle will change each time N changes to a different value. What I want is to have the VALUE of N get placed into the script that sets the color. That is, I want to end up with: color=scene.my.colorarray(17)} so that the color of the spawned circle will change when I change that particular array element, and NOT the index, N. How can I tell Algodoo that I want the VALUE of N to be placed in the spawned script, rather than the name of the variable, N? I tried things like: {color=scene.my.colorarray(math.tostring(N))}, but that, and many other variations did not work.
2. My second question involves somehow sensing the color (or other attributes) of a geometry without having to use OnCollide. For example, I want to be able to slide a circle across my scene, and have it change to the colors of other objects that it happnes to be in contact with, but not in collision with. As I drag it around, I want it to be continuously sensing for other objects. If my circle is stopped over another object, and if the other object color changes, I want the color of the circle to immediately change to the other geometry without requiring a collision. Is this even possible?
THANKS!
1. For my first question, here is what I am trying to do: I want to spawn a circle from an OnCollide script, and have the color of the spawned circle be taken from an array element with contains the color. For example: {color=scene.my.colorarray(17)}. The array element 17 contains the value: [1,1,0,1] which colors the circle yellow. That script works just fine. But I want to arrive at the desired array element by calculating the element index. For example, if the result of my calculation is 17, and it is in the variable N, then I could set the circle color by: {color=scene.my.colorarray(N)}. That works Okay too, but it's not exactly what I want because the color of the circle will change each time N changes to a different value. What I want is to have the VALUE of N get placed into the script that sets the color. That is, I want to end up with: color=scene.my.colorarray(17)} so that the color of the spawned circle will change when I change that particular array element, and NOT the index, N. How can I tell Algodoo that I want the VALUE of N to be placed in the spawned script, rather than the name of the variable, N? I tried things like: {color=scene.my.colorarray(math.tostring(N))}, but that, and many other variations did not work.
2. My second question involves somehow sensing the color (or other attributes) of a geometry without having to use OnCollide. For example, I want to be able to slide a circle across my scene, and have it change to the colors of other objects that it happnes to be in contact with, but not in collision with. As I drag it around, I want it to be continuously sensing for other objects. If my circle is stopped over another object, and if the other object color changes, I want the color of the circle to immediately change to the other geometry without requiring a collision. Is this even possible?
THANKS!
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Writing and reading geometry variables
1. Your method works for me.
2.
For example, define "Scene.my.color" and set attraction = {Scene.my.color = owner.color; 0}.
Then, Scene.my.color will return the value of the geom color.
2.
For example, define "Scene.my.color" and set attraction = {Scene.my.color = owner.color; 0}.
Then, Scene.my.color will return the value of the geom color.
NOTE: I'm not an Algoryx member.
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
-
tatt61880 - [Most Helpful Person 2010]
- Posts: 1150
- Joined: Mon Aug 31, 2009 5:45 pm
- Location: Tokyo, Japan
Re: Writing and reading geometry variables
tatt61880 wrote:1. Your method works for me.
2.
For example, define "Scene.my.color" and set attraction = {Scene.my.color = owner.color; 0}.
Then, Scene.my.color will return the value of the geom color.
Tatt - Thanks very much for your reply (you have helped me many times in the past, and I appreciate it very much!) but you do not understand my question. In the OnCollide parameter of the circle to be spawned, you need to put curly brackets around the script so that the actual code gets written to the color parameter, like this: {Scene.my.colorarray(Scene.my.colorarrayIndex)}. This way, I could change the color of the array element, and the color of that particular circle will then change along with it. But I do not want the NAME of the index to be written to the script, but rather the VALUE of the index. That way, if the index value should change (which it will) then the color of the circle will not change because the script has a constant for the array index instead of a variable. Do you get it now? In other words, I want the script that's written to the spawned circle to be: {Scene.my.colorarray(21)}. I need some way to write the VALUE of the array index to that script so that the color can change when the array element changes, but NOT when the array index changes.
Concerning your answer number 2, you apparently do not understand that one either! I do not want the color of of the circle being dragged by me (owner) but rather the color of other geometries that the circle comes in contact with as it's moving across the screen. I want to do that without using OnCollide because I want to detect the color at any point along the surface of the geometry, and not only when it collides. Do you get it now?
Thanks again!
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Writing and reading geometry variables
1. For the first question, I have modified the onCollide in Tatt's scene a bit.
2. It should be possible. The underlying circles would have to send their positions and colors to an array and the circle that is flying over should test if it's within some radius to the center of any of these circles and change its color to the color of the circle that it is enough close to.
I might try to make something later.
2. It should be possible. The underlying circles would have to send their positions and colors to an array and the circle that is flying over should test if it's within some radius to the center of any of these circles and change its color to the color of the circle that it is enough close to.
I might try to make something later.
-
Ivan - Posts: 202
- Joined: Tue Oct 06, 2009 2:01 pm
- Location: Croatia
Re: Writing and reading geometry variables
Ivan wrote:1. For the first question, I have modified the onCollide in Tatt's scene a bit.
YES, THAT WORKS EXACTLY HOW I WANT IT TO!!! THANKS, IVAN!!
2. It should be possible. The underlying circles would have to send their positions and colors to an array and the circle that is flying over should test if it's within some radius to the center of any of these circles and change its color to the color of the circle that it is enough close to.
I might try to make something later.
Yes, that should work, but it sounds a little more complex than I was hoping it would be, and it's a little beyond my expertise with Thyme script, so I hope that you could find the time to write the script for me.
Thanks again!!
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Writing and reading geometry variables
I don't know if this is satisfying, but I made something that works and I will try to improve it tommorow if you or someone else like Tatt don't figure out something better.
Here it is. Just move the small circle around. If its center is within the radius of 1 meter from the center of a large circle, it will change its color respectively.
Here it is. Just move the small circle around. If its center is within the radius of 1 meter from the center of a large circle, it will change its color respectively.
- Attachments
-
- Color sensing.phz
- (18.47 KiB) Downloaded 46 times
-
Ivan - Posts: 202
- Joined: Tue Oct 06, 2009 2:01 pm
- Location: Croatia
Re: Writing and reading geometry variables
Xray wrote:but you do not understand my question.
That is because your question is incorrect.
{color=scene.my.colorarray(N)} isn't same with color={scene.my.colorarray(N)}
NOTE: I'm not an Algoryx member.
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
-
tatt61880 - [Most Helpful Person 2010]
- Posts: 1150
- Joined: Mon Aug 31, 2009 5:45 pm
- Location: Tokyo, Japan
Re: Writing and reading geometry variables
Ivan wrote:I don't know if this is satisfying, but I made something that works and I will try to improve it tommorow if you or someone else like Tatt don't figure out something better.
Here it is. Just move the small circle around. If its center is within the radius of 1 meter from the center of a large circle, it will change its color respectively.
Hey, that works pretty well! GOOD JOB! Now, I would like you to modify it just a bit so that the color changes back to some fixed base color (such as black) when the small circle moves OUT of the radius of the large circle. Also, I was wonding if it's possible to sense the color of the background, and have that become the base color? I will try to figure this stuff out myself, if you or other people do not have much time to devote to this. In other words, I don't expect people to do all of my work for me! I will learn much better if I have to try and figure things out for myself. And I could usually do that once I'm given the basics. You (and some other people) have helped me a great deal, and I appreciate it!
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Writing and reading geometry variables
tatt61880 wrote:Xray wrote:but you do not understand my question.
That is because your question is incorrect.
{color=scene.my.colorarray(N)} isn't same with color={scene.my.colorarray(N)}
Tatt - The thing that made Ivan's scene work is he created a local variable "_N" for each spawned circle which cannot be changed by global scripts. The only way to change the color of a specific spawned circle is to change the value of its associated array element in scene.my.colorarray. It works exactly as I need it to.
Thanks for your help!
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Writing and reading geometry variables
Ivan wrote:I don't know if this is satisfying, but I made something that works and I will try to improve it tommorow if you or someone else like Tatt don't figure out something better.
Here it is. Just move the small circle around. If its center is within the radius of 1 meter from the center of a large circle, it will change its color respectively.
Ivan - I made a slight mod to your scene so that the small circle senses the other circles at their radius, rather than at a fixed distance. I did this by saving the radius of each large circle in the array. The array elements for each circle now looks like this: scene.my.array = [color, pos, radius]. I figured this out by myself, and I'm pretty proud of myself right now!
The only issue with this mod is, it can only work with circles, which is Okay for my current purpose. I may mod it again later so that it will detect other geomitry shapes too.
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Writing and reading geometry variables
Here is an improved version of my scene without errors like "Stack overflow" and "List index out of bounds".
The circle now has background color if it's not close to any of the big circles. I'm pretty proud of myself right now too!
EDIT: corrected typo
The circle now has background color if it's not close to any of the big circles. I'm pretty proud of myself right now too!
EDIT: corrected typo
- Attachments
-
- Color sensing.phz
- (19.76 KiB) Downloaded 48 times
Last edited by Ivan on Mon Aug 13, 2012 9:08 pm, edited 1 time in total.
-
Ivan - Posts: 202
- Joined: Tue Oct 06, 2009 2:01 pm
- Location: Croatia
Re: Writing and reading geometry variables
Ivan wrote:Here is an improved version of my scene which has errors like "Stack overflow" and "List index out of bounds".
The circle now has background color if it's not close to any of the big circles. I'm pretty proud of myself right now too!
NICE JOB! That's just what I'm looking for! Now, I'll combine your mod with my mod, and I'll be able to sense the color of circles at their edges regardless of their size, and the sensing circle will switch back to the background color when it leaves the outside edges of the circles. PERFECT!
Thanks again! (We make a great team. )
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Writing and reading geometry variables
_N isn't needed if you used eval();
I don't know which is better.
I don't know which is better.
- Code: Select all
(e)=>{
eval(
@"
Scene.addBox({
color := { Scene.my.colorarray(" + Scene.my.N + @")};
pos := e.pos;
collideSet := 0;
});
");
}
NOTE: I'm not an Algoryx member.
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
-
tatt61880 - [Most Helpful Person 2010]
- Posts: 1150
- Joined: Mon Aug 31, 2009 5:45 pm
- Location: Tokyo, Japan
Re: Writing and reading geometry variables
tatt61880 wrote:_N isn't needed if you used eval();
I don't know which is better.
- Code: Select all
(e)=>{
eval(
@"
Scene.addBox({
color := { Scene.my.colorarray(" + Scene.my.N + @")};
pos := e.pos;
collideSet := 0;
});
");
}
Tatt - What does eval do? I found the definition in the Thyme commands and variables list, but all it says is, "evaluates a function", which doesn't explain how to use it. Could you please explain exactly what your script shown above does, and how it works?
Thanks very much!
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Writing and reading geometry variables
The oncollide is EVAL'd everytime the object collides with something.
Eval, essentially just means the code is run, if I remember correctly
Eval, essentially just means the code is run, if I remember correctly
When asking for help, READ THE STICKIES!
- electronicboy
- Posts: 1694
- Joined: Mon Aug 31, 2009 6:18 pm
Re: Writing and reading geometry variables
electronicboy wrote:The oncollide is EVAL'd everytime the object collides with something.
Eval, essentially just means the code is run, if I remember correctly
Huh? The script in OnCollide gets run every time the object collides with another object, so how is what you said any different?
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Writing and reading geometry variables
eval function is commonly used function, not only in Thyme but also in Perl, Python, Lisp, ....
So, just googling the word will help you.
By the way, I think you may don't know what @" " is about.
Just google "verbatim string literal" for that. This is C# style string literals that starts with @".
So, just googling the word will help you.
By the way, I think you may don't know what @" " is about.
Just google "verbatim string literal" for that. This is C# style string literals that starts with @".
README.txt wrote:=== Algodoo 2.0.0 RC1, 2011-09-23 ===
* NEW: Thyme: Added support for C# style string literals that starts with @" and ends with ".
NOTE: I'm not an Algoryx member.
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
-
tatt61880 - [Most Helpful Person 2010]
- Posts: 1150
- Joined: Mon Aug 31, 2009 5:45 pm
- Location: Tokyo, Japan
Re: Writing and reading geometry variables
Xray wrote:electronicboy wrote:The oncollide is EVAL'd everytime the object collides with something.
Eval, essentially just means the code is run, if I remember correctly
Huh? The script in OnCollide gets run every time the object collides with another object, so how is what you said any different?
In short, when the code is "evaluated", it is processed/ran.
EVAL'd = ran.
When asking for help, READ THE STICKIES!
- electronicboy
- Posts: 1694
- Joined: Mon Aug 31, 2009 6:18 pm
Re: Writing and reading geometry variables
I was googling and this is how I understand it.
eval() evaulates a string, i.e. it runs the code contained by the string. It seems to be very useful. Thanks Tatt!
And here I have found information about the string literal.
eval() evaulates a string, i.e. it runs the code contained by the string. It seems to be very useful. Thanks Tatt!
- Code: Select all
string := "2+3";
//input:
print(string);
print(eval(string));
//output:
2+3
5
And here I have found information about the string literal.
-
Ivan - Posts: 202
- Joined: Tue Oct 06, 2009 2:01 pm
- Location: Croatia
Re: Writing and reading geometry variables
tatt61880 wrote:By the way, I think you may don't know what @" " is about.
Just google "verbatim string literal" for that. This is C# style string literals that starts with @".README.txt wrote:=== Algodoo 2.0.0 RC1, 2011-09-23 ===
* NEW: Thyme: Added support for C# style string literals that starts with @" and ends with ".
tatt - I was reading over this thread and I was wondering where you got that "README.txt" file from? Is there documentation on-line somewhere that describes new additions to Thyme? If so, where can I find it?
Thanks!
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Writing and reading geometry variables
Xray wrote:tatt61880 wrote:By the way, I think you may don't know what @" " is about.
Just google "verbatim string literal" for that. This is C# style string literals that starts with @".README.txt wrote:=== Algodoo 2.0.0 RC1, 2011-09-23 ===
* NEW: Thyme: Added support for C# style string literals that starts with @" and ends with ".
tatt - I was reading over this thread and I was wondering where you got that "README.txt" file from? Is there documentation on-line somewhere that describes new additions to Thyme? If so, where can I find it?
Thanks!
C:\Program Files\Algodoo\README.txt
NOTE: I'm not an Algoryx member.
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
-
tatt61880 - [Most Helpful Person 2010]
- Posts: 1150
- Joined: Mon Aug 31, 2009 5:45 pm
- Location: Tokyo, Japan
Re: Writing and reading geometry variables
tatt61880 wrote:C:\Program Files\Algodoo\README.txt
I did not know that was there. THANKS!
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
22 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 7 guests