OnMouseDown, moho.layer, and other topics

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
Peteroid
Posts: 162
Joined: Thu Aug 12, 2010 3:57 am
Location: las vegas, NV
Contact:

OnMouseDown, moho.layer, and other topics

Post by Peteroid »

I beleive it is a common practice to use OnMouseDown as the routine to the functionality into. At least many scripts seem to have this function right under the title "the guts of the script".

Since I can't see anything going on, I use a technique a called 'sound debugging'. I place a 'beep' at locations in the code. If I hear the beep I know it got there, if not... well let's talk about that...

I went into a provided script, Track Layer, and put a Beep in its OnMouseDown. I never hear it. So, either this code isn't ever executed, or during a mouse interrupt one can't use Beep (which I could understand, sound is very interrupt driven itself).

If this is true so much for my 'sound debugging'. Because if I follow the way I see it done (since i have no way of knowing if it can be done another way), I must put my code in OnMouseDown to get a valid 'moho' object... which if I'm right means no beep will ever be heard when in my code.

So my question is... is this the case? OnMouseDown is being called, I just can't hear it with Beep?

NEXT

I noticed these routines in some scripts:

moho.document:PrepMultiUndo()
moho.document:SetDirty()

Does this make it so it becomes part of the UnDo/Redo mechanism (if so, very cool!)? And does SetDirty tell this mechanism a change will be made soon (so it can save a copy first)?

NEXT

By placing my code in DoLayout (as a way of testing it since I can see it IS getting there since it changes the toolbar)... I get a valid 'moho', which I pass to my routine for getting info.

But, I tried mimicking what I saw in other scripts, and use moho.layer for the current layer.

Although it lets me create this, it is always nil for me in my code. At first I tried moho.fLayer, but it too is always nil.

I make sure there is a selected Layer, and I assume what is meant by 'current layer' IS the layer the end-user last selected. I can only assume this.

Well that's my latest batch of hurdles to jump over.... thanks for any help in advance! :)
[==Peter==]
User avatar
DK
Posts: 2849
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Hi Peteroid.
Just wanted to say I am fascinated reading your posts. Although I can't help you on the Lua I am getting a great insight into it thanks to you.

Cheers
D.K
ponysmasher
Posts: 370
Joined: Thu Aug 05, 2004 2:23 am
Location: Los Angeles
Contact:

Post by ponysmasher »

Instead of using a beep you can print some stuff to the lua console whenever something happens. Like this:

Code: Select all

print("This is what will be printed")
You can also print variables so you can see their value:

Code: Select all

print(ThisIsAvariable) 
If you want to print multiple strings/variables put two periods between each thing:

Code: Select all

print("This is text"..aVariable.."More text")
And yes, prepundo/prepmultiundo makes it part of the undo function.

Set dirty will tell the document that stuff has changed without being saved. You know when you make changes in a document, an asterisk appears by the name in the title bar to let you know that you haven't saved the latest changes. That whole thing.

Man, it can be really hard to explain technical things in english when it's not your first language...
ponysmasher
Posts: 370
Joined: Thu Aug 05, 2004 2:23 am
Location: Los Angeles
Contact:

Post by ponysmasher »

You know, not to be a dick or anything but if you didn't know about the print function you should probably read some lua tutorials and familiarize yourself with the language before attempting to understand moho scripting.

In those tutorials the first thing you do is the whole "hello world" thing that uses the print function.

Just a helpful tip.
User avatar
Peteroid
Posts: 162
Joined: Thu Aug 12, 2010 3:57 am
Location: las vegas, NV
Contact:

Post by Peteroid »

ponysmasher wrote:You know, not to be a dick or anything but if you didn't know about the print function you should probably read some lua tutorials and familiarize yourself with the language before attempting to understand moho scripting.

In those tutorials the first thing you do is the whole "hello world" thing that uses the print function.

Just a helpful tip.
To be fair, I'm having no problem with the LUA language... all my 'problems' involve the MOHO.GUI interface (and those problems are just because I'm still learning about MOHO, and the doco for that is sparse and at times inaccurate).

I wrote the pure LUA portion in a few hours. It is very close to the computer language C, and I've been programming in C for 20+ years. That also has been a slight hindrance, since anyplace the two languages differ I tend to do the C way till I'm corrected. This is legal, but not the norm, but I still put semi-colons to delineate lines (this it has to be done in C, is optional in LUA). I do this because if I ever want to lift LUA code and make a C version I don't have to put a semi-colon after each statement... easier to do this incrementally as one composes the code than have to do it all at once.

And, in fact, to get the LUA code the tool I'm working, I first wrote it in C, tested it, then made a LUA version of it. So it can go both ways...

I just didn't know about this 'print' function in LUA. That is good to know! Thanks! I assume if the LUA console is not already up, this evokes it? Up to now I've dreaded the LUA console when it came up, since whenever it did it meant a problem in my script. I will be nice to evoke it for the side of 'good' rather than the side of 'evil'... hehe

Finally... LUA Tutorials? WHERE? :)
[==Peter==]
Post Reply