Page 1 of 1

Mouse click script

PostPosted: Thu Sep 29, 2011 4:15 am
by David long
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.

Re: Mouse click script

PostPosted: Mon Oct 03, 2011 4:28 am
by Mystery
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.

Re: Mouse click script

PostPosted: Sun Jul 15, 2012 7:23 pm
by jason595
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?

Re: Mouse click script

PostPosted: Sun Jul 15, 2012 9:21 pm
by electronicboy
That script would be pasted into the console! :)

Re: Mouse click script

PostPosted: Sun Jul 22, 2012 6:04 am
by Xray
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!

Re: Mouse click script

PostPosted: Sun Jul 22, 2012 1:38 pm
by electronicboy
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).

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.

Re: Mouse click script

PostPosted: Sun Jul 22, 2012 3:48 pm
by Xray
electronicboy - Thanks for that information. You were very helpful. :thumbup:

Re: Mouse click script

PostPosted: Tue Jul 24, 2012 10:13 pm
by Benjii
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 ( :angel: ) but i've been trying to figure out these issues for days now and i'm getting frustrated!! Please help!

Re: Mouse click script

PostPosted: Tue Jul 24, 2012 10:23 pm
by Xray
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.

Re: Mouse click script

PostPosted: Wed Jul 25, 2012 9:08 am
by Benjii
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!

Re: Mouse click script

PostPosted: Wed Jul 25, 2012 4:40 pm
by TC42
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.
Rating: rated 5
Filesize: 16.91 kB
Comments: 4
Ratings: 1
download

Re: Mouse click script

PostPosted: Wed Jul 25, 2012 4:54 pm
by Xray
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!

Re: Mouse click script

PostPosted: Wed Jul 25, 2012 10:27 pm
by Benjii
Same for me, (remember with me you're talking to someone with a negative IQ :crazy: ) I don't really understand how and where to use that script. Thanks though. :thumbup:

Re: Mouse click script

PostPosted: Wed Jul 25, 2012 10:53 pm
by TC42
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:
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.

Re: Mouse click script

PostPosted: Wed Jul 25, 2012 11:49 pm
by Xray
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.

Re: Mouse click script

PostPosted: Thu Jul 26, 2012 9:10 am
by Benjii
Thanks, that helps a lot! :thumbup:

Re: Mouse click script

PostPosted: Thu Jul 26, 2012 12:56 pm
by Ivan
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.

Re: Mouse click script

PostPosted: Thu Jul 26, 2012 4:46 pm
by TC42
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.

Re: Mouse click script

PostPosted: Thu Jul 26, 2012 4:47 pm
by Xray
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! :clap:

Re: Mouse click script

PostPosted: Thu Jul 26, 2012 4:52 pm
by Xray
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!

Re: Mouse click script

PostPosted: Thu Jul 26, 2012 7:02 pm
by electronicboy
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.

Re: Mouse click script

PostPosted: Thu Jul 26, 2012 10:14 pm
by Xray
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!