Skip to content
Forum Archive

Buttons in AVS

10 posts

Warrior of the Light#

Buttons in AVS

It's questionable if this belongs in the presets subforum or in the AVS forum, but I didn't start this thread only about the preset, but more about the functionality.

A lot of people have already worked this out, but here's my way of doing this:

You don't want the button to flip per frame when you hold the mouse button for multiple frames, what would happen if you would simply use button=getkbmouse(3); I solved this by generating a pulse when the mouse-button is pressed.

This pulse normally would only trigger the button for 1 frame. You want it to switch per pulse. Here's how I solved it all (button is reg02).


xm=getkbmouse(1);
ym=getkbmouse(2);
rm=getkbmouse(3);
mc=if(below(xm,-.9)&above(xm,-1)&above(ym,.9)&below(ym,1)&rm,1,0);
mcpulse=if(equal(mcold,mcnew),0,if(equal(mcold,0),1,0));
mcold=var;
var=if(equal(mc,0),mcpulse,1);
mcnew=var;
mcswitch=if(mcpulse,bnot(mcswitch),mcswitch);
reg02=mcswitch;
Example preset is attached (will most likely be in my new pack).
The button appears when you move the mouse over the left and bottom of the preset ( xpos < -0.9 or ypos < 0.9 ) Click it and the preset changes. Also explained in the comment.
UnConeD#
Your method is waaaaaay too complicated (not to mention such a thing has been posted before).

Pulse:

old=new;new=getkbmouse(3);pulse=band(new,bnot(old));

Then just check the x/y coordinates and and with pulse:
if(band(pulse,...), /* do mouse click */ ,0);
S-uper_T-oast#
UnConeD got it.
I am kicking aorund an idea like that for a prest library GUI type fux0red thing, it would be nice if it worked.
Warrior of the Light#
%@#$!!! just when I think I've worked someting out... 😠

Nevermind...

By the way, why is band() faster than & ? Aren't funtions slower than operators in this case (pulse) ? 😕

[edit]
Am I the only one who likes the altered preset or am I the only one? None of my friends seem to like it... 😢
[/edit]
Tuggummi#
Hmm, doesn't & do something else? The explanation on the help is hard to understand for me tho 😕

But band would be * too in occasions, band(1,1)=1 and 1*1=1 Just as long as they are numbers and the values are 1 precisely.
Don't know what is the fastest way though 😛

[edit]
The altered preset is nicer with low fps, but with high fps it tends to flicker too much.
[/edit]
TomyLobo#
band() is boolean AND
& is bitwise AND

the C representation of band(x, y) should be something like
(((x == 0) || (y==0))? 0 : 1)

x & y is probably
(double)(((int)x)&((int)y))

band() is 2 floating point comparisons and a boolean OR,
whereas & is 3 type conversions and a bitwise AND
guess which one is faster 😉
Warrior of the Light#
I know what they do 😔 i was talking about my case, but this makes it more clear... thanks
DynamicMovement#
UnConeD's method has benefits & disadvantages:

For writing DM it has functionality, but, when I want to code other parts I have same problems.
UnConeD#
Comparing functions with operators in AVS makes no sense: the scripting language is way too high level to be able to decide what goes on on the assembly level.

Get the WA5 SDK and look in the nseel dir, nseel-cfunc.c. Then come back and discuss speed issues 🙄 .