Execute function after some time
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Execute function after some time
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.
Let's say something like this: send myFunction(parameter) in 2 seconds
Thank you.
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Execute function after some time
Hi croivo,
You are so very close!
Simon
You are so very close!
Code: Select all
send "myFunction("& parameter &")" to me in 2 seconds
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Execute function after some time
I've tried this:
and that doesn't work...
Code: Select all
on mouseUp
send "myFunction("& "Hello" &")" to me in 2 seconds
end mouseUp
function myFunction theText
answer theText
end myFunction
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Execute function after some time
OK you got me.
I'm sure there a better way to do this but here is my Hack;
Simon
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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Execute function after some time
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.
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.
Last edited by FredBeck on Sat Jan 23, 2016 11:18 am, edited 1 time in total.
Re: Execute function after some time
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
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Execute function after some time
Thank you Fred,
It was bugging me that I left it so Hacky.
A little change
As theText should normally be changing
Simon
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
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Execute function after some time
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.
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
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...
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...
Last edited by FredBeck on Sat Jan 23, 2016 1:52 pm, edited 1 time in total.
Re: Execute function after some time
Guys thank you very much
Re: Execute function after some time
Better syntax I think :
F.
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