Mouse click script

Post your tutorials here.

Mouse click script

Postby David long » Thu Sep 29, 2011 4:15 am

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'm 300% awesome
David long
 
Posts: 3
Joined: Sat Sep 17, 2011 1:54 am

Re: Mouse click script

Postby Mystery » Mon Oct 03, 2011 4:28 am

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.
User avatar
Mystery
 
Posts: 2802
Joined: Thu Sep 03, 2009 1:16 pm
Location: Southern Australia

Re: Mouse click script

Postby jason595 » Sun Jul 15, 2012 7:23 pm

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

Postby electronicboy » Sun Jul 15, 2012 9:21 pm

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

Postby Xray » Sun Jul 22, 2012 6:04 am

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!
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Mouse click script

Postby electronicboy » Sun Jul 22, 2012 1:38 pm

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.
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: Mouse click script

Postby Xray » Sun Jul 22, 2012 3:48 pm

electronicboy - Thanks for that information. You were very helpful. :thumbup:
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Mouse click script

Postby Benjii » Tue Jul 24, 2012 10:13 pm

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!
Si hoc legere scis numium eruditionis habes.
User avatar
Benjii
 
Posts: 42
Joined: Sun Apr 08, 2012 11:43 am
Location: Peak District, UK

Re: Mouse click script

Postby Xray » Tue Jul 24, 2012 10:23 pm

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.
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Mouse click script

Postby Benjii » Wed Jul 25, 2012 9:08 am

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.
User avatar
Benjii
 
Posts: 42
Joined: Sun Apr 08, 2012 11:43 am
Location: Peak District, UK

Re: Mouse click script

Postby TC42 » Wed Jul 25, 2012 4:40 pm

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
Image
Spambot wrote:Nowadays, memes usually are studied less in the field of biology, but more with the arena of psychology along with sociology. But, the major area of a meme, getting embraced and imitated all the time is what’s at any core connected with any meme.
User avatar
TC42
 
Posts: 984
Joined: Sun Jan 09, 2011 1:53 pm
Location: $ sudo apt get-install sandwich_

Re: Mouse click script

Postby Xray » Wed Jul 25, 2012 4:54 pm

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!
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Mouse click script

Postby Benjii » Wed Jul 25, 2012 10:27 pm

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:
Si hoc legere scis numium eruditionis habes.
User avatar
Benjii
 
Posts: 42
Joined: Sun Apr 08, 2012 11:43 am
Location: Peak District, UK

Re: Mouse click script

Postby TC42 » Wed Jul 25, 2012 10:53 pm

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.
Image
Spambot wrote:Nowadays, memes usually are studied less in the field of biology, but more with the arena of psychology along with sociology. But, the major area of a meme, getting embraced and imitated all the time is what’s at any core connected with any meme.
User avatar
TC42
 
Posts: 984
Joined: Sun Jan 09, 2011 1:53 pm
Location: $ sudo apt get-install sandwich_

Re: Mouse click script

Postby Xray » Wed Jul 25, 2012 11:49 pm

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.
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Mouse click script

Postby Benjii » Thu Jul 26, 2012 9:10 am

Thanks, that helps a lot! :thumbup:
Si hoc legere scis numium eruditionis habes.
User avatar
Benjii
 
Posts: 42
Joined: Sun Apr 08, 2012 11:43 am
Location: Peak District, UK

Re: Mouse click script

Postby Ivan » Thu Jul 26, 2012 12:56 pm

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.
Image
User avatar
Ivan
 
Posts: 202
Joined: Tue Oct 06, 2009 2:01 pm
Location: Croatia

Re: Mouse click script

Postby TC42 » Thu Jul 26, 2012 4:46 pm

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.
Image
Spambot wrote:Nowadays, memes usually are studied less in the field of biology, but more with the arena of psychology along with sociology. But, the major area of a meme, getting embraced and imitated all the time is what’s at any core connected with any meme.
User avatar
TC42
 
Posts: 984
Joined: Sun Jan 09, 2011 1:53 pm
Location: $ sudo apt get-install sandwich_

Re: Mouse click script

Postby Xray » Thu Jul 26, 2012 4:47 pm

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:
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Mouse click script

Postby Xray » Thu Jul 26, 2012 4:52 pm

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!
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Mouse click script

Postby electronicboy » Thu Jul 26, 2012 7:02 pm

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

Postby Xray » Thu Jul 26, 2012 10:14 pm

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!
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests