Ristone3
|
  |
| Joined: 17 Aug 2008 |
| Total Posts: 693 |
|
|
| 29 Mar 2017 01:19 PM |
| Hi! I am trying to pass arguments to a function I am calling in delay() I have tried the following ### #### to do it and neither works: delay(1,function(variable)) -- Says delay requires two arguments. delay(1,function,variable) --This one prints seemingly random doubles. Anyone know how to accomplish this? |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2017 01:28 PM |
| For some reason the wiki shows it as delay(1,function). I used it like that and it worked fine. Maybe you can't pass a variable to a function with delay? I'm not sure either. |
|
|
| Report Abuse |
|
|
Ristone3
|
  |
| Joined: 17 Aug 2008 |
| Total Posts: 693 |
|
|
| 29 Mar 2017 01:29 PM |
| I am glad I am not alone. Well, looks like it's time to do it another way! |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2017 01:29 PM |
| coroutines work really well. |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2017 01:30 PM |
| or else if you're just removing something after a bit of time you can use debris. |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2017 02:28 PM |
No, you're probably just using it incorrectly. Two default arguments are passed to the function, or the second argument, you call spawn with.
If you want to be able to call the function with your own arguments then just use a closure.
|
|
|
| Report Abuse |
|
|
|
| 29 Mar 2017 02:28 PM |
delay*, however it works the same with spawn. They're both very similar functions.
|
|
|
| Report Abuse |
|
|
lovesicc
|
  |
| Joined: 17 Dec 2016 |
| Total Posts: 5 |
|
|
| 29 Mar 2017 02:32 PM |
function a() print("Hi") end
delay(3, a)
--> Hi
function a() print("Hi") end
function a(str) print(str) end
delay(3, function() a("Hi") end)
--> Hi
|
|
|
| Report Abuse |
|
|
lovesicc
|
  |
| Joined: 17 Dec 2016 |
| Total Posts: 5 |
|
|
| 29 Mar 2017 02:35 PM |
Woops,
function a() print("Hi") end delay(3, a) --> Hi
function a(str) print(str) end delay(3, function() a("Hi") end) --> Hi
|
|
|
| Report Abuse |
|
|
| |
|