Mouse click script
22 posts • Page 1 of 1
Mouse click script
Can you help me?
I need a simple mouse click script.
I need to figure out how to turn on a motor with a mouse click on a object.
I need a simple mouse click script.
I need to figure out how to turn on a motor with a mouse click on a object.
I'm 300% awesome
- David long
- Posts: 3
- Joined: Sat Sep 17, 2011 1:54 am
Re: Mouse click script
- Code: Select all
Scene.addLaserPen {
geom := 0;
relPoint := [-0.20744929, 0.19884428];
velocity := +inf;
fadeDist := 0.1;
maxRays := 1;
cutter := false;
opaqueBorders := true;
showLaserBodyAttrib := true;
size := 0.1;
collideSet := 127;
collideWater := true;
color := [1.0, 1.0, 1.0, 2.0];
activationButton := "mouse_left"
}
That will spawn a laser that activates with a left mouse click.
-
Mystery - Posts: 2802
- Joined: Thu Sep 03, 2009 1:16 pm
- Location: Southern Australia
Re: Mouse click script
Being new to Algodoo scripting, do I just copy and paste that code into console or do I have to add it to a shape script?
- jason595
- Posts: 2
- Joined: Sun Jul 15, 2012 6:03 pm
Re: Mouse click script
That script would be pasted into the console!
When asking for help, READ THE STICKIES!
- electronicboy
- Posts: 1694
- Joined: Mon Aug 31, 2009 6:18 pm
Re: Mouse click script
I'm not a Thyme "expert", but it seems to me that the really important line in that script is "activationButton := "mouse_left"" So, would I be able to stick that line into any script that generates a geometry (such as addbox or addcircle), and have it be activated by clicking the left mouse button?
Thanks!
Thanks!
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Mouse click script
The ActivateButton, control is only used on lasers.
so, if the code is spawning a laser, you could add that line to the part of the code that is used to spawn a laser, otherwise it will have no effect!
ActivateButton has no effect on Geometry, hinges/axels (see below).
Hint; you can copy objects out of algodoo and into Notepad++ (Windows notepad may have issues showing the text).
This will show you all the variables you can play with when spawning a particular type of objekt.
so, if the code is spawning a laser, you could add that line to the part of the code that is used to spawn a laser, otherwise it will have no effect!
ActivateButton has no effect on Geometry, hinges/axels (see below).
- Code: Select all
Scene.addHinge {
buttonForward := "right";
buttonBack := "left";
};
Hint; you can copy objects out of algodoo and into Notepad++ (Windows notepad may have issues showing the text).
This will show you all the variables you can play with when spawning a particular type of objekt.
When asking for help, READ THE STICKIES!
- electronicboy
- Posts: 1694
- Joined: Mon Aug 31, 2009 6:18 pm
Re: Mouse click script
electronicboy - Thanks for that information. You were very helpful.
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Mouse click script
I know this isn't all to do with the mouse click but I think it relates to this topic.
1. How (if it's possible) do you make something change colour when the mouse is over it (not necessarily to change colour but maybe to change the collision layer or the attraction)?
2. How do you add more variables(not sure if that's what they are called but i mean the boxes where you enter values or scripts when you open up the 'script menu' window e.g. onCollide or onLaserHit) for example when the mouse is over or on mouse click so i could enter scripts that would apply to those 'variables'.
Sorry if i've gone a little off subject ( ) but i've been trying to figure out these issues for days now and i'm getting frustrated!! Please help!
1. How (if it's possible) do you make something change colour when the mouse is over it (not necessarily to change colour but maybe to change the collision layer or the attraction)?
2. How do you add more variables(not sure if that's what they are called but i mean the boxes where you enter values or scripts when you open up the 'script menu' window e.g. onCollide or onLaserHit) for example when the mouse is over or on mouse click so i could enter scripts that would apply to those 'variables'.
Sorry if i've gone a little off subject ( ) but i've been trying to figure out these issues for days now and i'm getting frustrated!! Please help!
Si hoc legere scis numium eruditionis habes.
-
Benjii - Posts: 42
- Joined: Sun Apr 08, 2012 11:43 am
- Location: Peak District, UK
Re: Mouse click script
Hi Benjii - The BEST person to ask about Thyme scripts (in my opinion) is Kilinich. He does some amazing things with scripts, and you can click on his user name anywhere in this forum to see the hundreds of amazing scenes that he has created using Thyme scripts. Some of them are quite complex and would probably require his explanations of how they work, so you may need to PM him. I learned a lot from his scenes.
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Mouse click script
I know Kilinich is a genius and i have already subscribed to him, although saying that i haven't gone into great detail dissecting his scenes. Still, if anyone who can help me is browsing this forum pleeease help me!
Si hoc legere scis numium eruditionis habes.
-
Benjii - Posts: 42
- Joined: Sun Apr 08, 2012 11:43 am
- Location: Peak District, UK
Re: Mouse click script
Benjii wrote:I know this isn't all to do with the mouse click but I think it relates to this topic.
1. How (if it's possible) do you make something change colour when the mouse is over it (not necessarily to change colour but maybe to change the collision layer or the attraction)?
Easy. You know the position or the box, the size of the box, and the position of the mouse, right?
Therefore, in pseudo-code:
- Code: Select all
if (app.mousepos < box right edge && app.mousepos > box left edge) {
if (app.mousepos < box top edge && app.mousepos > box bottom edge) {
//put code here!
}
}
It is all based on coordinates, and would _probably_ change depending on which quadrant you are using. This scene has some of the actual functions.
-
TC42 - Posts: 984
- Joined: Sun Jan 09, 2011 1:53 pm
- Location: $ sudo apt get-install sandwich_
Re: Mouse click script
TC42 - I downloaded your sample scene "Oncollides as functions", and I'm sure that these scripts would be very handy to use, but you gave no verbal explanation as to how to use each of those scripts. I see a box, a ball, and a list of scripts, and no clue how to use any of them! I have a basic understanding of Thyme, and I understnad pseudocode because of my prior programming experience, but I am not able to figure out what those scripts are supposed to do. A little verbiage explaining each would be very helpful!
Thanks!
Thanks!
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Mouse click script
Same for me, (remember with me you're talking to someone with a negative IQ ) I don't really understand how and where to use that script. Thanks though.
Si hoc legere scis numium eruditionis habes.
-
Benjii - Posts: 42
- Joined: Sun Apr 08, 2012 11:43 am
- Location: Peak District, UK
Re: Mouse click script
Using oncollides as functions really only applies to people like Kilinich, who frequently use phunlets and might need to have phunlet-friendly functions.
I don't really remember how exactly oncollide-functions work, but I think you call the functions with 'e.geom.oncollide" in a laser colliding with a geom containing a function in the oncollide. Currently, I'm buried underneath several tons of C and NXT-G, so my thyme might be a little rusty.
So I would recommend you stay away from functions stored in oncollides or onhitbylaser for now, and use console-based functions instead. You enter functions into the console similarly to the way you enter scene.my variables, except you must include any inputs that the function will use. So if you want a function that adds two numbers, the code will be:
Or you could go functionless and simply put that code into an oncollide or onhitbylaser. The benefit of functions is that you only have to write out a simply tag to reuse code rather than having to write out the entire block of text again.
The functions in the scene _should_ output true/false depending on whether or not the mouse is inside the shape. Since algodoo is coordinate-based, this will depend on how the shape described on a coord plane.
So, on a coord plane, a circle would be described as a locus of points that are all a given distance from a center point. To check if the mouse is within a circle, we could simply figure out whether the mouse is within a given distance of the center point. That is what the is ispointincircle function does.
I don't really remember how exactly oncollide-functions work, but I think you call the functions with 'e.geom.oncollide" in a laser colliding with a geom containing a function in the oncollide. Currently, I'm buried underneath several tons of C and NXT-G, so my thyme might be a little rusty.
So I would recommend you stay away from functions stored in oncollides or onhitbylaser for now, and use console-based functions instead. You enter functions into the console similarly to the way you enter scene.my variables, except you must include any inputs that the function will use. So if you want a function that adds two numbers, the code will be:
- Code: Select all
Scene.my.addnum = (x, y) => {
Answer := x + y;
Answer;
};
Or you could go functionless and simply put that code into an oncollide or onhitbylaser. The benefit of functions is that you only have to write out a simply tag to reuse code rather than having to write out the entire block of text again.
The functions in the scene _should_ output true/false depending on whether or not the mouse is inside the shape. Since algodoo is coordinate-based, this will depend on how the shape described on a coord plane.
So, on a coord plane, a circle would be described as a locus of points that are all a given distance from a center point. To check if the mouse is within a circle, we could simply figure out whether the mouse is within a given distance of the center point. That is what the is ispointincircle function does.
-
TC42 - Posts: 984
- Joined: Sun Jan 09, 2011 1:53 pm
- Location: $ sudo apt get-install sandwich_
Re: Mouse click script
TC42 wrote:So I would recommend you stay away from functions stored in oncollides or onhitbylaser for now, and use console-based functions instead. You enter functions into the console similarly to the way you enter scene.my variables, except you must include any inputs that the function will use.
If someone were to write a scene using concole functions that they call from oncollides, how can another person view how those functions were written? It seems that if I wanted to reverse-engineer someone else's scene, when I open my console, I see a list of system messages, but no user functions. Where are those functions stored, and how can I view/copy them?
Thanks
EDIT: I originally quoted the wrong text from TC42. I corrected the quote (as seen above) with the text that I had intended.
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Mouse click script
Xray wrote:If someone were to write a scene using concole functions that they call from oncollides, how can another person view how those functions were written? It seems that if I wanted to reverse-engineer someone else's scene, when I open my console, I see a list of system messages, but no user functions. Where are those functions stored, and how can I view/copy them?
If you want to see these functions, you have to open the .phz (scene file) with an archiver. You can do that because .phz-s are actually .zip archives. So, when you open it, you will see a scene.phn file, checksums.txt and images used by the scene. Then extract the .phn file and open it with a text editor. In that file you can find all variables and functions stored in the scene.
-
Ivan - Posts: 202
- Joined: Tue Oct 06, 2009 2:01 pm
- Location: Croatia
Re: Mouse click script
Or if you know how the function is called in the oncollide, for example 'scene.my.function1(0, 3, 5)', you simply need to type the name of the function into the console, which in this case would be 'scene.my.function1'. Then the console _should_ show the function.
-
TC42 - Posts: 984
- Joined: Sun Jan 09, 2011 1:53 pm
- Location: $ sudo apt get-install sandwich_
Re: Mouse click script
TC42 wrote:Or if you know how the function is called in the oncollide, for example 'scene.my.function1(0, 3, 5)', you simply need to type the name of the function into the console, which in this case would be 'scene.my.function1'. Then the console _should_ show the function.
That's what I needed to know! THANKS!
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Mouse click script
Ivan wrote:If you want to see these functions, you have to open the .phz (scene file) with an archiver. You can do that because .phz-s are actually .zip archives. So, when you open it, you will see a scene.phn file, checksums.txt and images used by the scene. Then extract the .phn file and open it with a text editor. In that file you can find all variables and functions stored in the scene.
I sort of knew that but I had trouble trying to open ".PHZ" files because Windows did not know how to handle that file extension. Do you think that ANY archiver program would be able to open that file type, or is there a particular archiver that I would need to find and download? THANKS!
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Mouse click script
Xray wrote:Ivan wrote:If you want to see these functions, you have to open the .phz (scene file) with an archiver. You can do that because .phz-s are actually .zip archives. So, when you open it, you will see a scene.phn file, checksums.txt and images used by the scene. Then extract the .phn file and open it with a text editor. In that file you can find all variables and functions stored in the scene.
I sort of knew that but I had trouble trying to open ".PHZ" files because Windows did not know how to handle that file extension. Do you think that ANY archiver program would be able to open that file type, or is there a particular archiver that I would need to find and download? THANKS!
.PHZ files are just .ZIP files
In explorer, Go (you may have to press ALT on windows vista/7), tools --> Folder options --> View --> "Hide file extensions for known file types. (Please note; this sequence is rougthly translated, my computer is in swedish, translation SHOULD be accurate).
Then, find the .PHZ file, and rename it to end with .zip .
I would suggest Installing Notepad++ for use as a text editor, as it also allows you to right click on the .phn files, with the selection to open the file.
When asking for help, READ THE STICKIES!
- electronicboy
- Posts: 1694
- Joined: Mon Aug 31, 2009 6:18 pm
Re: Mouse click script
Electronicboy - I tried your suggestion of renaming the PHZ files to ZIP files, and then extracting them, and that worked perfectly! When I'm finished extracting the file, I then just highlight the entire filename and press Ctrl-Z which changes the filename extension back to its original type without having to actually retype it!
Thanks much!
Thanks much!
-
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 9 guests