[Closed] Updating value on mouse move
Hello !
I am quite new with maxscript, and get some big trouble with the max help, most of the time if I ever find what I am looking for there is symply no exemple to show me how to use it…
So here I am !
I’d like to update a certain variable with the pos of my mouse, lets say only on the x axes for now.
For this I have thinking evaluating a first time the pos of my mouse every 1 second
then every 2 and substract the two to get a value I could use… only I have not a clue how to proceed for this second part…
Here’s where I am stuck curently :
rollout test “Test Timer”
(
timer clock “testClock” interval: 1000 –tick once a second
label test”1″
on clock tick do
(
valUp = (test.text as integer)+1
test.text = valUp as string
mousePos = mouse.screenPos
print mousePos
)
timer clock2 “testClock2” interval: 2000 –tick once a second
label test2″2″
on clock2 tick do
(
valUp = (test2.text as integer)+2
test2.text = valUp as string
mousePos2 = mouse.screenPos
print mousePos2
)
)
createDialog test
I am looking first on how isolated the x pos of my two clock and then making a difference of it… every two seconds in my exemple ( I will increase the speed once its working…). Then I will use this difference for updating another variable.
Of cours I dont find my happiness in the maxscript help… if someone could give me at least a hint it would be much appreciated.
Thanks !
Blobynator
Hey,
you’ve been quite close, you only forgot to declare a local variable on the top of the function, that store the position of the state earlier. In your example your “mousePos” variables only live during the execution of each-clock event. So you cannot get their value after the code for that event has been executed.
You also don’t need two timers, one with modulo is enough.
Here is the code:
rollout test "Test Timer"
(
local mousePos -- add this if you want a mouse position from the very start local mousePos = mouse.screenPos
timer clock "testClock" interval: 1000 --tick once a second
label test "1"
label test2 "2"
on clock tick do -- you don't need two timers, you can use modulo to test for every even and odd second
(
if (mod clock.ticks 2) == 1 then -- for every odd second
(
test.text = ((test.text as integer) + 1) as string
mousePos = mouse.screenPos -- store the current position to the local variable mousePos (at the top of this block)
)
else -- for every even
(
test2.text = ((test2.text as integer) + 1) as string
if mousePos != undefined then -- if the mousePos has been initialized (there was at least 1 tick)
(
print (mousePos - mouse.screenPos) -- get the mouse.Screenpos at this state and subtract it from the state one second earlier
)
)
)
)
createDialog test
By the way, the MaxScript Help might be a bit huge and frustrating at the beginning, but it helps a lot, besides that, cgtalk is always a good resource to look for code examples.
-k.
Hi ! Thanks Kogen : ) Yeah, I have figured that out a bit after the same day, but since it was my first post on this forum it took a few days before this message apears so couldn’t edit !
For the maxscript help well… it looks more like a listing of functions than a true help to me. I mean , there is really not enought exemples…every functions should have an exemple of its aplication just bellow… I don’t count how many time I have find what I was looking for but have need to look for exemple on google or other scripts only for understand how to use the function !!
I mean for exemple : http://docs.unity3d.com/Documentation/ScriptReference/Application-dataPath.html
This is already a lot more clear. I don’t really find that normal to need an help just for reading an help… having exemples in a help seems the minimum to me or its not a help, just an index.
And I know I am really far to be the only one to think that about this help, actually most people I know who have used max script also complaint about it so I know the problem with this help don’t come only from me . It often easier to type what you need in google and browse the result than actually use the official max script help that’s a shame !
Thanks for your help anyway