Page 1 of 1
Execute function after some time
Posted: Fri Jan 22, 2016 11:14 pm
by croivo
What is the most simple way to execute function after few seconds?
Let's say something like this: send myFunction(parameter) in 2 seconds
Thank you.
Re: Execute function after some time
Posted: Sat Jan 23, 2016 12:05 am
by Simon
Hi croivo,
You are so very close!
Code: Select all
send "myFunction("& parameter &")" to me in 2 seconds
Simon
Re: Execute function after some time
Posted: Sat Jan 23, 2016 12:22 am
by croivo
I've tried this:
Code: Select all
on mouseUp
send "myFunction("& "Hello" &")" to me in 2 seconds
end mouseUp
function myFunction theText
answer theText
end myFunction
and that doesn't work...
Re: Execute function after some time
Posted: Sat Jan 23, 2016 12:39 am
by Simon
OK you got me.
I'm sure there a better way to do this but here is my Hack;
Code: Select all
on mouseUp
send timeFunction to me in 2 seconds
end mouseUp
on timeFunction
return myFunction(Hello)
end timeFunction
function myFunction theText
answer theText
end myFunction
Simon
Re: Execute function after some time
Posted: Sat Jan 23, 2016 2:15 am
by FredBeck
Hi!
That's because functions need to be GOT
You need either to :
send "get myFunction("& "Hello" &")" to me in 2 seconds
or
send "myHandler" && "Hello" to me in 2 seconds
... I think.
Fred.
Re: Execute function after some time
Posted: Sat Jan 23, 2016 2:21 am
by FredBeck
This works here
Code: Select all
on mouseUp
put "get " & quote & "myFunction(" & "Hello" &")" & quote into tFunc
send tFunc to me in 2 seconds
end mouseUp
function myFunction theText
answer theText
end myFunction
Code: Select all
on mouseUp
put "myHandler" && quote & "Hello" & quote into tCom
send tCom to me in 2 seconds
end mouseUp
command myHandler theText
answer theText
end myHandler
Re: Execute function after some time
Posted: Sat Jan 23, 2016 2:28 am
by Simon
Thank you Fred,
It was bugging me that I left it so Hacky.
A little change
Code: Select all
on mouseUp
put "Hello" into tWord
put "get " & quote & "myFunction(" & tWord &")" & quote into tFunc
send tFunc to me in 2 seconds
end mouseUp
function myFunction theText
answer theText
end myFunction
As theText should normally be changing
Simon
Re: Execute function after some time
Posted: Sat Jan 23, 2016 11:13 am
by FredBeck
Does it make sense to even do that, since you can pass parameters to a handler?
I mean, a function usually takes a parameter in and spits a result out, and a handler is usually for doing stuff involving other objects (such as the answer dialog window).
Plus the fact that sending a function needs so many more quotes and brackets... I always struggle with those.
F.
Re: Execute function after some time
Posted: Sat Jan 23, 2016 12:37 pm
by FredBeck
Simon,
I don't think your code is hacky at all, the more I think about it.
The quotes positions are really awkward :
get "myFunction(Hello)"
normally puts "myFunction(Hello)" into the variable it
I would expect
get myFunction("Hello")
to be the thing to send...
ps,
I just checked, It works in Variable Checking / Strict Compilation Mode too. I didn't think it would...
Re: Execute function after some time
Posted: Sat Jan 23, 2016 1:04 pm
by croivo
Guys thank you very much
Re: Execute function after some time
Posted: Wed Jan 27, 2016 11:49 pm
by FredBeck
Better syntax I think :
Code: Select all
on mouseUp
put "hello" into tWord
put "value(myFunction(" & quote & tWord & quote & "))" into tFunc
send tFunc to me in 2 seconds
end mouseUp
function myFunction theText
answer theText
end myFunction
F.